-
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?
Changes from 5 commits
e851bd1
56acea2
eb138db
a46af33
9f8338b
1d9a1eb
aae3965
7764376
bc2f8cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "feat: use browser `:focus-visible` if supported", | ||
"packageName": "@fluentui/react-tabster", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,8 +20,7 @@ type HTMLElementWithFocusVisibleScope = { | |
} & HTMLElement; | ||
|
||
export function applyFocusVisiblePolyfill(scope: HTMLElement, win: Window): () => void { | ||
if (alreadyInScope(scope)) { | ||
// Focus visible polyfill already applied at this scope | ||
if (alreadyInScope(scope) || browserSupportsFocusVisible()) { | ||
return () => undefined; | ||
} | ||
|
||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. I would like to hear from @mshoho that we can use There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 |
||
} |
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?