diff --git a/packages/eds-core-react/src/components/Autocomplete/Autocomplete.tsx b/packages/eds-core-react/src/components/Autocomplete/Autocomplete.tsx index 61cf6cd97e..05a1d5202e 100644 --- a/packages/eds-core-react/src/components/Autocomplete/Autocomplete.tsx +++ b/packages/eds-core-react/src/components/Autocomplete/Autocomplete.tsx @@ -195,6 +195,28 @@ const findPrevIndex: IndexFinderType = ({ return prevIndex } +type OptionLabelProps = T extends string + ? { + /** Custom option label */ + optionLabel?: (option: T) => string + /** Disable option + * @default () => false + */ + optionDisabled?: (option: T) => boolean + /** List of options in dropdown */ + options: string[] + } + : { + /** 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 = { selectedItems: T[] } export type AutocompleteProps = { @@ -251,16 +273,10 @@ 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 use of react portal for dropdown */ 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 */ @@ -279,7 +295,8 @@ export type AutocompleteProps = { * @default 300 */ dropdownHeight?: number -} & HTMLAttributes +} & HTMLAttributes & + OptionLabelProps function AutocompleteInner( props: AutocompleteProps,