-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Navigator: focus screen wrapper instead of first tabbable element #51816
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
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
eae594c
Navigator: focus screen wrapper instead of first tabbable element
ciampo 5feb5e1
Update unit tests
ciampo e1056a3
Update snapshot
ciampo 5d0dc09
CHANGELOG
ciampo 6a90b3a
Add aria-label, aria-labelledby and role props, including types, test…
ciampo 4c868df
Add focus outline to screen
ciampo 89c0286
Remove `aria-labelledby` from types and docs, add default `aria-label…
ciampo 7409673
Merge branch 'trunk' of github.com:WordPress/gutenberg into feat/navi…
alexstine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,6 @@ import { css } from '@emotion/react'; | |
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { focus } from '@wordpress/dom'; | ||
| import { | ||
| useContext, | ||
| useEffect, | ||
|
|
@@ -18,7 +17,7 @@ import { | |
| useId, | ||
| } from '@wordpress/element'; | ||
| import { useReducedMotion, useMergeRefs } from '@wordpress/compose'; | ||
| import { isRTL } from '@wordpress/i18n'; | ||
| import { __, isRTL } from '@wordpress/i18n'; | ||
| import { escapeAttribute } from '@wordpress/escape-html'; | ||
|
|
||
| /** | ||
|
|
@@ -51,10 +50,14 @@ function UnconnectedNavigatorScreen( | |
| forwardedRef: ForwardedRef< any > | ||
| ) { | ||
| const screenId = useId(); | ||
| const { children, className, path, ...otherProps } = useContextSystem( | ||
| props, | ||
| 'NavigatorScreen' | ||
| ); | ||
| const { | ||
| children, | ||
| className, | ||
| path, | ||
| 'aria-label': ariaLabel = __( 'Navigator screen' ), | ||
| role = 'region', | ||
| ...otherProps | ||
| } = useContextSystem( props, 'NavigatorScreen' ); | ||
|
|
||
| const prefersReducedMotion = useReducedMotion(); | ||
| const { location, match, addScreen, removeScreen } = | ||
|
|
@@ -75,12 +78,33 @@ function UnconnectedNavigatorScreen( | |
| const classes = useMemo( | ||
| () => | ||
| cx( | ||
| css( { | ||
| // Ensures horizontal overflow is visually accessible. | ||
| overflowX: 'auto', | ||
| // In case the root has a height, it should not be exceeded. | ||
| maxHeight: '100%', | ||
| } ), | ||
| css` | ||
| /* Ensures horizontal overflow is visually accessible. */ | ||
| overflow-x: auto; | ||
| /* In case the root has a height, it should not be exceeded. */ | ||
| max-height: 100%; | ||
|
|
||
| &::after { | ||
| content: ''; | ||
| position: absolute; | ||
| inset: 0; | ||
| z-index: 9999; | ||
| pointer-events: none; | ||
| } | ||
|
|
||
| &:focus { | ||
| outline: none; | ||
| } | ||
|
|
||
| &:focus::after { | ||
| box-shadow: inset 0 0 0 | ||
| var( --wp-admin-border-width-focus ) | ||
| var( --wp-admin-theme-color ); | ||
|
|
||
| // Windows High Contrast mode will show this outline, but not the box-shadow. | ||
| outline: 2px solid transparent; | ||
| } | ||
| `, | ||
| className | ||
| ), | ||
| [ className, cx ] | ||
|
|
@@ -130,12 +154,9 @@ function UnconnectedNavigatorScreen( | |
| } | ||
|
|
||
| // If the previous query didn't run or find any element to focus, fallback | ||
| // to the first tabbable element in the screen (or the screen itself). | ||
| // to the screen itself. | ||
| if ( ! elementToFocus ) { | ||
| const firstTabbable = ( | ||
| focus.tabbable.find( wrapperRef.current ) as HTMLElement[] | ||
| )[ 0 ]; | ||
| elementToFocus = firstTabbable ?? wrapperRef.current; | ||
| elementToFocus = wrapperRef.current; | ||
| } | ||
|
|
||
| locationRef.current.hasRestoredFocus = true; | ||
|
|
@@ -211,6 +232,9 @@ function UnconnectedNavigatorScreen( | |
| <motion.div | ||
| ref={ mergedWrapperRef } | ||
| className={ classes } | ||
| tabIndex={ -1 } | ||
|
||
| role={ role } | ||
| aria-label={ ariaLabel } | ||
| { ...otherProps } | ||
| { ...animatedProps } | ||
| > | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
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.
Focus indication must always be visible. Instead of resetting native outline, we should provide our own custom focus style.