-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
feat: use browser :focus-visible
if supported
#24195
base: master
Are you sure you want to change the base?
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit bc2f8cb:
|
📊 Bundle size reportUnchanged fixtures
|
Perf Analysis (
|
Scenario | Render type | Master Ticks | PR Ticks | Iterations | Status |
---|---|---|---|---|---|
Avatar | mount | 1598 | 1518 | 5000 | |
Button | mount | 1152 | 1140 | 5000 | |
FluentProvider | mount | 1864 | 1871 | 5000 | |
FluentProviderWithTheme | mount | 730 | 741 | 10 | |
FluentProviderWithTheme | virtual-rerender | 729 | 690 | 10 | |
FluentProviderWithTheme | virtual-rerender-with-unmount | 734 | 755 | 10 | |
MakeStyles | mount | 2247 | 2351 | 50000 | |
SpinButton | mount | 3107 | 3093 | 5000 |
Asset size changesSize Auditor did not detect a change in bundle size for any component! Baseline commit: a0e1e0c2780ad6ba73aaeee1aa1525168a4d4045 (build) |
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.
LGTM
@@ -103,3 +102,7 @@ function alreadyInScope(el: HTMLElement | null | undefined): boolean { | |||
|
|||
return alreadyInScope(el?.parentElement); | |||
} | |||
|
|||
function browserSupportsFocusVisible() { | |||
return CSS.supports('selector(:focus-visible)'); |
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.
I would like to hear from @mshoho that we can use focus-visible
in supported browsers.
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.
@miroslavstastny focus-visible isn't fully sufficient. It cannot be triggered programmatically. And keyborg has things like detecting if the focus is moved by screen readers (and consequently enabling the keyboard navigation mode).
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.
There is focusVisible option: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus
but: https://caniuse.com/?search=focusVisible
packages/react-components/react-tabster/src/hooks/useFocusWithin.ts
Outdated
Show resolved
Hide resolved
packages/react-components/react-tabster/src/hooks/useFocusWithin.ts
Outdated
Show resolved
Hide resolved
packages/react-components/react-tabster/src/hooks/useFocusVisible.ts
Outdated
Show resolved
Hide resolved
packages/react-components/react-tabster/src/hooks/useFocusVisible.ts
Outdated
Show resolved
Hide resolved
@@ -28,6 +28,8 @@ export const createCustomFocusIndicatorStyle = ( | |||
[`:global(.fui-FluentProvider)`]: { | |||
[`& .${FOCUS_VISIBLE_CLASS}`]: style, | |||
}, |
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.
Can this be wrapped in a @ supports not selector(:focus-visible)
block so that it's easier for the browser to know they don't have to try and match this style if :focus-visible
is supported?
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.
Outside of my minor feedback, this PR looks good
Waiting on microsoft/keyborg#19 so that we can handle edge cases where screen readers pull focus |
Because this pull request has not had activity for over 150 days, we're automatically closing it for house-keeping purposes. The pull request will still be available for reference. If it's still relevant to merge at some point, you can reopen or make a new version based on the latest code. |
Current Behavior
v9
:focus-visible
ponyfill will always be usedNew Behavior
Both native
:focus-visible
and ponyfill styles are written to DOM, but if the ponyfill is never applied, its styles will never be used because there is no selector:focus-visible
native:focus-visible
ponyfill 🦄:focus-visible
Improvement in %Related Issue(s)
Addresses #24183