Skip to content
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

Conversation

jorgefilipecosta
Copy link
Member

@jorgefilipecosta jorgefilipecosta commented Oct 17, 2018

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.

@jorgefilipecosta jorgefilipecosta added [Type] Enhancement A suggestion for improvement. [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). labels Oct 17, 2018
isMultiSelecting: false,
};
case 'INSERT_BLOCKS': {
if ( action.updateSelection ) {
Copy link
Contributor

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.

Copy link
Member Author

@jorgefilipecosta jorgefilipecosta Oct 17, 2018

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.

Copy link
Contributor

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.

Copy link
Member Author

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?

@chrisvanpatten
Copy link
Member

OH MY GOSH this is so exciting. 😁🤗

In my custom Columns block we dispatch an insertBlock action to insert blocks from our own UI and it works but causes the paragraph inside the column to get selected. Being able to disable this behavior would be just the most incredible thing.

💟

@jorgefilipecosta jorgefilipecosta force-pushed the add/mechanism-to-avoid-force-child-selection-on-blocks-with-templates branch 5 times, most recently from c21c801 to a54d5b7 Compare October 24, 2018 19:26
Copy link
Contributor

@youknowriad youknowriad left a 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?

@@ -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.
Copy link
Contributor

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`
Copy link
Contributor

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"?

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Contributor

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 ?

@afercia
Copy link
Contributor

afercia commented Nov 6, 2018

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.

@afercia afercia added [Type] Bug An existing feature does not function as intended and removed [Type] Enhancement A suggestion for improvement. labels Nov 6, 2018
@jorgefilipecosta jorgefilipecosta force-pushed the add/mechanism-to-avoid-force-child-selection-on-blocks-with-templates branch from a54d5b7 to 7ec29d1 Compare November 6, 2018 19:47
@jorgefilipecosta
Copy link
Member Author

jorgefilipecosta commented Nov 6, 2018

I rebased this PR and retested and things looked fine, it should be ready, I added it to 4.3 milestone.

@jorgefilipecosta jorgefilipecosta added this to the 4.3 milestone Nov 6, 2018
Copy link
Member

@chrisvanpatten chrisvanpatten left a 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 :)

@jorgefilipecosta jorgefilipecosta force-pushed the add/mechanism-to-avoid-force-child-selection-on-blocks-with-templates branch from 7ec29d1 to 696f26c Compare November 6, 2018 22:03
Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@jorgefilipecosta jorgefilipecosta merged commit 16a718a into master Nov 7, 2018
@jorgefilipecosta jorgefilipecosta deleted the add/mechanism-to-avoid-force-child-selection-on-blocks-with-templates branch November 7, 2018 12:16
daniloercoli added a commit that referenced this pull request Nov 7, 2018
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants