diff --git a/packages/eds-core-react/src/components/Autocomplete/Autocomplete.tsx b/packages/eds-core-react/src/components/Autocomplete/Autocomplete.tsx index 16ea3b126d..22deabbc5b 100644 --- a/packages/eds-core-react/src/components/Autocomplete/Autocomplete.tsx +++ b/packages/eds-core-react/src/components/Autocomplete/Autocomplete.tsx @@ -124,8 +124,8 @@ type IndexFinderType = ({ allDisabled, }: { index: number - optionDisabled: AutocompleteProps['optionDisabled'] - availableItems: AutocompleteProps['options'] + optionDisabled: (option: T) => boolean + availableItems: readonly T[] allDisabled?: boolean calc?: (n: number) => number }) => number @@ -235,7 +235,7 @@ const defaultOptionDisabled = () => false // MARK: types export type AutocompleteChanges = { selectedItems: T[] } -export type AutocompleteProps = { +export type AutocompleteProps = { /** List of options in dropdown */ options: readonly T[] /** Total number of options */ @@ -293,8 +293,6 @@ export type AutocompleteProps = { 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 option @@ -333,7 +331,21 @@ export type AutocompleteProps = { * Callback for clear all button */ onClear?: () => void -} & HTMLAttributes +} & HTMLAttributes & + (T extends string | number + ? { + /** Custom option label. NOTE: This is required when option is an object */ + optionLabel?: (option: T) => string + } + : T extends object + ? { + /** Custom option label. NOTE: This is required when option is an object */ + optionLabel: (option: T) => string + } + : { + /** Custom option label. NOTE: This is required when option is an object */ + optionLabel?: (option: T) => string + }) // MARK: component function AutocompleteInner( @@ -1224,7 +1236,7 @@ function AutocompleteInner( ) } // MARK: exported component -export const Autocomplete = forwardRef(AutocompleteInner) as ( +export const Autocomplete = forwardRef(AutocompleteInner) as ( props: AutocompleteProps & { ref?: React.ForwardedRef /** @ignore */