-
Notifications
You must be signed in to change notification settings - Fork 4.6k
HTML block: Fix accessibility issues on back-end #54408
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
Conversation
|
Size Change: +147 B (0%) Total Size: 1.62 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in 54172bc. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6237634689
|
|
I figured out the toolbar issue. Turns out the focus state is managed in writing-flow/use-tab-nav hook. When a block such as HTML changes DOM structure, simply placing focus on the element writing flow remembers last isn't going to work. This might be a good opportunity to fix this in a follow-up PR. Something like:
Might be something to think about in the toolbar improvement PR currently happening. It will likely face the same problem with blocks that change their DOM structures. Need a better way to predict focus in blocks. |
| // Effect for managing focus. | ||
| useEffect( () => { | ||
| if ( ! shouldFocus ) { | ||
| return; | ||
| } | ||
| if ( isPreview ) { | ||
| blockRef?.current?.focus(); | ||
| } else { | ||
| htmlTextareaRef?.current?.focus(); | ||
| } | ||
| }, [ shouldFocus, isPreview ] ); |
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.
Suggestion: Have you tried triggering the focus from switchToPreview and switchToHTML callbacks? Since these actions trigger DOM change, triggering the focus change also makes sense to me.
While there's nothing wrong with useEffect, direct callbacks should have preference.
P.S. I've not tested this approach.
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.
@Mamaduka I tried but the ref was unavailable at that stage even calling it after the state change. That's why I opted to track in state.
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.
Right, the htmlTextareaRef won't be available when a state update is dispatched.
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.
@Mamaduka I think I might try to fix this in writing flow instead. If other blocks render new content, it would be better that writing flow be able to handle it where right now focus handling fails and we have to handle it secondary in blocks.
I'll split my attempt into another PR and just test. It might go somewhere, might not.
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.
Makes sense. Ping me if I can help with review or testing.
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.
Working in: #54443.
alexstine
left a comment
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.
Couple notes.
| html={ content } | ||
| styles={ styles } | ||
| title={ __( 'Custom HTML Preview' ) } | ||
| tabIndex={ -1 } |
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.
Added this because focus should not enter iFrame unless user wants it to. There is no way to escape the iFrame currently since writing flow is unaware of 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.
Is there an easy fix for this? I guess not since the secondary iFrame is a different browser context.
Co-authored-by: Marco Ciampini <[email protected]>
ciampo
left a comment
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.
Code-wise, things LGTM. I'll let @Mamaduka give a last round of review and approve
Mamaduka
left a comment
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.
Thank you, @alexstine and @ciampo!
What?
Fixes back-end accessibility of the HTML block.
Why?
My PR does not fully fix this issue but I make good progress.
#46846
How?
Testing Instructions
aria-describedbyattribute which matches the ID of the block description.Notes
Wondering why the focus return from toolbar does not work for this block. Might be worth investigating this so focus does not need to be managed in the block itself.
Testing Instructions for Keyboard
Screenshots or screencast