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

Conversation

larseirikhansen
Copy link
Contributor

@larseirikhansen larseirikhansen commented Aug 15, 2024

Description

Found this bug a while ago. The bug: After triggering autocomplete, adding a trailing space will continue the suggestion. For example, writing "ap " (with two trailing spaces) will be interpreted as having written "appl", given that the first autocomplete suggestion is "apple". Spaces almost function as a wildcard. A letter after the space(s) stops the behaviour.

This fix: trailing spaces no longer work as wildcards in autocomplete. They still work as spaces for multiple words.


Discussion:
With this fix, writing spaces still don't filter out items in the dropdown (like writing a letter will). So adding a space after a word won't remove all results that don't include that space. This might be convenient in some cases, but it also allows for confusing edge cases like this:

Screenshot 2024-08-15 at 11 35 59

Here, the third (instead of the first) option in the dropdown is the autocomplete suggestion. Is the fact that the autocomplete result is not always on top more confusing than it is convenient? If so, I will make space like letters

Copy link

changeset-bot bot commented Aug 15, 2024

🦋 Changeset detected

Latest commit: a388497

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@navikt/ds-react Patch
@navikt/ds-css Patch
@navikt/ds-tokens Patch
@navikt/ds-tailwind Patch
@navikt/aksel-icons Patch
@navikt/aksel Patch
@navikt/aksel-stylelint Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@larseirikhansen larseirikhansen changed the title 🐛 trailing spaces are no longer an accepted autocomplete-letter 🐛 trailing spaces are no longer accepted autocomplete-letters Aug 15, 2024
Copy link
Contributor

Storybook demo

9c17425c1 | 88 komponenter | 139 stories

Copy link
Collaborator

@KenAJoh KenAJoh left a comment

Choose a reason for hiding this comment

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

LGTM 🚀 Nice to have a small comment for future us when we inevitably end up doing some refactors 📝

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()),

@HalvorHaugan HalvorHaugan changed the title 🐛 trailing spaces are no longer accepted autocomplete-letters 🐛 Combobox: trailing spaces are no longer accepted autocomplete-letters Sep 3, 2024
@larseirikhansen larseirikhansen merged commit e271bc0 into main Sep 4, 2024
4 checks passed
@larseirikhansen larseirikhansen deleted the combobox-space-bug branch September 4, 2024 09:01
@github-actions github-actions bot mentioned this pull request Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants