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: revert 3408 type change + readonly #3515

Merged
merged 4 commits into from
Jun 14, 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 @@ -223,34 +223,11 @@ const handleListFocus = (e: FocusEvent<HTMLElement>) => {

const defaultOptionDisabled = () => false
// MARK: types
// prettier-ignore
type OptionLabelProps<T,> = T extends string | number
? {
/** Custom option label */
optionLabel?: (option: T) => string
/** Disable option
* @default () => false
*/
optionDisabled?: (option: T) => boolean
/** List of options in dropdown */
options: (string | number)[]
}
: {
/** Custom option label */
optionLabel: (option: T) => string
/** Disable option
* @default () => false
*/
optionDisabled?: (option: T) => boolean
/** List of options in dropdown */
options: T[]
}

export type AutocompleteChanges<T> = { selectedItems: T[] }

export type AutocompleteProps<T> = {
/** List of options in dropdown */
options: T[]
options: readonly T[]
/** Label for the select element */
label: ReactNode
/** Array of initial selected items
Expand Down Expand Up @@ -302,12 +279,18 @@ export type AutocompleteProps<T> = {
multiple?: boolean
/** Add select-all option. Throws an error if true while multiple = false */
allowSelectAll?: boolean
/** Custom option label. NOTE: This is required when option is an object */
optionLabel?: (option: T) => string
/** Custom option template */
optionComponent?: (option: T, isSelected: boolean) => ReactNode
/** Disable use of react portal for dropdown
* @deprecated Autocomplete now uses the native popover api to render the dropdown. This prop will be removed in a future version
*/
disablePortal?: boolean
/** Disable option
* @default () => false
*/
optionDisabled?: (option: T) => boolean
/** Custom filter function for options */
optionsFilter?: (option: T, inputValue: string) => boolean
/** If `true` the width of the dropdown will adjust to the width of the input */
Expand All @@ -330,8 +313,7 @@ export type AutocompleteProps<T> = {
* Method that is used to compare objects by value. If omitted, objects are matched by reference.
*/
itemCompare?: (value: T, compare: T) => boolean
} & HTMLAttributes<HTMLDivElement> &
OptionLabelProps<T>
} & HTMLAttributes<HTMLDivElement>

// MARK: component
function AutocompleteInner<T>(
Expand Down Expand Up @@ -561,7 +543,7 @@ function AutocompleteInner<T>(

// MARK: downshift state
let comboBoxProps: UseComboboxProps<T> = {
items: availableItems,
items: availableItems as T[], //can not pass readonly type to downshift so we cast it to regular T[]
initialSelectedItem: initialSelectedOptions[0],
isItemDisabled(item) {
return optionDisabled(item)
Expand Down