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

Heading block: use toolbar for heading level control #20246

Merged
merged 5 commits into from
May 26, 2020

Conversation

ZebulanStanphill
Copy link
Member

@ZebulanStanphill ZebulanStanphill commented Feb 14, 2020

Description

Having the heading level picker in both the toolbar and inspector is confusing and inconsistent. It's also weird that only the inspector version contains the h1, h5, and h6 options.

This PR removes the inspector control and puts all the heading level options into the toolbar dropdown.

How has this been tested?

I opened up a post and played around with the heading level toolbar control to verify that it worked.

Screenshots

image

UPDATE: based on feedback, I've updated the control to look like this:

image

Checklist:

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

minLevel={ 2 }
maxLevel={ 5 }
minLevel={ 1 }
maxLevel={ 7 }
Copy link
Member Author

Choose a reason for hiding this comment

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

No, this is not a mistake. The maxLevel is actually exclusive rather than inclusive, so you have to set it to 7 if you want to include heading level 6. I thought that was weird, but I decided it would be best to address it in a separate PR, if it needs to be addressed at all. Does anyone else think this is weird?

Copy link
Contributor

Choose a reason for hiding this comment

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

The fact that heading 1 was omitted from the toolbar was a requirement/recommendation from the a11y team to discourage its usage as it's generally used for post title in the templates. Is this something we want to reconsider?

Copy link
Member Author

Choose a reason for hiding this comment

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

@youknowriad Some kind of warning would be helpful, similar to the color contrast warning (which can be used in the toolbar, as demonstrated by the Navigation block). No equivalent currently exists for heading levels except in the Document Outline.

Showing a duplicate control in the inspector with the discouraged options is not the right answer, in my opinion. We should be dealing with incorrect heading levels the same way we deal with low-contrast background/text color combinations: by warning the user when they choose a potentially poor option.

@paaljoachim
Copy link
Contributor

paaljoachim commented Feb 14, 2020

Thanks for adjusting this feature Zeb!

This is what it looks like right now:
Screen Shot 2020-02-14 at 20 10 30

It looks like a bug.

@youknowriad youknowriad added Needs Accessibility Feedback Need input from accessibility Needs Design Feedback Needs general design feedback. labels Feb 14, 2020
@ZebulanStanphill
Copy link
Member Author

The E2E test failure is because in packages/e2e-tests/specs/editor/various/rich-text.test.js, the should handle change in tag name gracefully test tries to click on one of the buttons in the inspector, which has been removed.

I'm not sure how to update the test to click the button in the block toolbar, however. Something I have just discovered is that the heading level button in the toolbar doesn't have any aria-label, so I can't click it from the E2E test the same way that the existing test works (by clicking a button with a matching aria-label).

I fixed the label issue in #20248. I guess that PR needs to be merged before this one so I can fix the E2E test.

@shaunandrews
Copy link
Contributor

Would it be possible to do something like this, were we don't need to repetitive "Heading" labels for each option?

image

@ZebulanStanphill
Copy link
Member Author

I've temporarily included changes from #20248 to show that, with the label fix from that PR merged and with the e2e test adjusted, all tests pass.

@ZebulanStanphill
Copy link
Member Author

@shaunandrews I'm sure it would be possible, but it's out of the scope of this PR, and it might have negative effects on accessibility due to the removal of visible labels. I'd recommend opening a separate issue for that.

@karmatosed
Copy link
Member

karmatosed commented Feb 17, 2020

Whilst I am for them all going in toolbar, I do wonder if what @shaunandrews is suggesting would be a better visual. Whilst I understand the focus of this PR iterating on the design to be the best possible one I think might work here, or at least we should rapidly get an issue up for that. Having such a long list in dropdown/menu feels very cumbersome. It's the problem with content and UI not work on this PR though.

@ZebulanStanphill ZebulanStanphill force-pushed the update/heading-block-level-controls branch 2 times, most recently from d40edd6 to 8d63e11 Compare February 19, 2020 16:31
@ZebulanStanphill
Copy link
Member Author

#20248 has been merged into master, so I have rebased this branch, and it is now ready for review/merge!

@github-actions
Copy link

github-actions bot commented Feb 19, 2020

Size Change: +112 B (0%)

Total Size: 1.12 MB

Filename Size Change
build/block-library/editor-rtl.css 7.2 kB +32 B (0%)
build/block-library/editor.css 7.2 kB +33 B (0%)
build/block-library/index.js 119 kB +47 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.62 kB 0 B
build/api-fetch/index.js 3.4 kB 0 B
build/autop/index.js 2.83 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/index.js 6.93 kB 0 B
build/block-directory/style-rtl.css 790 B 0 B
build/block-directory/style.css 791 B 0 B
build/block-editor/index.js 105 kB 0 B
build/block-editor/style-rtl.css 10.9 kB 0 B
build/block-editor/style.css 10.9 kB 0 B
build/block-library/style-rtl.css 7.48 kB 0 B
build/block-library/style.css 7.48 kB 0 B
build/block-library/theme-rtl.css 684 B 0 B
build/block-library/theme.css 686 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/blocks/index.js 48.1 kB 0 B
build/components/index.js 190 kB 0 B
build/components/style-rtl.css 17.1 kB 0 B
build/components/style.css 17.1 kB 0 B
build/compose/index.js 9.28 kB 0 B
build/core-data/index.js 11.4 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/deprecated/index.js 771 B 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 3.11 kB 0 B
build/edit-navigation/index.js 6.63 kB 0 B
build/edit-navigation/style-rtl.css 857 B 0 B
build/edit-navigation/style.css 856 B 0 B
build/edit-post/index.js 302 kB 0 B
build/edit-post/style-rtl.css 12.2 kB 0 B
build/edit-post/style.css 12.2 kB 0 B
build/edit-site/index.js 13.8 kB 0 B
build/edit-site/style-rtl.css 5.53 kB 0 B
build/edit-site/style.css 5.53 kB 0 B
build/edit-widgets/index.js 7.87 kB 0 B
build/edit-widgets/style-rtl.css 4.58 kB 0 B
build/edit-widgets/style.css 4.57 kB 0 B
build/editor/editor-styles-rtl.css 425 B 0 B
build/editor/editor-styles.css 428 B 0 B
build/editor/index.js 44.6 kB 0 B
build/editor/style-rtl.css 5.06 kB 0 B
build/editor/style.css 5.06 kB 0 B
build/element/index.js 4.65 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/index.js 7.71 kB 0 B
build/format-library/style-rtl.css 502 B 0 B
build/format-library/style.css 502 B 0 B
build/hooks/index.js 2.13 kB 0 B
build/html-entities/index.js 622 B 0 B
build/i18n/index.js 3.56 kB 0 B
build/is-shallow-equal/index.js 711 B 0 B
build/keyboard-shortcuts/index.js 2.51 kB 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/index.js 3.13 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/media-utils/index.js 5.29 kB 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/rich-text/index.js 14.8 kB 0 B
build/server-side-render/index.js 2.67 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.28 kB 0 B
build/url/index.js 4.02 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

@ZebulanStanphill
Copy link
Member Author

Rebased; everything looks fine in the new G2 UI.

@karmatosed
Copy link
Member

@ZebulanStanphill thanks for working on this. What I currently see is:

image

I still personally feel having just the idea that @shaunandrews shared would be better. Would you be able to work on that as an iteration?

@ZebulanStanphill
Copy link
Member Author

@shaunandrews' mockup looks cool, but it seems like it might be less accessible than the existing dropdown. However, I'm willing to try it out.

Unfortunately, I'm not sure how to go about implementing it. There are no existing implementations of anything quite like his mockup. Do I use ToolbarGroup or Toolbar? Dropdown or DropdownMenu? It's not clear to me what the correct way to approach this is. If anyone has suggestions, please share them.

I also find it confusing that the toolbar has more visible information for each option when isCollapsed is enabled, compared to when it is disabled.

@ZebulanStanphill
Copy link
Member Author

ZebulanStanphill commented Mar 10, 2020

Speaking of simplified dropdown menus, the newly-opened #20761 is quite relevant.

@ZebulanStanphill ZebulanStanphill force-pushed the update/heading-block-level-controls branch from a2340eb to 5158cb7 Compare March 25, 2020 19:07
Copy link
Member

@diegohaz diegohaz left a comment

Choose a reason for hiding this comment

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

Great work @ZebulanStanphill!

I tested it on Chrome, Safari and Firefox and can confirm that the issue with closing the popover when pressing any of the heading toolbar buttons happens on Safari and Firefox (on MacOS). So, it's probably related to buttons not receiving focus on click on those browsers. I just suggested a temporary workaround for that. But I'll try to find a better solution in the Toolbar module itself.

Also, arrow keys aren't working on the heading dropdown toggle button. And a simple solution for that is to just use ToolbarButton instead of ToolbarItem.

@ZebulanStanphill ZebulanStanphill force-pushed the update/heading-block-level-controls branch 3 times, most recently from 4dfb0c6 to a87fc5d Compare May 24, 2020 19:49
@ZebulanStanphill
Copy link
Member Author

Thanks for the help, @diegohaz! I've switched to using a standard ToolbarButton and I've applied the macOS Firefox/Safari fix you suggested (and tested it on a friend's computer to confirm it worked).

Everything appears to be working as intended now! 😄

Copy link
Member

@diegohaz diegohaz left a comment

Choose a reason for hiding this comment

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

Tested it on Chrome, Firefox and Safari, and it looks great! Also, I was able to use it with VoiceOver + Safari and NVDA + Firefox without problems. Couldn't find any other issue.

The only thing that feels odd to me is that the initial focus isn't on the current selected item. But this is probably something out of the scope of this PR as the same happens to the text alignment option.

@paaljoachim
Copy link
Contributor

paaljoachim commented May 25, 2020

The Heading block also works now in Safari. Good job Zeb!

@ZebulanStanphill ZebulanStanphill force-pushed the update/heading-block-level-controls branch from a87fc5d to 16e582e Compare May 25, 2020 12:27
@paaljoachim
Copy link
Contributor

paaljoachim commented May 25, 2020

One thing though.
I noticed some jumping of the black inserter during selection of various Heading levels when checking Safari. As I am using Gutenberg.run to check. At the moment I am having difficulty checking again. I was going to see if the same effect was in Chrome and Firefox as well. Changing the size of the heading should not as I see it make the inserter at all jump.

@ZebulanStanphill ZebulanStanphill force-pushed the update/heading-block-level-controls branch from 16e582e to e0b2a1b Compare May 25, 2020 15:09
@ZebulanStanphill
Copy link
Member Author

ZebulanStanphill commented May 26, 2020

@paaljoachim

Changing the size of the heading should not as I see it make the inserter at all move.

I tried it out myself, and the behavior appears totally normal to me. Each heading size is a different height, so of course the appender would move up/down. The block is changing height, so the appender moves to stay below the block. Or are you talking about something else?

@paaljoachim
Copy link
Contributor

Hey Zeb. Yes, I am talking about the moving inserter like so:

Heading-Inserter-jumps

But I do understand what your saying. As the size of the block changes the location of the inserter changes. Making it jump up or down based on which heading size is selected.
I just wanted to mention it.
Alrighty moving on..:)
Looks like the Heading block is ready for merge..:)

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.

Nice work here. Thanks for being perseverant with the PR.

@ZebulanStanphill ZebulanStanphill removed Needs Accessibility Feedback Need input from accessibility Needs Design Feedback Needs general design feedback. Needs Technical Feedback Needs testing from a developer perspective. labels May 26, 2020
@ZebulanStanphill ZebulanStanphill merged commit 47ae410 into master May 26, 2020
@ZebulanStanphill ZebulanStanphill deleted the update/heading-block-level-controls branch May 26, 2020 14:39
@github-actions github-actions bot added this to the Gutenberg 8.3 milestone May 26, 2020
@ZebulanStanphill
Copy link
Member Author

Now that this PR is out of the way, I've started working on adding a heading level checker to the block to encourage more semantic heading level choices: #22650.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Heading Affects the Headings Block [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants