Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Combobox: trailing spaces are no longer accepted autocomplete-letters #3105

Merged
merged 3 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nasty-jeans-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@navikt/ds-react": patch
---

:bug: Combobox: trailing spaces no longer work like wildcards for autocomplete suggestions
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
normalizeText(listItem.label).startsWith(text.toLocaleLowerCase()),
// We deliberately avoid using `normalizeText()` to avoid trimming input
normalizeText(listItem.label).startsWith(text.toLocaleLowerCase()),

);
};

Expand Down
4 changes: 3 additions & 1 deletion @navikt/core/react/src/form/combobox/combobox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => (
Expand Down
Loading