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: add heading level checker #22650

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from

Conversation

ZebulanStanphill
Copy link
Member

@ZebulanStanphill ZebulanStanphill commented May 26, 2020

Description

Closes #10581 and #20870. Blocked by #29610.

Derived from #14889; big thanks to @Jackie6!. This PR adds a heading level checker to the Heading block to warn users when they select a heading level that is most likely incorrect. I've rebased/refactored the PR to work with the latest master, and I've addressed a lot of the feedback provided on that PR.

Note that this PR does not change anything in the native mobile app.

Screenshots

image

UPDATE: it now looks like this:

image
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.

@ZebulanStanphill ZebulanStanphill added [Type] Enhancement A suggestion for improvement. [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). Needs Design Feedback Needs general design feedback. Needs Technical Feedback Needs testing from a developer perspective. Needs Accessibility Feedback Need input from accessibility [Block] Heading Affects the Headings Block labels May 26, 2020
@github-actions
Copy link

github-actions bot commented May 26, 2020

Size Change: +1.48 kB (0%)

Total Size: 1.4 MB

Filename Size Change
build/block-library/blocks/heading/editor-rtl.css 218 B +89 B (+69%) 🆘
build/block-library/blocks/heading/editor.css 218 B +89 B (+69%) 🆘
build/block-library/editor-rtl.css 9.61 kB +65 B (+1%)
build/block-library/editor.css 9.59 kB +64 B (+1%)
build/block-library/index.js 149 kB +1.17 kB (+1%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.78 kB 0 B
build/api-fetch/index.js 3.4 kB 0 B
build/autop/index.js 2.82 kB 0 B
build/blob/index.js 664 B 0 B
build/block-directory/index.js 8.63 kB 0 B
build/block-directory/style-rtl.css 1 kB 0 B
build/block-directory/style.css 1.01 kB 0 B
build/block-editor/index.js 125 kB 0 B
build/block-editor/style-rtl.css 12.1 kB 0 B
build/block-editor/style.css 12.1 kB 0 B
build/block-library/blocks/archives/editor-rtl.css 61 B 0 B
build/block-library/blocks/archives/editor.css 60 B 0 B
build/block-library/blocks/audio/editor-rtl.css 58 B 0 B
build/block-library/blocks/audio/editor.css 58 B 0 B
build/block-library/blocks/audio/style-rtl.css 103 B 0 B
build/block-library/blocks/audio/style.css 103 B 0 B
build/block-library/blocks/block/editor-rtl.css 161 B 0 B
build/block-library/blocks/block/editor.css 161 B 0 B
build/block-library/blocks/button/editor-rtl.css 475 B 0 B
build/block-library/blocks/button/editor.css 474 B 0 B
build/block-library/blocks/button/style-rtl.css 479 B 0 B
build/block-library/blocks/button/style.css 479 B 0 B
build/block-library/blocks/buttons/editor-rtl.css 315 B 0 B
build/block-library/blocks/buttons/editor.css 315 B 0 B
build/block-library/blocks/buttons/style-rtl.css 364 B 0 B
build/block-library/blocks/buttons/style.css 363 B 0 B
build/block-library/blocks/calendar/style-rtl.css 208 B 0 B
build/block-library/blocks/calendar/style.css 208 B 0 B
build/block-library/blocks/categories/editor-rtl.css 84 B 0 B
build/block-library/blocks/categories/editor.css 83 B 0 B
build/block-library/blocks/categories/style-rtl.css 79 B 0 B
build/block-library/blocks/categories/style.css 79 B 0 B
build/block-library/blocks/code/style-rtl.css 90 B 0 B
build/block-library/blocks/code/style.css 90 B 0 B
build/block-library/blocks/columns/editor-rtl.css 190 B 0 B
build/block-library/blocks/columns/editor.css 190 B 0 B
build/block-library/blocks/columns/style-rtl.css 421 B 0 B
build/block-library/blocks/columns/style.css 421 B 0 B
build/block-library/blocks/cover/editor-rtl.css 390 B 0 B
build/block-library/blocks/cover/editor.css 389 B 0 B
build/block-library/blocks/cover/style-rtl.css 1.25 kB 0 B
build/block-library/blocks/cover/style.css 1.25 kB 0 B
build/block-library/blocks/embed/editor-rtl.css 486 B 0 B
build/block-library/blocks/embed/editor.css 486 B 0 B
build/block-library/blocks/embed/style-rtl.css 396 B 0 B
build/block-library/blocks/embed/style.css 395 B 0 B
build/block-library/blocks/file/editor-rtl.css 199 B 0 B
build/block-library/blocks/file/editor.css 198 B 0 B
build/block-library/blocks/file/style-rtl.css 248 B 0 B
build/block-library/blocks/file/style.css 248 B 0 B
build/block-library/blocks/freeform/editor-rtl.css 2.45 kB 0 B
build/block-library/blocks/freeform/editor.css 2.45 kB 0 B
build/block-library/blocks/gallery/editor-rtl.css 689 B 0 B
build/block-library/blocks/gallery/editor.css 690 B 0 B
build/block-library/blocks/gallery/style-rtl.css 1.07 kB 0 B
build/block-library/blocks/gallery/style.css 1.06 kB 0 B
build/block-library/blocks/group/editor-rtl.css 318 B 0 B
build/block-library/blocks/group/editor.css 317 B 0 B
build/block-library/blocks/group/style-rtl.css 57 B 0 B
build/block-library/blocks/group/style.css 57 B 0 B
build/block-library/blocks/heading/style-rtl.css 76 B 0 B
build/block-library/blocks/heading/style.css 76 B 0 B
build/block-library/blocks/html/editor-rtl.css 281 B 0 B
build/block-library/blocks/html/editor.css 281 B 0 B
build/block-library/blocks/image/editor-rtl.css 717 B 0 B
build/block-library/blocks/image/editor.css 716 B 0 B
build/block-library/blocks/image/style-rtl.css 477 B 0 B
build/block-library/blocks/image/style.css 478 B 0 B
build/block-library/blocks/latest-comments/editor-rtl.css 159 B 0 B
build/block-library/blocks/latest-comments/editor.css 158 B 0 B
build/block-library/blocks/latest-comments/style-rtl.css 269 B 0 B
build/block-library/blocks/latest-comments/style.css 269 B 0 B
build/block-library/blocks/latest-posts/editor-rtl.css 137 B 0 B
build/block-library/blocks/latest-posts/editor.css 137 B 0 B
build/block-library/blocks/latest-posts/style-rtl.css 523 B 0 B
build/block-library/blocks/latest-posts/style.css 522 B 0 B
build/block-library/blocks/list/editor-rtl.css 65 B 0 B
build/block-library/blocks/list/editor.css 65 B 0 B
build/block-library/blocks/list/style-rtl.css 63 B 0 B
build/block-library/blocks/list/style.css 63 B 0 B
build/block-library/blocks/media-text/editor-rtl.css 191 B 0 B
build/block-library/blocks/media-text/editor.css 191 B 0 B
build/block-library/blocks/media-text/style-rtl.css 535 B 0 B
build/block-library/blocks/media-text/style.css 532 B 0 B
build/block-library/blocks/more/editor-rtl.css 434 B 0 B
build/block-library/blocks/more/editor.css 434 B 0 B
build/block-library/blocks/navigation-link/editor-rtl.css 681 B 0 B
build/block-library/blocks/navigation-link/editor.css 683 B 0 B
build/block-library/blocks/navigation-link/style-rtl.css 694 B 0 B
build/block-library/blocks/navigation-link/style.css 692 B 0 B
build/block-library/blocks/navigation/editor-rtl.css 1.34 kB 0 B
build/block-library/blocks/navigation/editor.css 1.34 kB 0 B
build/block-library/blocks/navigation/style-rtl.css 213 B 0 B
build/block-library/blocks/navigation/style.css 214 B 0 B
build/block-library/blocks/nextpage/editor-rtl.css 395 B 0 B
build/block-library/blocks/nextpage/editor.css 395 B 0 B
build/block-library/blocks/page-list/editor-rtl.css 215 B 0 B
build/block-library/blocks/page-list/editor.css 215 B 0 B
build/block-library/blocks/page-list/style-rtl.css 527 B 0 B
build/block-library/blocks/page-list/style.css 526 B 0 B
build/block-library/blocks/paragraph/editor-rtl.css 109 B 0 B
build/block-library/blocks/paragraph/editor.css 109 B 0 B
build/block-library/blocks/paragraph/style-rtl.css 288 B 0 B
build/block-library/blocks/paragraph/style.css 289 B 0 B
build/block-library/blocks/post-author/editor-rtl.css 209 B 0 B
build/block-library/blocks/post-author/editor.css 209 B 0 B
build/block-library/blocks/post-author/style-rtl.css 183 B 0 B
build/block-library/blocks/post-author/style.css 184 B 0 B
build/block-library/blocks/post-comments-form/style-rtl.css 250 B 0 B
build/block-library/blocks/post-comments-form/style.css 250 B 0 B
build/block-library/blocks/post-content/editor-rtl.css 139 B 0 B
build/block-library/blocks/post-content/editor.css 139 B 0 B
build/block-library/blocks/post-excerpt/editor-rtl.css 73 B 0 B
build/block-library/blocks/post-excerpt/editor.css 73 B 0 B
build/block-library/blocks/post-featured-image/editor-rtl.css 338 B 0 B
build/block-library/blocks/post-featured-image/editor.css 338 B 0 B
build/block-library/blocks/post-featured-image/style-rtl.css 100 B 0 B
build/block-library/blocks/post-featured-image/style.css 100 B 0 B
build/block-library/blocks/preformatted/style-rtl.css 63 B 0 B
build/block-library/blocks/preformatted/style.css 63 B 0 B
build/block-library/blocks/pullquote/editor-rtl.css 183 B 0 B
build/block-library/blocks/pullquote/editor.css 183 B 0 B
build/block-library/blocks/pullquote/style-rtl.css 316 B 0 B
build/block-library/blocks/pullquote/style.css 316 B 0 B
build/block-library/blocks/query-loop/editor-rtl.css 90 B 0 B
build/block-library/blocks/query-loop/editor.css 89 B 0 B
build/block-library/blocks/query-loop/style-rtl.css 315 B 0 B
build/block-library/blocks/query-loop/style.css 317 B 0 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B 0 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B 0 B
build/block-library/blocks/query-pagination/editor-rtl.css 270 B 0 B
build/block-library/blocks/query-pagination/editor.css 262 B 0 B
build/block-library/blocks/query-pagination/style-rtl.css 168 B 0 B
build/block-library/blocks/query-pagination/style.css 168 B 0 B
build/block-library/blocks/query/editor-rtl.css 814 B 0 B
build/block-library/blocks/query/editor.css 812 B 0 B
build/block-library/blocks/quote/editor-rtl.css 61 B 0 B
build/block-library/blocks/quote/editor.css 61 B 0 B
build/block-library/blocks/quote/style-rtl.css 169 B 0 B
build/block-library/blocks/quote/style.css 169 B 0 B
build/block-library/blocks/rss/editor-rtl.css 201 B 0 B
build/block-library/blocks/rss/editor.css 202 B 0 B
build/block-library/blocks/rss/style-rtl.css 290 B 0 B
build/block-library/blocks/rss/style.css 290 B 0 B
build/block-library/blocks/search/editor-rtl.css 165 B 0 B
build/block-library/blocks/search/editor.css 165 B 0 B
build/block-library/blocks/search/style-rtl.css 342 B 0 B
build/block-library/blocks/search/style.css 344 B 0 B
build/block-library/blocks/separator/editor-rtl.css 99 B 0 B
build/block-library/blocks/separator/editor.css 99 B 0 B
build/block-library/blocks/separator/style-rtl.css 236 B 0 B
build/block-library/blocks/separator/style.css 236 B 0 B
build/block-library/blocks/shortcode/editor-rtl.css 504 B 0 B
build/block-library/blocks/shortcode/editor.css 504 B 0 B
build/block-library/blocks/site-logo/editor-rtl.css 201 B 0 B
build/block-library/blocks/site-logo/editor.css 201 B 0 B
build/block-library/blocks/site-logo/style-rtl.css 115 B 0 B
build/block-library/blocks/site-logo/style.css 115 B 0 B
build/block-library/blocks/social-link/editor-rtl.css 164 B 0 B
build/block-library/blocks/social-link/editor.css 165 B 0 B
build/block-library/blocks/social-links/editor-rtl.css 696 B 0 B
build/block-library/blocks/social-links/editor.css 696 B 0 B
build/block-library/blocks/social-links/style-rtl.css 1.32 kB 0 B
build/block-library/blocks/social-links/style.css 1.32 kB 0 B
build/block-library/blocks/spacer/editor-rtl.css 317 B 0 B
build/block-library/blocks/spacer/editor.css 317 B 0 B
build/block-library/blocks/spacer/style-rtl.css 48 B 0 B
build/block-library/blocks/spacer/style.css 48 B 0 B
build/block-library/blocks/subhead/editor-rtl.css 99 B 0 B
build/block-library/blocks/subhead/editor.css 99 B 0 B
build/block-library/blocks/subhead/style-rtl.css 80 B 0 B
build/block-library/blocks/subhead/style.css 80 B 0 B
build/block-library/blocks/table/editor-rtl.css 478 B 0 B
build/block-library/blocks/table/editor.css 478 B 0 B
build/block-library/blocks/table/style-rtl.css 390 B 0 B
build/block-library/blocks/table/style.css 390 B 0 B
build/block-library/blocks/tag-cloud/editor-rtl.css 118 B 0 B
build/block-library/blocks/tag-cloud/editor.css 118 B 0 B
build/block-library/blocks/tag-cloud/style-rtl.css 94 B 0 B
build/block-library/blocks/tag-cloud/style.css 94 B 0 B
build/block-library/blocks/template-part/editor-rtl.css 557 B 0 B
build/block-library/blocks/template-part/editor.css 556 B 0 B
build/block-library/blocks/text-columns/editor-rtl.css 95 B 0 B
build/block-library/blocks/text-columns/editor.css 95 B 0 B
build/block-library/blocks/text-columns/style-rtl.css 166 B 0 B
build/block-library/blocks/text-columns/style.css 166 B 0 B
build/block-library/blocks/verse/editor-rtl.css 62 B 0 B
build/block-library/blocks/verse/editor.css 62 B 0 B
build/block-library/blocks/verse/style-rtl.css 87 B 0 B
build/block-library/blocks/verse/style.css 87 B 0 B
build/block-library/blocks/video/editor-rtl.css 504 B 0 B
build/block-library/blocks/video/editor.css 503 B 0 B
build/block-library/blocks/video/style-rtl.css 193 B 0 B
build/block-library/blocks/video/style.css 193 B 0 B
build/block-library/common-rtl.css 1.1 kB 0 B
build/block-library/common.css 1.1 kB 0 B
build/block-library/style-rtl.css 8.86 kB 0 B
build/block-library/style.css 8.86 kB 0 B
build/block-library/theme-rtl.css 736 B 0 B
build/block-library/theme.css 736 B 0 B
build/block-serialization-default-parser/index.js 1.87 kB 0 B
build/block-serialization-spec-parser/index.js 3.06 kB 0 B
build/blocks/index.js 48.3 kB 0 B
build/components/index.js 283 kB 0 B
build/components/style-rtl.css 15.6 kB 0 B
build/components/style.css 15.5 kB 0 B
build/compose/index.js 11.1 kB 0 B
build/core-data/index.js 16.7 kB 0 B
build/customize-widgets/index.js 3.96 kB 0 B
build/customize-widgets/style-rtl.css 168 B 0 B
build/customize-widgets/style.css 168 B 0 B
build/data-controls/index.js 828 B 0 B
build/data/index.js 8.88 kB 0 B
build/date/index.js 31.8 kB 0 B
build/deprecated/index.js 769 B 0 B
build/dom-ready/index.js 577 B 0 B
build/dom/index.js 4.94 kB 0 B
build/edit-navigation/index.js 11 kB 0 B
build/edit-navigation/style-rtl.css 1.26 kB 0 B
build/edit-navigation/style.css 1.25 kB 0 B
build/edit-post/index.js 306 kB 0 B
build/edit-post/style-rtl.css 6.81 kB 0 B
build/edit-post/style.css 6.8 kB 0 B
build/edit-site/index.js 27 kB 0 B
build/edit-site/style-rtl.css 4.47 kB 0 B
build/edit-site/style.css 4.46 kB 0 B
build/edit-widgets/index.js 20.1 kB 0 B
build/edit-widgets/style-rtl.css 3.2 kB 0 B
build/edit-widgets/style.css 3.2 kB 0 B
build/editor/editor-styles-rtl.css 543 B 0 B
build/editor/editor-styles.css 545 B 0 B
build/editor/index.js 42.1 kB 0 B
build/editor/style-rtl.css 3.9 kB 0 B
build/editor/style.css 3.9 kB 0 B
build/element/index.js 4.61 kB 0 B
build/escape-html/index.js 735 B 0 B
build/format-library/index.js 6.75 kB 0 B
build/format-library/style-rtl.css 637 B 0 B
build/format-library/style.css 639 B 0 B
build/hooks/index.js 2.28 kB 0 B
build/html-entities/index.js 623 B 0 B
build/i18n/index.js 4.01 kB 0 B
build/is-shallow-equal/index.js 699 B 0 B
build/keyboard-shortcuts/index.js 2.53 kB 0 B
build/keycodes/index.js 1.95 kB 0 B
build/list-reusable-blocks/index.js 3.15 kB 0 B
build/list-reusable-blocks/style-rtl.css 629 B 0 B
build/list-reusable-blocks/style.css 628 B 0 B
build/media-utils/index.js 5.34 kB 0 B
build/notices/index.js 1.85 kB 0 B
build/nux/index.js 3.4 kB 0 B
build/nux/style-rtl.css 731 B 0 B
build/nux/style.css 727 B 0 B
build/plugins/index.js 2.9 kB 0 B
build/primitives/index.js 1.42 kB 0 B
build/priority-queue/index.js 791 B 0 B
build/react-i18n/index.js 1.45 kB 0 B
build/redux-routine/index.js 2.83 kB 0 B
build/reusable-blocks/index.js 3.78 kB 0 B
build/reusable-blocks/style-rtl.css 225 B 0 B
build/reusable-blocks/style.css 225 B 0 B
build/rich-text/index.js 13.4 kB 0 B
build/server-side-render/index.js 2.82 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.27 kB 0 B
build/url/index.js 3.02 kB 0 B
build/viewport/index.js 1.86 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.22 kB 0 B

compressed-size-action

@ZebulanStanphill ZebulanStanphill force-pushed the add/heading-block-level-checker branch 4 times, most recently from 94fcb03 to 7c81d45 Compare May 26, 2020 22:57
@ZebulanStanphill
Copy link
Member Author

Remaining tasks/questions:

1: I need someone to test that this works as expected with screen readers.

2: For non-screen-reader users, there is no immediate indication that a heading level is invalid. After selecting a heading level, the dropdown immediately closes. How do we improve this? I see 2 potential solutions:

  • Add some kind of indicator to the toolbar button that the heading level is invalid. (Color the icon yellow, perhaps?)
  • Move the warning to appear within the block content itself when the block is selected. This would definitely be noticeable... maybe even too noticeable?

3: Here's the toughest issue: how do we make this work properly with headings that are not inside Heading blocks? There are already many 3rd party heading blocks in various plugins, not to mention the fact that Custom HTML and Classic blocks can contain headings.

Solving this issue here should also solve it for the content structure tool. It could potentially also solve the problem I've run into with <!--nextpage--> detection in #21234.

@enriquesanchez
Copy link
Contributor

hey @ZebulanStanphill

I too noticed how hard it is to see the warning message because of how the menu immediately closes. I'm not sure I have the right answer to this, but I think that your idea of a warning indicator might be worth exploring:

Frame 10

I was confused by:

The selected heading level may be invalid. See the content structure tool for more info.

What is the content structure tool?


I also tested with VoiceOver and Safari. I was only able to get the warning correctly announced once, but after that, I wasn't able to get it again. I'm not sure why this is happening. I even tried creating a new heading block and I could not get the warning properly announced again. Is it somehow setup to only fire once?

2020-05-27 16-57-37 2020-05-27 17_00_37

@ZebulanStanphill
Copy link
Member Author

This is the content structure tool:
image

I currently have the effect running the speak function set to only run again when either the chosen level changes or the validity of the heading level changes. I have it working this way because that's how it was in #14889. How is it supposed to work, in your opinion?

Also, while double-checking the code in the PR, I spotted some potential optimizations, so I applied them and rebased the PR. The code is now slightly cleaner.

@enriquesanchez
Copy link
Contributor

enriquesanchez commented May 28, 2020

This is the content structure tool:

Ah, I forgot how it was called! 🤦

I currently have the effect running the speak function set to only run again when either the chosen level changes or the validity of the heading level changes. I have it working this way because that's how it was in #14889. How is it supposed to work, in your opinion?

I was not aware of that. I think that because the warning is always there, so you see it every time you open the headings menu, I was expecting the speak function to follow a similar pattern and also be announced every time the menu was interacted with. But I don't have strong opinions about this, if this is how it was set up before, then I'm fine if it stays that way.

@ZebulanStanphill
Copy link
Member Author

I'm not actually sure how I should go about implementing a yellow dot-thing for the button. Any recommendations?

@ZebulanStanphill
Copy link
Member Author

ZebulanStanphill commented Jun 2, 2020

Alright, I decided to try adding the dot in a similar way to how the color indicator for the RichText inline text color format tool works. I'm not entirely satisfied with how it looks (and I'd like feedback on any better way to approach this), but it does work as I coded it to:

image

@shaunandrews
Copy link
Contributor

I honestly never knew that there was such a thing as an "incorrect heading level." What are the benefits to enforcing the "correct" heading level?

I realize we already do it in the Content Structure UI, but exposing it more widely — especially with an ever present dot in the toolbar — seems like it could be more annoying than helpful.

Irregardless of all that, I think the warning message needs to be much easier to understand; Right now its full of jargon and phrases that will make little sense to most people. Referring users to seek out and find another UI isn't really helpful — the message should stand on it's own.

@shaunandrews
Copy link
Contributor

I think the warning should maybe refer to why heading should be in order. Something like this might be more informative and helpful:

Placing headings in the wrong order could make it difficult for visitors to use your site.

@ZebulanStanphill ZebulanStanphill removed the Needs Design Feedback Needs general design feedback. label Jul 8, 2020
@ZebulanStanphill ZebulanStanphill linked an issue Jul 16, 2020 that may be closed by this pull request
@ZebulanStanphill
Copy link
Member Author

Rebased to keep the PR fresh and updated the screenshots in the original post. All this PR needs is a final code review before merge.

@jasmussen
Copy link
Contributor

Still subscribed here, still appreciate your work. I hope as the dust settles people will come around to a code review here.

Copy link
Contributor

@ntsekouras ntsekouras 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 left some small comments but it's a great improvement 👍

Maybe we could add more specific titles in a follow-up PR, as I explain my reasoning in the comment?

targetLevel === 1 && hasTitle && ! hasMultipleH1;
const levelIsTooDeep = targetLevel > precedingLevel + 1;
const levelIsInvalid = levelIsDuplicateH1 || levelIsTooDeep;
const levelMayBeInvalid =
Copy link
Contributor

Choose a reason for hiding this comment

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

I think here we know when levelIsInvalid so levelMayBeInvalid should be just levelAndPostTitleMayBothBeH1, no?

Also you use only levelMayBeInvalid exported property in HeadingLevelDropdown, but since you know when it is invalid, you could use it to handle some options more specifically there.

It's certainly a big improvement already and not a blocker but maybe a follow-up PR could enhance it a bit more with more specific messages for invalid and maybe invalid.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I could go as far as explicitly handling each possible invalidity reason with a specific message, e.g. "The chosen heading level is too deep. Use a lower level or add a lower level heading before this one." But if I do something like that, then I'm not sure the "See the content structure tool for more info" bit should still be there anymore.

I'm not entirely sure how much info should be given in the warning. So for now I'll just keep it simple and as you suggested, explore improvements in a follow-up PR.

@ZebulanStanphill
Copy link
Member Author

It's worth noting that this heading level validator only knows about core Heading blocks. It won't work with anything else. The proposed Accordion block (#21584) would use h1-h6 elements (and not a Heading block), assuming we don't implement the accordion toggle and content as two different child blocks. We would have to update the logic in both blocks PLUS the content structure tool to ensure that the heading level validation logic is still accurate most of the time.

But even then, the logic will still be invalid when any 3rd party heading (or accordion) blocks are in use. I'm starting to question whether it's worth adding this if there's a good chance that it's warnings will often be wrong when 3rd party blocks are in use. And there's no way for plugins to fix this, as far as I am aware.

In my mind I keep coming back to #22874. I think we really need to have some kind of API that both core and 3rd party blocks can hook into for a centralized source of document outline info.

@jasmussen
Copy link
Contributor

As a separate conversation to have about the heading levels, it might be useful for developers to have access to a Heading component that automatically output the right heading level based on its context. This would not be a block, but simply something to import for blocks that bake in a heading.

@gchtr
Copy link
Contributor

gchtr commented Aug 14, 2020

But even then, the logic will still be invalid when any 3rd party heading (or accordion) blocks are in use. I'm starting to question whether it's worth adding this if there's a good chance that it's warnings will often be wrong when 3rd party blocks are in use. And there's no way for plugins to fix this, as far as I am aware.

We disabled the core/heading block and use our own block for headings. Obviously, the The Document Outline is not showing up at all and the heading count is always at 0. I think custom heading blocks should definitely be considered.

In my mind I keep coming back to #22874. I think we really need to have some kind of API that both core and 3rd party blocks can hook into for a centralized source of document outline info.

Yes, please!

I wonder whether in addition to adding notifications about wrong heading levels and ways to fix them, a heading would also benefit from a setting to adjust the display level. Here’s what we currently use (probably there’s be a better way to design it):

custom-heading

I don’t know whether this was discussed before. In my experience, users often choose a heading based on its visual styles. When notifying them that they have the wrong heading level, there’s a conflict between heading styles and heading levels. Is it more important be semantically correct and have an accessible heading structure, or to have a visual appearance of the heading that best fits other elements on the page? I think that’s a question that we shouldn’t even have to ask ourselves. Heading level and appearance should be separated.

@ZebulanStanphill
Copy link
Member Author

The Heading block already has a "Typography" panel in the inspector containing font size options. (And that's a discussion for a separate issue anyway.)

@ZebulanStanphill ZebulanStanphill force-pushed the add/heading-block-level-checker branch 2 times, most recently from b7764d4 to 84f2a24 Compare August 17, 2020 19:46
@ZebulanStanphill ZebulanStanphill added the [Status] Blocked Used to indicate that a current effort isn't able to move forward label Aug 28, 2020
@ZebulanStanphill
Copy link
Member Author

I've decided to mark this PR as blocked for now, due to the lack of support for 3rd party blocks. #22874 needs to be resolved before this feature can be merged, in my opinion.

Base automatically changed from master to trunk March 1, 2021 15:43
@aristath
Copy link
Member

aristath commented Mar 5, 2021

Is this one still blocked?

@ZebulanStanphill
Copy link
Member Author

@aristath Thanks for checking in. I was able to get #21234 merged without any new APIs, so I think I might be able to get this one working as well using a similar approach I've been wanting to attempt a revamp of this PR, but I haven't found the time yet. I'll comment again when I either get it working or determine that it's still blocked.

@ZebulanStanphill
Copy link
Member Author

@aristath Turns out it was indeed possible to get this PR fully working. The validator can now see all heading elements preceding the current block, not just core Heading blocks. This makes it a lot more accurate... in fact, it is now more accurate than the Document Outline tool in the editor's top bar, leading to the two disagreeing with each other.

Technically, the Document Outline is the buggy one, but since the notices on the Heading block tell you to read the Document Outline, we should probably fix its logic first. In the mean time, however, feel free to re-test and re-review this PR.

@ZebulanStanphill
Copy link
Member Author

I've created #29610 to fix the Document Outline.

@masteradhoc
Copy link
Contributor

@ntsekouras can we push this further? really like the solution by @ZebulanStanphill

@ntsekouras
Copy link
Contributor

@ntsekouras can we push this further? really like the solution by @ZebulanStanphill

It seems there are still blocking issues here.. Can someone provide a TLDR for the current challenges of this?

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 [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Package] Block library /packages/block-library [Status] Blocked Used to indicate that a current effort isn't able to move forward [Type] Enhancement A suggestion for improvement.
Projects
None yet
10 participants