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 heading hierarchy checker notice #14889

Closed
wants to merge 6 commits into from

Conversation

Jackie6
Copy link
Contributor

@Jackie6 Jackie6 commented Apr 9, 2019

Description

Fix #10581

How has this been tested?

  • local test
  • browser test

Screenshots

image

Types of changes

Add a checker to check if the selected heading level is correct

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.

@Jackie6 Jackie6 changed the title Add/heading checker Add heading hierarchy checker notice Apr 9, 2019
@Jackie6
Copy link
Contributor Author

Jackie6 commented Apr 9, 2019

@AmartyaU Can you explain further about this issue?

@AmartyaU
Copy link
Contributor

AmartyaU commented Apr 9, 2019

@Jackie6 and I talked about the content of the error messages, which has also been debated about in the parent issue. We also have a solution that details the exact heading level to choose in the error message, something like "This heading level is incorrect. Please use H1, or H2 instead."

Our question is if the error message should be short but vague or long and detailed?

@gziolo gziolo added [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). Needs Accessibility Feedback Need input from accessibility [Block] Heading Affects the Headings Block labels Apr 10, 2019
@gziolo gziolo added User Experience (UX) [Type] Enhancement A suggestion for improvement. Needs Design Feedback Needs general design feedback. labels Apr 10, 2019
@afercia
Copy link
Contributor

afercia commented Apr 10, 2019

Thanks for working on this! Works pretty well :)

Stepping in after @gziolo invitation to give some feedback on the message wording. Personally, I'd keep it as is because in the sidebar the message should be short, simple, and informative. "This heading level is incorrect." seems OK to me.

However, I'm wondering if the message should also point users to the "Content structure" tool in the top bar because:

  • the information there is more detailed
  • it would help improve discoverability of the "Content structure" tool

There are cases "Content structure" definitely gives more context. For example, a H1 in the post content may be correct in some edge cases. Screenshots to illustrate the added context:

Screenshot 2019-04-10 at 12 15 19

Screenshot 2019-04-10 at 12 15 27

I know @joedolson has some thoughts on the message wording, I'd like to hear his opinion :)

@mapk
Copy link
Contributor

mapk commented Apr 10, 2019

I'm wondering if the message should also point users to the "Content structure" tool in the top bar

@afercia how do you imagine this working? Would there be a link that opened this popover from the Block Inspector in relation to the messaging?

@Jackie6
Copy link
Contributor Author

Jackie6 commented Apr 10, 2019

Hi, @afercia Thanks for comments. I could not imagine the edge cases where the H1 heading is correct, could you illustrate this a bit more? And I have the same question as @mapk, how would you expect to open the popover?

@joedolson
Copy link
Contributor

The edge cases where an H1 would be correct would be pretty obscure, I think. I can think of at least one - if the theme omits the page title and the heading is the first block of content in the post. While that's unusual, I have seen cases, probably due to people wanting a different title used in lists of links than displayed on the page.

I agree with the short wording; I think attempting to elaborate the wording in this context isn't beneficial. Giving a brief warning then providing access to the more detailed information would seem more user-friendly.

@afercia
Copy link
Contributor

afercia commented Apr 10, 2019

The edge cases where an H1 would be correct would be pretty obscure, I think. I can think of at least one - if the theme omits the page title

Yep, also some post formats in some themes don't have a h1 heading, e.g. Twenty Thirteen "status" (if I remember correctly). Also, custom post types might not have a post title as well.

@afercia
Copy link
Contributor

afercia commented Apr 10, 2019

how do you imagine this working? Would there be a link that opened this popover from the Block Inspector in relation to the messaging?

Wasn't actually thinking at a control to open the Content Structure. Interaction would be tricky: focus should be moved there, then moved back to the invoking context when closing, etc.

I was just thinking to specify in the text something like:
"Hey dear user, this heading level is not correct. You may want to check the Content Structure tool for more context". With some shorter wording, of course :)

Copy link
Member

@gziolo gziolo 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, I left some feedback. It's mostly about code-related improvements. The functionality itself seems to work as expected but that you can polish with accesibility experts :)

packages/block-library/src/heading/heading-checker.js Outdated Show resolved Hide resolved
packages/block-library/src/heading/heading-checker.js Outdated Show resolved Hide resolved

export default compose(
withSelect( ( select ) => {
const { getBlocks } = select( 'core/block-editor' );
Copy link
Member

Choose a reason for hiding this comment

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

@jorgefilipecosta - is there a way to get all heading blocks only so we didn't have to use computeOutlineHeadings in the first place?

There is getGlobalBlockCount, so something similar would be nice.

That way we could share the same selector in both places and remove this computeOutlineHeadings helper altogether.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In fact, headings has been computed in

export const DocumentOutline = ( { blocks = [], title, onSelect, isTitleSupported, hasOutlineItemsDisabled } ) => {
const headings = computeOutlineHeadings( blocks );

I am not sure whether we could avoid computing it again.

Copy link
Member

Choose a reason for hiding this comment

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

We can if we create memoized shared selector, similar to how getBlocks is cached as of today. It might be a complicated task and that's why I asked @jorgefilipecosta for help.

Copy link
Member

Choose a reason for hiding this comment

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

We could create a generic selector that returns the blocks of a given type, so it is not specific to this functionality.
But I'm not sure if it would fit our needs, computeOutlineHeadings does more than just returning the heading blocks, it computes, for example, the heading path required to show the path where a heading is nested on.
I think in this specific case just the selector would work, but in the checks, we do in the Content Structure we would still need something like computeOutlineHeadings to associate a path to each heading.
Exposing a selector that does what computeOutlineHeadings does (or similar functionality with paths) seems very specific to this functionality.
I guess a possible path here is just implementing level-checker.js as part of the editor module and reusing computeOutlineHeadings there.

packages/block-library/src/heading/heading-checker.js Outdated Show resolved Hide resolved
packages/block-library/src/heading/heading-checker.js Outdated Show resolved Hide resolved
@AmartyaU
Copy link
Contributor

AmartyaU commented Apr 11, 2019

I was just thinking to specify in the text something like:
"Hey dear user, this heading level is not correct. You may want to check the Content Structure tool for more context". With some shorter wording, of course :)

@afercia I love this solution. It would be the most user-friendly without complicated code and recurring feedback.

Something like "This heading level is incorrect. Check the Content Structure tool for more context."

We can also link 'Content Structure tool' to a resource explaining what the tool is for people who have never used it before? Like you said, it would also increase discoverability this way!

@afercia
Copy link
Contributor

afercia commented Apr 11, 2019

We can also link 'Content Structure tool' to a resource explaining what the tool is for people who have never used it before. Like you said, it would also increase discoverability this way!

Yep, good point. Worth noting Gutenberg and core will do this starting from 5.2 for the alt text description 🙂linking to the W3C alt text tutorial

Screenshot 2019-04-11 at 15 49 23

We'd just need to identify a good resource (better if translated or translatable). I guess a link could also be added in a separate PR.

ZebulanStanphill added a commit that referenced this pull request May 26, 2020
Derived from #14889.

Rebase and major fixes by @ZebulanStanphill.

Co-authored-by: Jackie6 <Jackie6@users.noreply.github.com>
@ZebulanStanphill
Copy link
Member

It looks like this PR has fallen stale/inactive. I've picked up the work in #22650. Thank you for getting this train moving, @Jackie6! It would have been a lot harder to get this feature working without your initial effort!

ZebulanStanphill added a commit that referenced this pull request Jun 2, 2020
Derived from #14889.

Rebase and major fixes by @ZebulanStanphill.

Co-authored-by: Jackie6 <Jackie6@users.noreply.github.com>
ZebulanStanphill added a commit that referenced this pull request Jun 3, 2020
Derived from #14889.

Rebase and major fixes by @ZebulanStanphill.

Co-authored-by: Jackie6 <Jackie6@users.noreply.github.com>
ZebulanStanphill added a commit that referenced this pull request Jun 8, 2020
Derived from #14889.

Rebase and major fixes by @ZebulanStanphill.

Co-authored-by: Jackie6 <Jackie6@users.noreply.github.com>
ZebulanStanphill added a commit that referenced this pull request Jun 10, 2020
Derived from #14889.

Rebase and major fixes by @ZebulanStanphill.

Co-authored-by: Jackie6 <Jackie6@users.noreply.github.com>
ZebulanStanphill added a commit that referenced this pull request Jun 10, 2020
Derived from #14889.

Rebase and major fixes by @ZebulanStanphill.

Co-authored-by: Jackie6 <Jackie6@users.noreply.github.com>
ZebulanStanphill added a commit that referenced this pull request Jun 14, 2020
Derived from #14889.

Rebase and major fixes by @ZebulanStanphill.

Co-authored-by: Jackie6 <Jackie6@users.noreply.github.com>
ZebulanStanphill added a commit that referenced this pull request Jun 17, 2020
Derived from #14889.

Rebase and major fixes by @ZebulanStanphill.

Co-authored-by: Jackie6 <Jackie6@users.noreply.github.com>
ZebulanStanphill added a commit that referenced this pull request Jun 17, 2020
Derived from #14889.

Rebase and major fixes by @ZebulanStanphill.

Co-authored-by: Jackie6 <Jackie6@users.noreply.github.com>
ZebulanStanphill added a commit that referenced this pull request Jun 29, 2020
Derived from #14889.

Rebase and major fixes by @ZebulanStanphill.

Co-authored-by: Jackie6 <Jackie6@users.noreply.github.com>
ZebulanStanphill added a commit that referenced this pull request Jun 30, 2020
Derived from #14889.

Rebase and major fixes by @ZebulanStanphill.

Co-authored-by: Jackie6 <Jackie6@users.noreply.github.com>
ZebulanStanphill added a commit that referenced this pull request Jul 2, 2020
Derived from #14889.

Rebase and major fixes by @ZebulanStanphill.

Co-authored-by: Jackie6 <Jackie6@users.noreply.github.com>
ZebulanStanphill added a commit that referenced this pull request Jul 3, 2020
Derived from #14889.

Rebase and major fixes by @ZebulanStanphill.

Co-authored-by: Jackie6 <Jackie6@users.noreply.github.com>
ZebulanStanphill added a commit that referenced this pull request Jul 3, 2020
Derived from #14889.

Rebase and major fixes by @ZebulanStanphill.

Co-authored-by: Jackie6 <Jackie6@users.noreply.github.com>
ZebulanStanphill added a commit that referenced this pull request Jul 17, 2020
Derived from #14889.

Rebase and major fixes by @ZebulanStanphill.

Co-authored-by: Jackie6 <Jackie6@users.noreply.github.com>
ZebulanStanphill added a commit that referenced this pull request Aug 3, 2020
Derived from #14889.

Rebase and major fixes by @ZebulanStanphill.

Co-authored-by: Jackie6 <Jackie6@users.noreply.github.com>
ZebulanStanphill added a commit that referenced this pull request Aug 16, 2020
Derived from #14889.

Rebase and major fixes by @ZebulanStanphill.

Co-authored-by: Jackie6 <Jackie6@users.noreply.github.com>
ZebulanStanphill added a commit that referenced this pull request Aug 17, 2020
Derived from #14889.

Rebase and major fixes by @ZebulanStanphill.

Co-authored-by: Jackie6 <Jackie6@users.noreply.github.com>
ZebulanStanphill added a commit that referenced this pull request Feb 21, 2021
Derived from #14889.

Rebase and major fixes by @ZebulanStanphill.

Co-authored-by: Jackie6 <Jackie6@users.noreply.github.com>
ZebulanStanphill added a commit that referenced this pull request Mar 7, 2021
Derived from #14889.

Rebase and major fixes by @ZebulanStanphill.

Co-authored-by: Jackie6 <Jackie6@users.noreply.github.com>
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). Needs Design Feedback Needs general design feedback. [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a headings hierarchy checker notice in the heading block sidebar