-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Focus 1st parent block on block remove, if no previous block is available #48204
Focus 1st parent block on block remove, if no previous block is available #48204
Conversation
Size Change: +774 B (0%) Total Size: 1.33 MB
ℹ️ View Unchanged
|
Flaky tests detected in e0304f6bef7991d14dbd48d8b86453ca3c015418. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4282471922
|
@draganescu Focus issue is confirmed fixed on Windows 10 Chrome/Firefox. This is working great. As a follow-up, we should look at the same thing evaluated for the navigation block. When deleting a block from the document overview, focus is switched back to the canvas instead of remaining in the list view. I think it would be helpful to simply move focus in the list view if the block was deleted from the list view. I have heard this will not be an easy task but I think the navigation block does this now so maybe it will be easy enough as a follow-up. Thanks. |
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.
Thanks for the PR @draganescu! I just left a comment and will have a closer look next week.
This comment was marked as resolved.
This comment was marked as resolved.
39135d9
to
7d1b30b
Compare
Co-authored-by: Dave Smith <444434+getdave@users.noreply.github.com> Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com>
5054ece
to
cbacabf
Compare
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 code looks pretty clean to me. Do you think it would be a good idea to add a new E2E test showing a literal block removal and previous/parent focus?
@alexstine test added |
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.
Looks good to me and the multi-tests should help us prevent regressions in the future.
@Mamaduka can you confirm this is making it into backports? |
…able (#48204) * change default selection on remove blocks action to include selecting first available parent if there is no previous block * revert renaming the selectPreviousBlock API and add a param to also select the parent when needed * Fix removeBlock call in list item block * updates remove block test to account for new selectPreviousBlock param * Try to fix editing-widgets e2e test * focus back on widget body * Addressed feedback for documentation being more explanative Co-authored-by: Dave Smith <444434+getdave@users.noreply.github.com> Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com> * remove superfluous fix attewmpt * adds a test for parent selection by default --------- Co-authored-by: Ella van Durpe <ella@vandurpe.com> Co-authored-by: Tetsuaki Hamano <tetsuaki.hamano@gmail.com> Co-authored-by: Dave Smith <444434+getdave@users.noreply.github.com> Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com>
I just cherry-picked this PR to the wp/6.2 branch to get it included in the next release: 411a5c2 |
Drafting a Dev Note: Fixed focus issue after Block removal. In WordPress 6.2 the behavior of removeBlock() changed. Until then, when a block was removed, the previous block was selected (= gained focus). Occasionally, if there wasn't any previous block available, it resulted in focus loss, which is particular grave when using a screen reader. With this update, the remove block behavior was augmented to select the first parent instead. For developer writing Custom Blocks, that might require a need to update their code, so they also account for the possibly that sometimes the parent is selected on block removal. There is a way to opt-out of this behavior by passing false as the second argument to Example code from the core/list block.
Details in #48204 |
Second review notes: 2nd sentence: "Occasionally, if there wasn't any previous block available, it resulted in focus loss, which is particular grave when using a screen reader." Change to "Occasionally..., which is particularly difficult when using a screen reader." (Grave will not be understood globally, and should be 'particularly') 3rd sentence: "With this update, the remove block behavior was augmented to select the first parent instead." Suggest "With this update, the behavior of the remove block was changed to select the first parent instead. 4th sentence: "For developer writing Custom Blocks, that might require a need to update their code, so they also account for the possibly that sometimes the parent is selected on block removal. Change to: "For a developer writing Custom Blocks, this might require an update to their code, to account for the possibility that sometimes the parent is selected on block removal." |
Fixed focus issue after Block removal. In WordPress 6.2 the behavior of the With this update, the behavior of the remove block action was changed to select the first parent when there is no previous block available. For a developer writing Custom Blocks or otherwise depending on the result of the Example code:
Details in #48204 |
@bph updated the devnote with a few tweaks and the suggestions from @abhansnuk 🙏🏻 |
@draganescu Where did you make your edits? I went ahead and published it on the Misc Editor dev note already - with Abha's suggestions. Sorry, we were on a deadline. |
What?
Closes #48017
Trying to fix a focus loss issue with the navigation block (see #48105) I found that at all times when we remove the last child of a block we end up with focus loss - focus moves to the
body
of the editor'siframe
.This PR fixes this and also the original issue.
Why?
Focus loss is one of the worst bugs in terms of using the UI via assistive technology. We already handle this by:
How?
This PR selects the 1st parent if the current block to be removed has no previous block to be selected. It also solves the same for the list view and the experimental off canvas editor component by updating the focus management logic in:
selectPreviousBlock
action of the block editor store, making it intoselectPreviousBlockOrFirstParent
updateSelectionAfterRemove
callback of theBlockSettingsDropdown
componentTesting Instructions
In a post, a template or a template part:
To do