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

Add new useVirtualFocus hook, for use in Combobox #2394

Merged
merged 18 commits into from
Nov 1, 2023

Conversation

it-vegard
Copy link
Contributor

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? ✨

  • Add JSDoc to component (see other components for reference)

Versioning 🏷️

  • Run yarn changeset to generate a version-entry for change.

…r other components later, but will scope it for Combobox at first.
@changeset-bot
Copy link

changeset-bot bot commented Oct 18, 2023

🦋 Changeset detected

Latest commit: 80b42da

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

@github-actions
Copy link
Contributor

github-actions bot commented Oct 18, 2023

Storybook demo

Endringer til review: 12

a4f8207a0 | 59 komponenter | 390 stories

…ions in a multiselect

selectedOptionsContext is not available inside customOptionsContext, so need to take isMultiSelect from props instead
…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
Copy link
Contributor

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

Copy link
Contributor

@larseirikhansen larseirikhansen left a 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 👍

@it-vegard it-vegard merged commit 909ae6a into main Nov 1, 2023
2 checks passed
@it-vegard it-vegard deleted the feature/useVirtualFocus-hook-for-combobox branch November 1, 2023 11:02
@github-actions github-actions bot mentioned this pull request Nov 1, 2023
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.

4 participants