diff --git a/packages/eds-core-react/src/components/Autocomplete/Autocomplete.stories.tsx b/packages/eds-core-react/src/components/Autocomplete/Autocomplete.stories.tsx index ad4eb4d5d1..b96c58ca4a 100644 --- a/packages/eds-core-react/src/components/Autocomplete/Autocomplete.stories.tsx +++ b/packages/eds-core-react/src/components/Autocomplete/Autocomplete.stories.tsx @@ -179,6 +179,41 @@ Multiple.args = { options: stocks, } +export const ControlledSingleSelect: StoryFn< + AutocompleteProps +> = () => { + const [selectedOptions, setSelectedOptions] = useState([]) + const options = ['option 1', 'option 2', 'option 3', 'option 4'] + const isOptionDisabled = (item: string) => item === 'option 3' + return ( +
+ + setSelectedOptions(options) + } + optionDisabled={isOptionDisabled} + /> + + Selected option is: {selectedOptions[0]} +
+ ) +} +//this story is for internal testing, so by default we hide the story from the sidebar +ControlledSingleSelect.tags = ['!dev'] + export const OptionLabel: StoryFn> = (args) => { const { options } = args diff --git a/packages/eds-core-react/src/components/Autocomplete/Autocomplete.tsx b/packages/eds-core-react/src/components/Autocomplete/Autocomplete.tsx index cb08e3b468..9a2a63af14 100644 --- a/packages/eds-core-react/src/components/Autocomplete/Autocomplete.tsx +++ b/packages/eds-core-react/src/components/Autocomplete/Autocomplete.tsx @@ -684,6 +684,11 @@ function AutocompleteInner( allDisabled, }), } + case useCombobox.stateChangeTypes.ControlledPropUpdatedSelectedItem: + setSelectedItems([changes.selectedItem]) + return { + ...changes, + } default: return changes }