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 Feature to expand/collapse Table of Contents #1205

Open
anthumchris opened this issue Mar 15, 2018 · 7 comments
Open

Add Feature to expand/collapse Table of Contents #1205

anthumchris opened this issue Mar 15, 2018 · 7 comments

Comments

@anthumchris
Copy link

anthumchris commented Mar 15, 2018

Originally discussed with @domenic, @tabatkins in whatwg/streams#885, this feature would add expand/collapse functionality to specific TOC lines. Pages wishing to implement this feature could add class "toc-collapsible" to the header markup. For example, the markup below would produce the expand/collapse functionality in the TOC for those headers:

<h3 class="toc-collapsible">General writable stream abstract operations</h3>
<h3 class="toc-collapsible">Writable stream abstract operations used by controllers</h3>

collapsed:

toc-collapsed

expanded:

toc-expanded


Which design should be used?

I created prototypes for designs and would need to know which one everyone would like to move forward with. This affects the hard-coded markup Bikeshed would add:

  1. Left Arrow Design
  2. Right Text Design

Where should the CSS/Javascript go?

I'm new to this project and would need to know where to put the required CSS/JS that this functionality requires. Should it be inline or in external files? I'll add inline to start and will modify as needed.

Other Requirements?

I can add this to the TOC documentation and create tests in the tests folder. Anything else needed? @tabatkins mentioned using details, summary, and a11y which I didn't understand and went over my head.

And what browsers are supported/unsupported? I'll need to do CSS/JS testing on your support matrix.

Feel free to assign this to me if you'd like.

@tabatkins
Copy link
Collaborator

The <details> and <summary> elements are built-in "expand to see more" elements in HTML. I could use these directly in the TOC, with a markup like:

<ol>
  <li>
    <details>
      <summary><a>1. Introduction</a></summary>
      <ol>
        <li><a>1.1 Module Interactions</a>
      </ol>
    </details>
  </li>
</ol>

(Leaf nodes can be left as just a elements, but if they have sub-sections they'll be put into a details instead.)

@tabatkins
Copy link
Collaborator

@anthumchris
Copy link
Author

anthumchris commented Mar 15, 2018

@tabatkins very cool, I had no idea and never used them before. Just tested on win VMs and...

<details> is not supported in Edge 16 (nor IE 11). Seems a JS work-around may be needed if moving forward with this structure. But GitHub likes it 👻

@domenic
Copy link
Collaborator

domenic commented Mar 15, 2018

I'm quite happy with this being a progressive enhancement that doesn't work in Edge yet.

@tabatkins
Copy link
Collaborator

Yeah, they'll just fail-open, looking identical to how things are formatted today. That's 100% okay with me.

@anthumchris
Copy link
Author

anthumchris commented Mar 16, 2018

Here's the first round prototyping implementation with Streams page. You'll notice differences in <details> UI behavior that aren't consistent across browsers: clicking header <a> navigates in Firefox, while other browsers don't navigate. This may not be ideal and removes navigability to the expandible TOC line.

https://dev.anthum.com/pub/whatwg-streams-toc-details.html

master...AnthumChris:toc-collapsible-details
whatwg/streams@master...AnthumChris:toc-collapsible-headers

@tabatkins
Copy link
Collaborator

Whoa, there's some non-determinism going on here in Chrome - I was able to navigate one of the links once, then when I returned it refused to navigate again and just toggled it open/close.

Anyway, boo on this not working in Chrome. Maybe we can add a tiny bit of JS to capture the click and dispatch properly?

(However, the link is definitely clickable in my demo linked above. There's something weird going on here.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants