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

Inserter: Add block pattern category selection dropdown in main inserter #24954

Merged
merged 17 commits into from
Sep 16, 2020

Conversation

apeatling
Copy link
Contributor

@apeatling apeatling commented Aug 31, 2020

Description

This PR adds a dropdown menu to the Patterns tab of the main inserter. Using this dropdown will filter the displayed patterns by category.

2020-09-01 13 59 35

How has this been tested?

  • Tested locally, confirmed this does not interact with other tabs, or searches.
  • All unit tests run and passed.

Types of changes

  • New feature, non breaking change.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • My code follows the accessibility standards.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@apeatling apeatling added the [Feature] Inserter The main way to insert blocks using the + button in the editing interface label Aug 31, 2020
@apeatling apeatling requested a review from ellatrix as a code owner August 31, 2020 23:33
@apeatling apeatling self-assigned this Aug 31, 2020
@apeatling
Copy link
Contributor Author

One question for this change. Should we include an "All" category? I have concerns because the poor performance of loading all patterns when you have more than 50 patterns to show. If we did have an All category I don't think it should default to being selected.

@github-actions
Copy link

github-actions bot commented Aug 31, 2020

Size Change: +1.15 kB (0%)

Total Size: 1.2 MB

Filename Size Change
build/autop/index.js 2.83 kB +1 B
build/block-directory/index.js 8.53 kB +5 B (0%)
build/block-editor/index.js 128 kB +380 B (0%)
build/block-editor/style-rtl.css 11.1 kB +70 B (0%)
build/block-editor/style.css 11.1 kB +66 B (0%)
build/block-library/editor-rtl.css 8.59 kB -85 B (0%)
build/block-library/editor.css 8.59 kB -82 B (0%)
build/block-library/index.js 135 kB -3.98 kB (2%)
build/block-library/style-rtl.css 7.6 kB +3 B (0%)
build/block-library/style.css 7.59 kB +1 B
build/blocks/index.js 47.8 kB -4 B (0%)
build/components/index.js 201 kB +117 B (0%)
build/compose/index.js 9.68 kB +4 B (0%)
build/core-data/index.js 12.2 kB -9 B (0%)
build/data-controls/index.js 1.28 kB -5 B (0%)
build/data/index.js 8.55 kB +3 B (0%)
build/edit-navigation/index.js 10.7 kB +2 B (0%)
build/edit-post/index.js 305 kB +3 B (0%)
build/edit-site/index.js 19 kB +25 B (0%)
build/edit-widgets/index.js 16.4 kB +4.21 kB (25%) 🚨
build/edit-widgets/style-rtl.css 2.75 kB +206 B (7%) 🔍
build/edit-widgets/style.css 2.75 kB +207 B (7%) 🔍
build/editor/index.js 45.3 kB +3 B (0%)
build/format-library/index.js 7.71 kB +2 B (0%)
build/keyboard-shortcuts/index.js 2.52 kB +1 B
build/list-reusable-blocks/index.js 3.12 kB +2 B (0%)
build/media-utils/index.js 5.32 kB +4 B (0%)
build/rich-text/index.js 13.9 kB +1 B
build/server-side-render/index.js 2.77 kB +2 B (0%)
build/viewport/index.js 1.85 kB +2 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.67 kB 0 B
build/api-fetch/index.js 3.41 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/style-rtl.css 943 B 0 B
build/block-directory/style.css 942 B 0 B
build/block-library/theme-rtl.css 741 B 0 B
build/block-library/theme.css 741 B 0 B
build/block-serialization-default-parser/index.js 1.88 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/components/style-rtl.css 15.5 kB 0 B
build/components/style.css 15.4 kB 0 B
build/date/index.js 31.9 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 4.48 kB 0 B
build/edit-navigation/style-rtl.css 868 B 0 B
build/edit-navigation/style.css 871 B 0 B
build/edit-post/style-rtl.css 6.24 kB 0 B
build/edit-post/style.css 6.22 kB 0 B
build/edit-site/style-rtl.css 3.13 kB 0 B
build/edit-site/style.css 3.13 kB 0 B
build/editor/editor-styles-rtl.css 492 B 0 B
build/editor/editor-styles.css 493 B 0 B
build/editor/style-rtl.css 3.8 kB 0 B
build/editor/style.css 3.8 kB 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 547 B 0 B
build/format-library/style.css 548 B 0 B
build/hooks/index.js 2.13 kB 0 B
build/html-entities/index.js 621 B 0 B
build/i18n/index.js 3.56 kB 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 476 B 0 B
build/list-reusable-blocks/style.css 476 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 671 B 0 B
build/nux/style.css 668 B 0 B
build/plugins/index.js 2.56 kB 0 B
build/primitives/index.js 1.41 kB 0 B
build/priority-queue/index.js 789 B 0 B
build/redux-routine/index.js 2.85 kB 0 B
build/shortcode/index.js 1.69 kB 0 B
build/token-list/index.js 1.27 kB 0 B
build/url/index.js 4.06 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.17 kB 0 B

compressed-size-action

@pablohoneyhoney
Copy link

pablohoneyhoney commented Sep 1, 2020

Worth aligning the drop down icon with other instances. It might need a smaller version but this could be true in revised Settings cases too. And I'd remove Viewing –the group (patterns), the terms, and the behaviour should be self-explanatory. Perhaps moving it to the drop down instead of saying Select a Category.

@youknowriad youknowriad added Needs Accessibility Feedback Need input from accessibility Needs Design Feedback Needs general design feedback. labels Sep 1, 2020
@mtias
Copy link
Member

mtias commented Sep 1, 2020

For breadcrumb purposes: #21080

@richtabor
Copy link
Member

Let's consider adding this same UX functionality for the "Blocks" tab as well.

@richtabor
Copy link
Member

One question for this change. Should we include an "All" category? I have concerns because the poor performance of loading all patterns when you have more than 50 patterns to show. If we did have an All category I don't think it should default to being selected.

I agree with having an "All" category, though I'd say a proper solution to the performance concern would be some sort of deferred/lazy-loading a set number of patterns within the "All" category.

@mtias
Copy link
Member

mtias commented Sep 1, 2020

We are already lazy loading but it's still a lot of elements on the page when you get to hundreds of patterns containing many blocks each cc @youknowriad

@youknowriad
Copy link
Contributor

though I'd say a proper solution to the performance concern would be some sort of deferred/lazy-loading a set number of patterns within the "All" category.

Right now, the list does have asyn/lazy loading but it's not performant enough regardless, depending on browsers and number of patterns. I'm in favor of avoiding the "All" category for now until we figure out a way to improve the performance.

@mtias
Copy link
Member

mtias commented Sep 1, 2020

@richtabor I'm a bit more hesitant with using the same implementation for blocks as with patterns. There's been an effort to reduce block categories in number in core, as well as having them visible by default. Patterns groupings are inherently more granular as there could be one for every block as well as subject specific ones. So i think the presentation / browsing should be optimized for each. One area where we could have a similar category dropdown is in the quick inserter for blocks, though.

@apeatling
Copy link
Contributor Author

apeatling commented Sep 1, 2020

I've updated to us CustomSelectControl. Ready for another review. 👍

Screen Shot 2020-09-01 at 2 01 48 PM

@enriquesanchez
Copy link
Contributor

I know it was suggested earlier to remove the "Viewing" label from the dropdown, but the lack of a label introduces accessibility issues. I strongly recommend we bring it back. It makes the component easier to use and understand.

The label is also necessary for CustomSelectControl to be fully accessible and work with speech recognition software.

@ZebulanStanphill
Copy link
Member

I agree there should be a label, but I'm not sure "Viewing" is the right term to use. How about "Category" or "Filter"?

<>
<div className="block-editor-inserter__panel-header">
<CustomSelectControl
label={ __( 'Select a Category' ) }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is still a label "Select a Category" that is readable by screen readers, just not visible on the page.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Visible labels should always be used when possible. aria-labels/tooltips should be a last resort.

While the efforts towards accessibility have been significant, there has been a strong dependence on methods we consider to be anti-patterns. First among these is a heavy use of ARIA attributes. ARIA, while sometimes necessary, should be considered only as a final option when no native HTML interactions are available.

https://make.wordpress.org/accessibility/2018/10/29/report-on-the-accessibility-status-of-gutenberg/

Copy link
Contributor

@glendaviesnz glendaviesnz Sep 8, 2020

Choose a reason for hiding this comment

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

In this instance, although aria-label="Select a Category" is set on the button we are not relying on this solely as there is also a native HTML <label>Select a Category</label> visible to screen readers. It seems that it is an acceptable practice to hide the labels from the visual UI, but I am may be missing something.

I agree with @joanrho and @apeatling that the dropdown down-arrow is sufficient here in communicating the intent in terms of the visual UI.

@apeatling
Copy link
Contributor Author

I'm open to design suggestions here.

In my opinion needing the visible label so users can understand implies that users also don't understand what the category heading labels are in the block inserter view. I don't think that's the case. We have down cheverons as an indicator that the component is clickable and expandable across the UI.

@joanrho
Copy link
Contributor

joanrho commented Sep 3, 2020

I agree that it makes sense to show "All" by default as well as providing the dropdown in the Blocks tab. Even if there may be five base categories (Text, Media, Design, Widgets, Embeds), other plugins may add their own blocks that extend that block menu even further, so the dropdown can only help users find what they're looking for (whether they're just browsing or searching with intention).

I also think the dropdown down-arrow is sufficient in communicating the additional categorization view options. Users have already clicked into the block inserter menu, so one can assume they're looking to add a block or pattern either by searching or browsing. The screen-reader visible text cue "Select a category" that's hidden from view sounds like a good idea.

@glendaviesnz
Copy link
Contributor

glendaviesnz commented Sep 9, 2020

This tested well for me. With some sample data of 60 patterns with 10 or so patterns per category, there was a minor delay when loading some of the categories with more complex blocks, but it was perfectly usable:

patterns-ok

If I went up to 180 patterns, with 20+ items in some categories the performance dropped noticeably (and understandably), with marked delays in loading:

patterns-slow

But, for current realistic use cases I think this PR is a good first step to actually make the pattern library usable with larger numbers of patterns ... and I think we are going to need this default category breakup regardless of how we decide to improve the performance for loading larger categories in the future, so those considerations don't need to delay the merging of this in my view.

@aaronrobertshaw
Copy link
Contributor

This works well for me 👍

I experienced the same minor (but still quite usable) delays with about a dozen patterns in a category. Scaling this up to 66 patterns in my test category, the time to display the previews reached nearly 30 seconds.

This is still a much better and more usable experience than when attempting to display multiple hundreds of patterns in one list. Prior to this change, that was taking several minutes to render the previews and also made it very difficult to scroll and see the available categories in order to more quickly target a desired pattern.

As a side note, throttling my connection to a much slower speed to stall some of the images loading didn't have any noticeable effect outside what you would expect.

My vote is to proceed with this PR and continue to optimise the performance of the category lists in future iterations.

@apeatling
Copy link
Contributor Author

@glendaviesnz @aaroncampbell Thanks for the reviews! Looking at the gif, I think there is an issue with lazy loading that I'm going to investigate. It seems to be waiting until all patterns are loaded before showing anything, which is not the case in the main branch.

@apeatling
Copy link
Contributor Author

Lazy loading should be fixed now, and results in a much faster load time for the patterns show on screen:

2020-09-09 11 36 46

@apeatling apeatling force-pushed the add/block-pattern-inserter-dropdown branch from a9af291 to fa66c90 Compare September 15, 2020 17:31
@apeatling
Copy link
Contributor Author

✅ Rebased

@glendaviesnz
Copy link
Contributor

I had a look at the select control, and if we switch to SelectControl it gives a native html select,

thanks!

@afercia, are you happy to clear your change request from the PR now?

@apeatling
Copy link
Contributor Author

useMemo changes working well for me Glen 👍

@youknowriad
Copy link
Contributor

Capture d’écran 2020-09-16 à 11 22 45 AM

Looks like there's a z-index issue (I'm testing on safari btw)

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 👍 Let's ship once the remaining remarks are fixed.

@jasmussen jasmussen dismissed afercia’s stale review September 16, 2020 18:44

The feedback is addressed

@apeatling apeatling merged commit a2419d0 into master Sep 16, 2020
@apeatling apeatling deleted the add/block-pattern-inserter-dropdown branch September 16, 2020 18:44
@github-actions github-actions bot added this to the Gutenberg 9.1 milestone Sep 16, 2020
@afercia
Copy link
Contributor

afercia commented Sep 17, 2020

are you happy to clear your change request from the PR now?

Sorry for being late. I have a huge queue of unread emails 😞 Thanks for going ahead!

@bph
Copy link
Contributor

bph commented Oct 1, 2020

For 🐝 -docs: added to Trello card.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Inserter The main way to insert blocks using the + button in the editing interface Needs Accessibility Feedback Need input from accessibility Needs Design Feedback Needs general design feedback.
Projects
None yet
Development

Successfully merging this pull request may close these issues.