-
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
Add mechanism to avoid forced child selection on blocks with templates. #10696
Add mechanism to avoid forced child selection on blocks with templates. #10696
Conversation
isMultiSelecting: false, | ||
}; | ||
case 'INSERT_BLOCKS': { | ||
if ( action.updateSelection ) { |
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.
For me, this is not what's causing the innerBlocks to be selected, it's the focusTabbable
function inside block.js
. This on ensures the inserted block (parent) is selected.
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.
But the children are inserted after the parent, so without this changes, the selection gets updated when the child blocks are inserted.
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.
Oh makes sense. Seems like a decent 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.
Hi @youknowriad thank you for looking into this PR. Do you think it is ready to merge?
OH MY GOSH this is so exciting. 😁🤗 In my custom Columns block we dispatch an 💟 |
c21c801
to
a54d5b7
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.
Looks good to me overall. @aduth Thoughts on this new argument?
docs/data/data-core-editor.md
Outdated
@@ -1514,7 +1514,10 @@ inserted, optionally at a specific index respective a root block list. | |||
* block: Block object to insert. | |||
* index: Index at which block should be inserted. | |||
* rootClientId: Optional root client ID of block list on which | |||
to insert. | |||
to insert. |
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.
Maybe we should just not add a line break at all for arguments with long lines (to avoid messing with the markdown output)
@@ -92,6 +92,13 @@ const TEMPLATE = [ [ 'core/columns', {}, [ | |||
|
|||
The previous example creates an InnerBlocks area containing two columns one with an image and the other with a paragraph. | |||
|
|||
### `templateInsertUpdatesSelection` |
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 wonder if this is really needed or if it should always be "false"?
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 it needs to be conditional. If you're building a nested block with a flow optimised for writing you would want the selection to be updated for keyboard use.
Making it always false would also be a change in the current behaviour, which updates the selection automatically.
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 agree for some blocks it may make sense to use a different setting.
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.
Would this be clearer if it's named: updateSelectionOnTemplateInsert
?
Right now, the "Media & Text" block accessibility is less than ideal, see #9416 (comment) In that PR it was mentioned there are higher order limitations with templates / nested blocks that, at that time, prevented to fully address the accessibility concerns. This PR is meant to solve one of those issues. However, there's no milestone set and the "Media & Text" block is still not accessible. We're now at less than a week from the scheduled Release Candidate. Are there any plans to help this PR move on? /Cc @mtias @youknowriad @jorgefilipecosta @tofumatt Adding the label "bug" as "Media & Text" is not accessible. |
a54d5b7
to
7ec29d1
Compare
I rebased this PR and retested and things looked fine, it should be ready, I added it to 4.3 milestone. |
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'm not comfortable commenting on the specific implementation, but I tested the feature with our custom columns block and it works beautifully. The user experience is dramatically improved by this.
Hope to see it make it into 4.3 :)
7ec29d1
to
696f26c
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.
LGTM 👍
…rnmobile/fix-merge-content-not-refreshed-UI * 'master' of https://github.com/WordPress/gutenberg: Fix the isBeingScheduled Selector. (#11572) Slot/Fill pattern with Toolbar #199 (#11115) Add mechanism to avoid forced child selection on blocks with templates. (#10696) Allow a block to disable being converted into a reusable block; Fix: Column block (#11550)
Description
Currently, if a block contains a template when we insert that block the block that gets focused is one of the child blocks specified in the template. We don't offer a way to disable this behavior.
This current behavior makes sense in most cases (e.g: columns) but for some cases,
we may want to keep the focus on the parent. E.g. In PR #9416 @afercia pointed some a11y concerns in automatically selecting the child block on the InnerBlocks area.
Blocks may have their own edition area and an InnerBlocks are at the end. Automatically selecting a block in the InnerBlocks area, has some accessible concerns has the parent block edition area may be unnoticeable for screen reader users.
This PR adds a flag to the InnerBlocks component that allows blocks to disable the behavior of automatically selecting the children. In order for this flag to be possible another flag was added in insertBlock(s) action that allows for blocks to be inserted without a selection update happening.
How has this been tested?
I created some tests blocks available in https://gist.github.com/jorgefilipecosta/a99dcbaedd35ec88c37b142679bc0dc1.
I checked that when I insert 'Test No Template Selection' the parent block is the block selected after the insert.
I checked that when I insert 'Test Template Selection' the first child is the block that gets inserted.
Columns continue to work exactly as before (the first paragraph gets selected) when a column is inserted.