-
Notifications
You must be signed in to change notification settings - Fork 42
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
Add new useVirtualFocus hook, for use in Combobox #2394
Conversation
…r other components later, but will scope it for Combobox at first.
🦋 Changeset detectedLatest commit: 80b42da The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
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 |
Storybook demoEndringer til review: 12a4f8207a0 | 59 komponenter | 390 stories |
…g IDs and for text lookups in lists.
…e of the currently (virtually) focused element instead This allows use of e.g. numbers as options, which data-value didn't.
# Conflicts: # @navikt/core/react/src/form/combobox/FilteredOptions/filteredOptionsContext.tsx # @navikt/core/react/src/form/combobox/Input/Input.tsx # yarn.lock
…g interpreted as being different from the existing options
…ithub.com/navikt/aksel into feature/useVirtualFocus-hook-for-combobox
@navikt/core/react/src/form/combobox/FilteredOptions/filtered-options-util.ts
Outdated
Show resolved
Hide resolved
@navikt/core/react/src/form/combobox/FilteredOptions/filteredOptionsContext.tsx
Outdated
Show resolved
Hide resolved
@navikt/core/react/src/form/combobox/FilteredOptions/filteredOptionsContext.tsx
Outdated
Show resolved
Hide resolved
…ions in a multiselect selectedOptionsContext is not available inside customOptionsContext, so need to take isMultiSelect from props instead
# Conflicts: # yarn.lock
…sulting type mismatches
@navikt/core/react/src/form/combobox/FilteredOptions/filteredOptionsContext.tsx
Outdated
Show resolved
Hide resolved
…xt to reflect that it is now actually a setState-function
…ead of each separate method. Done to remove need to wrap moveFocusUp and moveFocusDown in order to toggle isListOpen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Liker denne filen, smart å trekke ut utils
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Synes endringene ser ryddige ut, lets 🚢 🇮🇹 Så vi får gjort ferdig neste PR 👍
Might be useful for other components later, but will scope it for Combobox at first.
Description
The useVirtualFocus hook takes in a ref pointing to the container of the elements to use virtual focus on.
E.g. the
ul
element in the dropdown list in Combobox.The hook will maintain the reference to the currently "focused" child element, and provides methods for moving focus up and down by one, jump to the last element or to the top (currently setting the index to -1 to signal virtual focus being removed) or setting virtual focus to a specific element.
The hook also returns the element currently receiving virtual focus. This can then be used to get the ID, for use in e.g.
aria-activeDescendant
.Change summary
Added useVirtualHook
PR Checklist TODOs 📝
New component? ✨
Versioning 🏷️
yarn changeset
to generate a version-entry for change.