Problem/Motivation

The ToC links are generated to h2, h3 headings in node body field only.
In case there is a h4 heading in the url the page is scrolling to the h3 heading above it, rather than to that specific h4.

Steps to reproduce

1. Heading structure in node body field:

<div class="chunker-section">
  <h2 id="h2-hash">
  <p>...</p>
  <h3 id="h3-hash">
  <p>...</p>
  <div class="embedded-entity">
    <div id="h4-hash">
      <h4>...</h4>

2. Check a different hash in the url

* https://example-site.com/test-page#h2-hash OK scrolls to the right h2
* https://example-site.com/test-page#h3-hash OK scrolls to the right h3
* https://example-site.com/test-page#h4-hash scrolls to the top of a section (h2 header) or to the h3 that is above the requested h4.
TODO: It should scroll to the right position and show the correct h4 header.

Proposed resolution

* Make setActive(toc_selector, hash) working not only for h2 and h3 but also for h4
* h4 will require a different hash in node body field (for scrolling) and ToC block in the sidebar to set the closest h3 as an active link.

Remaining tasks

Needs a review

User interface changes

No

API changes

No

Data model changes

No

Issue fork sector_toc-3281000

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

tatianag created an issue. See original summary.

rosk0’s picture

Category: Feature request » Bug report
Status: Active » Needs work

It looks more like a bug report than feature request. Needs works as per review.

tatianag’s picture

Title: Scroll to h4 header if there is no a ToC entry (link) » Scroll to element with ID if there is no a ToC entry
Status: Needs work » Needs review

  • RoSk0 committed c0e8faf on 1.x authored by tatianag
    Issue #3281000 by tatianag: Scroll to element with ID if there is no ToC...
rosk0’s picture

Status: Needs review » Fixed

Merged , thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.