Exclude hidden elements from the table of content

Created on 27 June 2023, about 1 year ago
Updated 29 June 2023, 12 months ago

Problem/Motivation

At the moment the toc.js seems to recognize also headings which are hidden on the page with display none. This can be a bit troublesome because first of all the headings are not visible when trying to scroll the page but it also breaks the scrolling when it tries to scroll to an element which is not in the DOM. This results in the page actually scrolling to the top of the page.

Steps to reproduce

1. Configure the table of content to recognize all headings on a page.
2. Create an element which is using display none to hide the heading.

At the moment the hidden heading is included in the table of content. I would suggest that either we don't include hidden elements in the table of content by default or add an option to exclude them in the settings.

Proposed resolution

It should be possible to check with JS if the element is currently hidden and exclude the title from the table of contents.

Remaining tasks

Create the JS functionality and possibly unit tests.

User interface changes

Optionally make this setting configurable in the content type settings for the table of contents.

API changes

None.

Data model changes

Optionally add the new setting in the configuration schema.

✨ Feature request
Status

Active

Version

2.0

Component

Code

Created by

🇫🇮Finland HeikkiY Oulu

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @HeikkiY
  • 🇫🇮Finland HeikkiY Oulu
  • 🇫🇷France flocondetoile Lyon

    If you have headings hidden, with a specific class, for example .heading-hidden, you can target headings with this css selector for example h2:not(.heading-hidden). Anyway you should be able to target heading with css selector. If you have headings not visible it's certainly because they have a custom/specific CSS class to hide them not ?

Production build 0.69.0 2024