feat(useFocus): support :focus-visible
#3254
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before submitting the PR, please make sure you do the following
fixes #123
).Description
This PR introduces an additional option in the
useFocus
composable which replicates the:focus-visible
behavior from CSS. This enhancement allows for better control over how and when elements receive focus, improving the accessibility and usability of components that use this hook.In detail, when the
focusVisible
option is set to true, focus will only be set on an element if the:focus-visible
pseudo-class matches. This effectively adds support for the:focus-visible
pseudo-class inuseFocus
.Additional context
I'd like reviewers to focus on the new test as I think the test is just faking the
matches
properties which make the test irrelevant.馃 Generated by Copilot at b8ba143
This pull request adds a new feature and a test case for the
useFocus
hook. The feature allows the user to enable thefocusVisible
option, which makes thefocused
reactive value depend on the:focus-visible
pseudo-class of the target element. This improves the accessibility and keyboard navigation of the focus state.馃 Generated by Copilot at b8ba143
focusVisible
option touseFocus
hook to replicate:focus-visible
behavior of CSS (link, link)useFocus
hook withfocusVisible
option enabled (link)