Skip to content

Commit

Permalink
πŸ› Autocomplete: revert 3408 type change + readonly (#3515)
Browse files Browse the repository at this point in the history
* Revert changes from #3408

* πŸ› fix for #3493, make options readonly

* bump version for test release

* restore version after testrelease
  • Loading branch information
oddvernes committed Jun 14, 2024
1 parent ac3893a commit baf7e51
Showing 1 changed file with 9 additions and 27 deletions.
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

0 comments on commit baf7e51

Please sign in to comment.