Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Autocomplete: handle case all items disabled #3534

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,12 @@ type IndexFinderType = <T,>({
index,
optionDisabled,
availableItems,
allDisabled,
}: {
index: number
optionDisabled: AutocompleteProps<T>['optionDisabled']
availableItems: AutocompleteProps<T>['options']
allDisabled?: boolean
calc?: (n: number) => number
}) => number

Expand Down Expand Up @@ -167,7 +169,9 @@ const findNextIndex: IndexFinderType = ({
index,
optionDisabled,
availableItems,
allDisabled,
}) => {
if (allDisabled) return 0
const options = {
index,
optionDisabled,
Expand All @@ -188,7 +192,9 @@ const findPrevIndex: IndexFinderType = ({
index,
optionDisabled,
availableItems,
allDisabled,
}) => {
if (allDisabled) return 0
const options = {
index,
optionDisabled,
Expand Down Expand Up @@ -464,6 +470,8 @@ function AutocompleteInner<T>(
return inputOptions.filter((x) => !disabledItemsSet.has(x))
}, [inputOptions, optionDisabled])

const allDisabled = enabledItems.length === 0

const selectedDisabledItemsSet = useMemo(
() => new Set(selectedItems.filter(optionDisabled)),
[selectedItems, optionDisabled],
Expand Down Expand Up @@ -662,6 +670,7 @@ function AutocompleteInner<T>(
index: changes.highlightedIndex,
availableItems,
optionDisabled,
allDisabled,
}),
}
case useCombobox.stateChangeTypes.InputKeyDownArrowUp:
Expand All @@ -678,6 +687,7 @@ function AutocompleteInner<T>(
index: changes.highlightedIndex,
availableItems,
optionDisabled,
allDisabled,
}),
}
default:
Expand Down Expand Up @@ -725,6 +735,7 @@ function AutocompleteInner<T>(
index: changes.highlightedIndex,
availableItems,
optionDisabled,
allDisabled,
}),
}
case useCombobox.stateChangeTypes.InputKeyDownArrowUp:
Expand All @@ -741,6 +752,7 @@ function AutocompleteInner<T>(
index: changes.highlightedIndex,
availableItems,
optionDisabled,
allDisabled,
}),
}
case useCombobox.stateChangeTypes.InputKeyDownEnter:
Expand Down