Skip to content

Commit

Permalink
Re-introduce controlled value in storybook examples to not change Chr…
Browse files Browse the repository at this point in the history
…omatic snapshots
  • Loading branch information
it-vegard committed Oct 23, 2024
1 parent dc0f9f6 commit 79e896b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions @navikt/core/react/src/form/combobox/combobox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,16 @@ const complexOptions = [

export const WithAddNewOptions: StoryFn = ({ open }: { open?: boolean }) => {
const comboboxRef = useRef<HTMLInputElement>(null);
const [value, setValue] = useState<string | undefined>("hello");
return (
<UNSAFE_Combobox
id="combobox-with-add-new-options"
label="Komboboks med mulighet for å legge til nye verdier"
options={options}
allowNewValues={true}
shouldAutocomplete={true}
value={value}
onChange={setValue}
isListOpen={open ?? (comboboxRef.current ? true : undefined)}
ref={comboboxRef}
/>
Expand All @@ -196,6 +199,7 @@ export const MultiSelectWithAddNewOptions: StoryFn = ({
}: {
open?: boolean;
}) => {
const [value, setValue] = useState<string | undefined>("world");
const [selectedOptions, setSelectedOptions] = useState<string[]>(["hello"]);
const comboboxRef = useRef<HTMLInputElement>(null);
return (
Expand All @@ -205,8 +209,10 @@ export const MultiSelectWithAddNewOptions: StoryFn = ({
label="Multiselect komboboks med mulighet for å legge til nye verdier"
options={options}
allowNewValues={true}
value={value}
shouldAutocomplete={true}
selectedOptions={selectedOptions}
onChange={setValue}
onToggleSelected={(option, isSelected) =>
isSelected
? setSelectedOptions([...selectedOptions, option])
Expand Down

0 comments on commit 79e896b

Please sign in to comment.