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 missing headers in the Table of Contents #1916

Merged
merged 10 commits into from
Aug 3, 2017
Merged

Conversation

sirreal
Copy link
Member

@sirreal sirreal commented Jul 15, 2017

Add missing headers to the Table of Contents.
Separate TableOfContentsItem into independent component.

toc

Closes #1903

@sirreal sirreal added the [Status] In Progress Tracking issues with work in progress label Jul 15, 2017
@sirreal sirreal self-assigned this Jul 15, 2017
@sirreal sirreal added [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Type] Enhancement A suggestion for improvement. labels Jul 15, 2017
@sirreal sirreal changed the title [WIP] Add missing headers in the Table of Contents Add missing headers in the Table of Contents Jul 20, 2017
@sirreal sirreal removed the [Status] In Progress Tracking issues with work in progress label Jul 20, 2017
@mtias
Copy link
Member

mtias commented Jul 24, 2017

@afercia @jasmussen do you think showing missing headings would be better than just highlighting the parent-less level? One concern is that it sort of implies that you should add the missing heading levels instead of changing the incorrect one.

<div
className={ classnames(
'table-of-contents__item',
`is-H${ level }`,
Copy link
Member

Choose a reason for hiding this comment

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

This is from the original PR, but we should lowercase the class name.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 afe3467

@jasmussen
Copy link
Contributor

do you think showing missing headings would be better than just highlighting the parent-less level? One concern is that it sort of implies that you should add the missing heading levels instead of changing the incorrect one.

I agree, the obvious course of action is to simply change the sub heading to be one less deep. Could we show a little exclamation mark or warning triangle or something, which on hover can suggest, perhaps even with a button, to fix the level?

@mtias
Copy link
Member

mtias commented Jul 24, 2017

Let's start with highlighting with color and adding some text after the headline with "Should be Hx level". @sirreal would you be able to update this one?

@afercia
Copy link
Contributor

afercia commented Jul 24, 2017

Or just change the text from "Missing header level" to "Skipped heading level"?
Note: header is a different thing from heading.

@mtias
Copy link
Member

mtias commented Jul 24, 2017

What I mean is that presentation wise it's the difference between:

h1 Some text
  h2 ...
    h3 ...
      h4 ...
        h6 My other heading

And:

h1 Some text
  h6 My other heading
       (Incorrect heading level)

@sirreal
Copy link
Member Author

sirreal commented Jul 24, 2017

Or just change the text from "Missing header level" to "Skipped heading level"?
Note: header is a different thing from heading.

👍 @afercia Thanks! Replaced "header" with "heading" in 21b98c3

@sirreal
Copy link
Member Author

sirreal commented Jul 24, 2017

@mtias I've reworked the component a bit to provide the incorrect level message. Here's what it looks like now:

latest

@afercia
Copy link
Contributor

afercia commented Aug 2, 2017

The messages look correct and informative to me. The HTML in the meta box is all <div>s, it would be nice to use some slightly more semantic HTML. Even just <p>s and <span>s would be a bit better 🙂

It would be great if the outline report could update live while editing the post headings! Right now, after you make a change you need to save the post and refresh to see the outline updated. Not sure about technical details and maybe this could be merged as a first iteration" @sirreal thanks! and @mtias what's left to be done here?

Re: the build failing, I think it's the PHP 5.2 thing and just needs to be rebased?

@mtias
Copy link
Member

mtias commented Aug 2, 2017

Right now, after you make a change you need to save the post and refresh to see the outline updated.

It should update as soon as you focus-out from the heading you were writing. Does that work for you or you still need to save?

@mtias
Copy link
Member

mtias commented Aug 2, 2017

Also, I think we can remove the "experimental" wording :)

@afercia
Copy link
Contributor

afercia commented Aug 2, 2017

It should update as soon as you focus-out from the heading you were writing.

No, it doesn't for me. It does update when deleting a heading or adding a new one.

@mtias
Copy link
Member

mtias commented Aug 2, 2017

I'll check that out.

@sirreal sirreal force-pushed the add/toc-skipped-headers branch from a0f5938 to 65f9cd1 Compare August 3, 2017 10:55
@codecov
Copy link

codecov bot commented Aug 3, 2017

Codecov Report

Merging #1916 into master will increase coverage by 0.77%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1916      +/-   ##
==========================================
+ Coverage   22.15%   22.93%   +0.77%     
==========================================
  Files         138      139       +1     
  Lines        4283     5136     +853     
  Branches      723      967     +244     
==========================================
+ Hits          949     1178     +229     
- Misses       2814     3250     +436     
- Partials      520      708     +188
Impacted Files Coverage Δ
editor/sidebar/table-of-contents/index.js 0% <0%> (ø) ⬆️
editor/sidebar/table-of-contents/item.js 0% <0%> (ø)
editor/selectors.js 95.81% <0%> (-0.49%) ⬇️
editor/modes/visual-editor/block.js 0% <0%> (ø) ⬆️
editor/header/tools/preview-button.js 0% <0%> (ø) ⬆️
editor/sidebar/last-revision/index.js 0% <0%> (ø) ⬆️
editor/modes/visual-editor/block-list.js 0% <0%> (ø) ⬆️
editor/post-title/index.js 0% <0%> (ø) ⬆️
components/dropdown-menu/index.js 93.16% <0%> (+0.1%) ⬆️
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2beeb4c...b0159e8. Read the comment docs.

@sirreal
Copy link
Member Author

sirreal commented Aug 3, 2017

@mtias @afercia The issue with the Table of Contents not being updated and the test failures appear to be corrected after rebase.

@afercia
Copy link
Contributor

afercia commented Aug 3, 2017

@sirreal thanks! I was just testing it and seems to update now. There's a small CSS issue in Safari and Edge (see screenshot below), and I'd like to try a couple changes to improve a11y (I'm trying them in a local branch):

  • make the TOC list a <ul>: screen readers can announce how many items are in the list
  • wrap the CSS generated dashes within a span with aria-hidden="true" because some screen readers read out CSS generated content, for example before the H2 VoiceOver reads out "em dash". See also https://core.trac.wordpress.org/ticket/40428

From left to right: Safari, Edge, and (for reference) IE 11

screen shot 2017-08-03 at 14 43 28

N.B. the multiple scrollbars is a separate issue

@afercia
Copy link
Contributor

afercia commented Aug 3, 2017

If I'm not wrong headings.length > 1 won't work in the case there's just one heading. Was this intentional? /cc @mtias

@mtias
Copy link
Member

mtias commented Aug 3, 2017

@afercia yes, I thought it didn't make a lot of sense to show it only for one header. My plan was to not show the section at all if you don't have any headers as well.

@afercia
Copy link
Contributor

afercia commented Aug 3, 2017

@mtias OK that also avoids the need to handle singular/plural forms 1 Heading / n Headings.

@@ -1,9 +1,8 @@
/**
* External dependencies
* External Dependencies
Copy link
Member

Choose a reason for hiding this comment

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

"dependencies" should be lowercase

@afercia
Copy link
Contributor

afercia commented Aug 3, 2017

I went ahead:

  • shows the TOC section only when there are at least 2 headings
  • makes the list of headings a list
  • hides the CSS generated "dashes" from assistive technologies
  • fixes flexbox layout for Safari and Edge

Worth noting Safari + VoiceOver don't announce styled lists as lists, this is a Safari bug and the only way to fix it would be to add a redundant role="list" on the <ul> element (and disable a jsx-a11y rule).

Firefox + NVDA announcing the number of items in the list:

screenshot 28

Chrome + VoiceOver announcing the number of items in the list:

screen shot 2017-08-03 at 17 08 56

@mtias
Copy link
Member

mtias commented Aug 3, 2017

@sirreal feel free to merge when you think it's ready.

@sirreal sirreal merged commit 360a5ad into master Aug 3, 2017
@sirreal sirreal deleted the add/toc-skipped-headers branch August 3, 2017 15:49
@mtias
Copy link
Member

mtias commented Aug 3, 2017

Thanks both!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants