-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Improve accessibility of the Warning component in the block editor #67433
base: trunk
Are you sure you want to change the base?
Improve accessibility of the Warning component in the block editor #67433
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
@sarthaknagoshe2002 thanks for your PR. Good catch for adding the Unfortunately, testing with Safari and VoiceOver the Warning isn't announced. I guess because the editor sets focus on the newly inserted block. See in the screenshot below: focus is on the doubled 'More' block: I think a potential way to fix this would be setting focus on the Warning when it renders by using I'll leave a few comments in the review as well. |
<div | ||
className={ clsx( className, 'block-editor-warning' ) } | ||
role="alert" | ||
aria-live="assertive" |
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.
role alert inherently works as an assertive live region so that aria-live="assertive"
isn't necessary. aria-live
doesn;t work well for elements that appear in the DOM anyways.
<div className="block-editor-warning__actions"> | ||
<div | ||
className="block-editor-warning__actions" | ||
aria-describedby="block-editor-warning-message" |
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.
Not sure this aria-describedby
is necessary. It doesn't point to any ID anyways, please remove it.
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.
Left some comments
It seems to work fine in Chrome on macOS using the default screen reader. I also tested it on Safari, and it’s a bit buggy—I noticed it works intermittently. I’m currently investigating the issue and exploring possible solutions. |
@afercia I have now fixed things to make it work in safari.
Let me know this this requires any more changes. If not then I'll update the tests too. 😇 |
Also, the git hook seems to have modified the linting of some tsconfig.json file. |
if ( null !== alertRef.current ) { | ||
alertRef.current.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.
Question: can this be simplified? I'm not sure there's the need to set the initial ref to null
and then checking for it. To my understanding the optional chaining operator ?.
would make this much more concise. See an example here:
gutenberg/packages/block-library/src/video/tracks-editor.js
Lines 182 to 186 in e4649fe
const dropdownPopoverRef = useRef(); | |
useEffect( () => { | |
dropdownPopoverRef.current?.focus(); | |
}, [ trackBeingEdited ] ); |
packages/upload-media/tsconfig.json
Outdated
@@ -8,13 +8,13 @@ | |||
}, | |||
"include": [ "src/**/*" ], | |||
"references": [ | |||
{ "path": "../api-fetch" }, |
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.
changes to this file should be reverted, probably a result of merge conflict or something
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.
The pre-commit Git hook is enforcing linting even after reverting changes. Are there alternative solutions?
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 submitted a quick PR #68083 to fix it separately.
Once that is merged, please rebase this PR.
<p className="block-editor-warning__message"> | ||
<p | ||
className="block-editor-warning__message" | ||
ref={ alertRef } |
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 think the reg should be set on the container with tabIndex="0", otherwise moving focus will fail?
@sarthaknagoshe2002 yes I think those changes should be reverted. As a last step, when everything is done, I guess the snapshot of the failing test should be updated.
|
Accessibility Fix: #62737
What?
This PR improves the Warning component in the block editor by enhancing its accessibility.
Why?
Currently, the Warning component only provides a visual cue without notifying screen readers, which limits accessibility. These changes ensure that the component is accessible to all users.
How?
Testing Instructions