Jump links

Jump links for lit-material: an "On this page" list that highlights the section in view.

  • 1.8 KB gzipped
  • @lit-material/jump-links 0.2.1
  • Renders on the server

Example

Install

npm install @lit-material/jump-links @lit-material/tokens
import "@lit-material/jump-links";

Link @lit-material/tokens/css/index.css once per page for the colour, type and shape tokens. Install guide

API

An "On this page" list: links to a page's sections that highlight the one being read. The links are plain #id anchors, so they work before (and without) JavaScript and render on the server; scrolling then marks the section at the top of the viewport with aria-current="location".

Properties

PropertyAttributeTypeDefaultDescription
linkslinksJumpLink[][]The sections. Ignored while for is set. As an attribute it takes JSON, so server-rendered markup carries the links and hydrates to the same list.
htmlForforstring""Id of a container whose h2/h3 headings with ids become the links.
labellabelstring"On this page"Heading above the links; empty hides it. Also names the <nav>.
offsetoffsetnumber0Pixels covered by a sticky header: a section counts as current once its top passes this line.
currentproperty onlystring""Id of the section in view; reflected as aria-current on its link.

CSS parts

PartDescription
navThe <nav>.
linkEach link.
titleThe heading above the links.

Source on GitHub npm