feat: use browser :focus-visible if supported#24195
feat: use browser :focus-visible if supported#24195ling1726 wants to merge 9 commits intomicrosoft:masterfrom
:focus-visible if supported#24195Conversation
|
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) |
| } | ||
|
|
||
| function browserSupportsFocusVisible() { | ||
| return CSS.supports('selector(:focus-visible)'); |
There was a problem hiding this comment.
I would like to hear from @mshoho that we can use focus-visible in supported browsers.
There was a problem hiding this comment.
@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.
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.
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?
jspurlin
left a comment
There was a problem hiding this comment.
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-visibleponyfill will always be usedNew Behavior
Both native
:focus-visibleand 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-visiblenative:focus-visibleponyfill 🦄:focus-visibleImprovement in %Related Issue(s)
Addresses #24183