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 new Parent block selector to child blocks (mahjong) #21056

Merged
merged 32 commits into from
May 26, 2020

Conversation

shaunandrews
Copy link
Contributor

This PR aims to create a UI that allows you to select the parent block from the currently selected block's toolbar:

Toolbar Chip Hover with Delay

@shaunandrews shaunandrews self-assigned this Mar 20, 2020
@shaunandrews
Copy link
Contributor Author

Got a quick first pass up that looks like this:

Parent Selector Draft 1

@github-actions
Copy link

github-actions bot commented Mar 20, 2020

Size Change: +13 kB (1%)

Total Size: 1.12 MB

Filename Size Change
build/a11y/index.js 1.14 kB +123 B (10%) ⚠️
build/annotations/index.js 3.62 kB -1 B
build/api-fetch/index.js 3.4 kB +4 B (0%)
build/autop/index.js 2.83 kB +1 B
build/block-directory/index.js 6.48 kB -453 B (6%)
build/block-directory/style-rtl.css 788 B -2 B (0%)
build/block-directory/style.css 788 B -3 B (0%)
build/block-editor/index.js 105 kB +473 B (0%)
build/block-editor/style-rtl.css 11 kB +213 B (1%)
build/block-editor/style.css 11 kB +211 B (1%)
build/block-library/editor-rtl.css 7.2 kB -18 B (0%)
build/block-library/editor.css 7.2 kB -17 B (0%)
build/block-library/index.js 119 kB -183 B (0%)
build/block-library/style-rtl.css 7.48 kB -1 B
build/block-library/style.css 7.48 kB -1 B
build/block-library/theme-rtl.css 684 B +1 B
build/block-library/theme.css 686 B +1 B
build/block-serialization-default-parser/index.js 1.88 kB +1 B
build/blocks/index.js 48.1 kB -6 B (0%)
build/components/index.js 190 kB +7.46 kB (3%)
build/components/style-rtl.css 17.1 kB -2 B (0%)
build/components/style.css 17.1 kB -4 B (0%)
build/compose/index.js 9.31 kB +2.6 kB (27%) 🚨
build/core-data/index.js 11.4 kB +40 B (0%)
build/deprecated/index.js 771 B -1 B
build/edit-navigation/index.js 6.63 kB +27 B (0%)
build/edit-post/index.js 302 kB -34 B (0%)
build/edit-post/style-rtl.css 12.2 kB +39 B (0%)
build/edit-post/style.css 12.2 kB +39 B (0%)
build/edit-site/index.js 14 kB +1.21 kB (8%) 🔍
build/edit-site/style-rtl.css 5.52 kB +304 B (5%) 🔍
build/edit-site/style.css 5.53 kB +306 B (5%) 🔍
build/edit-widgets/index.js 8.05 kB +319 B (3%)
build/editor/index.js 44.6 kB +296 B (0%)
build/editor/style-rtl.css 5.06 kB -14 B (0%)
build/editor/style.css 5.06 kB -15 B (0%)
build/format-library/index.js 7.71 kB +72 B (0%)
build/hooks/index.js 2.13 kB +1 B
build/i18n/index.js 3.56 kB +1 B
build/keyboard-shortcuts/index.js 2.51 kB -1 B
build/list-reusable-blocks/index.js 3.12 kB -2 B (0%)
build/media-utils/index.js 5.29 kB -3 B (0%)
build/rich-text/index.js 14.8 kB +1 B
build/url/index.js 4.02 kB +1 B
ℹ️ View Unchanged
Filename Size Change
build/blob/index.js 620 B 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/data-controls/index.js 1.29 kB 0 B
build/data/index.js 8.42 kB 0 B
build/date/index.js 5.47 kB 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 3.11 kB 0 B
build/edit-navigation/style-rtl.css 857 B 0 B
build/edit-navigation/style.css 856 B 0 B
build/edit-widgets/style-rtl.css 4.59 kB 0 B
build/edit-widgets/style.css 4.59 kB 0 B
build/editor/editor-styles-rtl.css 425 B 0 B
build/editor/editor-styles.css 428 B 0 B
build/element/index.js 4.65 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/style-rtl.css 502 B 0 B
build/format-library/style.css 502 B 0 B
build/html-entities/index.js 622 B 0 B
build/is-shallow-equal/index.js 711 B 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/style-rtl.css 226 B 0 B
build/list-reusable-blocks/style.css 226 B 0 B
build/notices/index.js 1.79 kB 0 B
build/nux/index.js 3.4 kB 0 B
build/nux/style-rtl.css 616 B 0 B
build/nux/style.css 613 B 0 B
build/plugins/index.js 2.56 kB 0 B
build/primitives/index.js 1.5 kB 0 B
build/priority-queue/index.js 789 B 0 B
build/redux-routine/index.js 2.85 kB 0 B
build/server-side-render/index.js 2.68 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.28 kB 0 B
build/viewport/index.js 1.84 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.17 kB 0 B

compressed-size-action

@paaljoachim
Copy link
Contributor

Hey Shaun

I really like example 2. With the selecting of the "Column" parent.
It right away let's the user know that it is associated with the block, and will then notice that the parent block is selected.

@gziolo
Copy link
Member

gziolo commented Mar 21, 2020

This is cool. Do you have some ideas how user would be able to use the parent button using only keyboard navigation?

@ZebulanStanphill
Copy link
Member

@gziolo I imagine that you would get to it by shift-tabbing from the movers. In other words, you would shift-tab from the block icon to the movers, and then again to get to the select-parent button. That would make the most sense from a visual-order-should-match-DOM-order perspective.

Right now, there is an inserter button when you shift-tab from the movers, but I think that's a poor place to put that control. See #13571.

@shaunandrews
Copy link
Contributor Author

Here's the latest on this PR:

Parent Block Selector Demo i2

Things feel pretty good, though I could use some 👀 on the code — I'm certain there are missing things or better ways to accomplish some of these things.

Do you have some ideas how user would be able to use the parent button using only keyboard navigation?

You can put :focus on the Parent button using the normal tabbing — the button appears between the movers and the current block icon; When focused, the Parent button appears.

It's also worth noting that you can already use the keyboard's up/down arrows to move through the block hierarchy.

@shaunandrews shaunandrews marked this pull request as ready for review March 22, 2020 18:54
@shaunandrews shaunandrews added the Needs Design Feedback Needs general design feedback. label Mar 22, 2020
@shaunandrews shaunandrews requested review from jasmussen and mtias March 22, 2020 19:01
@ZebulanStanphill
Copy link
Member

I think that it would make more sense if the tab order was select-parent -> movers -> block switcher rather than movers -> select-parent -> block switcher. The select-parent button could be viewed as a sort of navigation link somewhat outside of the rest of the block toolbar (hence why it is floating a bit away from the rest of the toolbar). It's also the first thing in the visual order if you go top-bottom, left-right, so from an accessibility perspective, it should be the first thing in the DOM order.

@gziolo
Copy link
Member

gziolo commented Mar 23, 2020

I think that it would make more sense if the tab order was select-parent -> movers -> block switcher rather than movers -> select-parent -> block switcher. The select-parent button could be viewed as a sort of navigation link somewhat outside of the rest of the block toolbar (hence why it is floating a bit away from the rest of the toolbar). It's also the first thing in the visual order if you go top-bottom, left-right, so from an accessibility perspective, it should be the first thing in the DOM order.

I agree that it makes sense to have the select parent button first. It's also a regular button so it can't be in the tab order in the middle of the toolbar. Keep in mind that we still didn't finish refactoring all tollbars to handle toolbar buttons navigation with arrow keys only and making the toolbar being a single tab stop. I guess for the accessibility reasons the parent selector should be always focusable even when it is not visible? I don't think it's implemented at the moment.

@gziolo gziolo added the Needs Accessibility Feedback Need input from accessibility label Mar 23, 2020
@youknowriad
Copy link
Contributor

Should we support multi-selection too? I believe it triggers an error now.

@jasmussen
Copy link
Contributor

Rocking it, Shaun! This is working better than I expected:

vertical

Two things:

  1. The space between the "go up" button and the toolbar should be 12px, i.e. $grid-unit-15.
  2. I would make the top button appear in lockstep with the mover control, not shortly after.

Should we support multi-selection too? I believe it triggers an error now.

I would disable it entirely for multi selection.

Tab order feels correct to me, but I will defer to those with stronger opinions and background on best practices.

@ZebulanStanphill
Copy link
Member

I would make the top button appear in lockstep with the mover control, not shortly after.

Agreed.

@shaunandrews
Copy link
Contributor Author

Parent Block Selector Demo i3

Pushed a handful of changes:

  • Updated the space between the Parent button and the Toolbar to 12px.
  • The Parent button now appears at the same time as the Movers.
  • The tooltip now displays the parent block's title.
  • There was a bunch of prettier stuff that I keep ignoring (--no-verify is a nasty habit); I've cleaned things up now in the code.
  • The Parent button doesn't render if multiple blocks are selected. This could use some more testing, but I no longer see an error when selecting multiple blocks.

@ZebulanStanphill
Copy link
Member

Just tested out this PR. This is fantastic! Already, I can see myself using this button far more often than the footer breadcrumb links. The only thing I'd change is the label (see code suggestion I recently made) and the DOM/tab order of the button. Aside from that, I think this is perfect.

@shaunandrews shaunandrews removed the Needs Design Feedback Needs general design feedback. label Mar 24, 2020
@gziolo
Copy link
Member

gziolo commented Mar 26, 2020

It works great, it's going to be awesome 💯

I second all the concerns @ZebulanStanphill shared. I recorder a screencast where I use the mix of tabbing and arrow keys (left/right) to navigate to parent blocks:

block-parent

One thing I'm not sure about is whether this new "select parent" button should be part of the block toolbar and thus reachable with arrow left/right keys. It feels strange when you see how the focus moves at the moment because it's disconnected from the rest of the toolbar by both the spacing used and the direction that goes to the top. Maybe @enriquesanchez or @MarcoZehe could advise here on the best approach here.

@paaljoachim
Copy link
Contributor

paaljoachim commented Mar 26, 2020

I took a test run using gutenberg.run.

Before:
Screen Shot 2020-03-26 at 09 28 18

It would be nicer to bring the popup "parent" icon closer to the toolbar. Here is a mockup. To give a feeling for how the parent icon looks when it is closer to the toolbar. It creates a closeness between objects. A stronger association.

After:
Parent-icon-closer-to-toolbar

Bottom line: It will be helpful to bring "parent" icon a little closer to the toolbar and by doing so create an even stronger connection between the flow of the icons.

@ZebulanStanphill
Copy link
Member

ZebulanStanphill commented Mar 26, 2020

I think the select-parent button should feel a little detached from the toolbar because it isn't part of the toolbar. I think that was the idea in the original mockup. It's sort of like the sibling inserter in that respect. The button could also be viewed as a sort of navigational skip link, similar to the one used to get to the Inspector. That's one of the reasons I think it should be the "leftmost" tabbable. Having it accessible in the middle of the toolbar doesn't make sense if it isn't part of the toolbar (both technically and visually.

@shaunandrews
Copy link
Contributor Author

After the last rebase, I noticed that the tooltip for the Block Switcher component doesn't display when the block is within a parent block.

tooltips

However, for blocks without a parent the tooltip appears to display normally:

image

And for the life of me, I can't figure out why...

* Block parent selector component, displaying the hierarchy of the
* current block selection as a single icon to "go up" a level.
*
* @return {WPElement} Parent block selector.
Copy link
Member

Choose a reason for hiding this comment

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

I'm pretty sure this should be WPComponent, not WPElement?

@ItsJonQ
Copy link

ItsJonQ commented May 25, 2020

After the last rebase, I noticed that the tooltip for the Block Switcher component doesn't display when the block is within a parent block.

@shaunandrews Haii! I just took a looksy.

I'm not too sure why either 🤔

I took a look at the BlockSwitcher and BlockParentSelector blocks. Haven't found anything yet.

My hunch tells me that there's probably a event.stopPropagation() or something happening somewhere, which is preventing the Tooltip from firing.

Edit: I checked out the custom hook that handled the mover interactions:
https://github.com/WordPress/gutenberg/blob/master/packages/block-editor/src/components/block-toolbar/utils.js#L56

Although it uses event.stopPropagation(), it has no affect on the Tooltip

Will keep looking

@ItsJonQ
Copy link

ItsJonQ commented May 25, 2020

@shaunandrews I think I got it!

Screen Shot 2020-05-25 at 10 59 20 AM

I pushed up my change. I followed the trail of props. It looked like the inner ToolbarButton/Button was looking for title to be used for it's Tooltip (not label)

Let me know if that works for you! 🙏

@ZebulanStanphill
Copy link
Member

@ItsJonQ Well that seems like a bug (outside of this PR); it seems like label should work, shouldn't it?

@ItsJonQ
Copy link

ItsJonQ commented May 25, 2020

@ZebulanStanphill From what I can tell, it looks like ToolbarButton was updated with some other Toolbar components recently.

cc'ing @diegohaz !

Not saying you broke anything 🙏 ! Just curious. It looks like the label property was swapped with title. Was wondering if you had any context?

From a semantic perspective, title makes more sense. Just confirming the behaviour.

Thanks!

@youknowriad
Copy link
Contributor

if it's a recent change (swapping label with title), then it's a breaking change and should be undone. Also consistency with the "Button" component seems like a good thing isn't it?

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.

It seems like there's a JS unit test failure.

Other than that, it seems like we can land this.

@diegohaz
Copy link
Member

diegohaz commented May 26, 2020

Not saying you broke anything 🙏 ! Just curious. It looks like the label property was swapped with title. Was wondering if you had any context?

As far as I know, the ToolbarButton prop has always been title, and it's passed to the label prop on Button.

These props are named differently on ToolbarButton and Button:

<ToolbarButton title="title" isActive isDisabled />
<Button label="label" isPressed disabled />

Besides that, to pass additional props like event handlers to the underlying Button when using ToolbarButton, you have to use an extraProps prop:

<ToolbarButton extraProps={ { onKeyDown: ... } } />
<Button onKeyDown={ ... } />

I'm not aware of the reasons behind that. But it seems to me that we should deprecate those different props on ToolbarButton and adopt the same API as Button for consistency.

With #18931, ToolbarButton started to also accept the Button API, but only when using it as a child of <Toolbar __experimentalAccessibilityLabel />.

@diegohaz diegohaz mentioned this pull request May 26, 2020
6 tasks
@ItsJonQ
Copy link

ItsJonQ commented May 26, 2020

It seems like there's a JS unit test failure.

@youknowriad Wonderful! I just pushed an update to the test snapshots. That should do it

@ItsJonQ
Copy link

ItsJonQ commented May 26, 2020

Thanks for that context @diegohaz !!

@ItsJonQ
Copy link

ItsJonQ commented May 26, 2020

Looks like Travis is happy! I'll merge it up.
Thanks for the feedback + review all!

@ItsJonQ ItsJonQ merged commit 7e4b0d0 into master May 26, 2020
@ItsJonQ ItsJonQ deleted the try/block-parent-selector branch May 26, 2020 19:22
@github-actions github-actions bot added this to the Gutenberg 8.3 milestone May 26, 2020
@mapk
Copy link
Contributor

mapk commented May 26, 2020

Really great to see this getting merged! I'm excited to see it in play. 🎉

@mapk mapk added the Needs Figma Update Needs an update to Figma for design purposes label May 26, 2020
@mtias
Copy link
Member

mtias commented May 28, 2020

Kudos @shaunandrews !

@ZebulanStanphill ZebulanStanphill mentioned this pull request May 29, 2020
6 tasks
@shaunandrews
Copy link
Contributor Author

What a nice way to come back from a week offline — thanks for the assist, @ItsJonQ!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Blocks Overall functionality of blocks [Feature] Writing Flow Block selection, navigation, splitting, merging, deletion... Needs Figma Update Needs an update to Figma for design purposes [Type] Feature New feature to highlight in changelogs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.