diff --git a/.changeset/nasty-jeans-invent.md b/.changeset/nasty-jeans-invent.md new file mode 100644 index 00000000000..da3afc646e9 --- /dev/null +++ b/.changeset/nasty-jeans-invent.md @@ -0,0 +1,5 @@ +--- +"@navikt/ds-react": patch +--- + +:bug: Combobox: trailing spaces no longer work like wildcards for autocomplete suggestions diff --git a/@navikt/core/react/src/form/combobox/FilteredOptions/filtered-options-util.ts b/@navikt/core/react/src/form/combobox/FilteredOptions/filtered-options-util.ts index c7e8ce4698e..22907c2acc5 100644 --- a/@navikt/core/react/src/form/combobox/FilteredOptions/filtered-options-util.ts +++ b/@navikt/core/react/src/form/combobox/FilteredOptions/filtered-options-util.ts @@ -10,9 +10,8 @@ const getMatchingValuesFromList = (value: string, list: ComboboxOption[]) => list.filter((listItem) => isPartOfText(value, listItem.label)); const getFirstValueStartingWith = (text: string, list: ComboboxOption[]) => { - const normalizedText = normalizeText(text); return list.find((listItem) => - normalizeText(listItem.label).startsWith(normalizedText), + normalizeText(listItem.label).startsWith(text.toLocaleLowerCase()), ); }; diff --git a/@navikt/core/react/src/form/combobox/combobox.stories.tsx b/@navikt/core/react/src/form/combobox/combobox.stories.tsx index 9baedf2948b..a340e54e075 100644 --- a/@navikt/core/react/src/form/combobox/combobox.stories.tsx +++ b/@navikt/core/react/src/form/combobox/combobox.stories.tsx @@ -27,11 +27,13 @@ const options = [ "grape", "kiwi", "mango", + "mangosteen", + "mango pie", "passion fruit", "pineapple", "strawberry", "watermelon", - "grape fruit", + "grapefruit", ]; export const Default: StoryFunction = (props) => (