Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cagov/ds-page-navigation

Package Overview
Dependencies
Maintainers
6
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cagov/ds-page-navigation

Page navigation lists and links to the level 2 headings (H2) of a webpage. It is placed at the top of the page on the left. People can select a link to go directly to that section. The links are introduced by the text **On this page** by default. The page

  • 2.2.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
6
Created
Source

Page navigation

Page navigation lists and links to the level 2 headings (H2) of a webpage. It is placed at the top of the page on the left. People can select a link to go directly to that section. The links are introduced by the text On this page by default. The page navigation does not show if there are zero or one H2’s on the page.

Page navigation makes it easy to see what’s on a page. It allows people to scan a page and know if they’re in the right place.

When and how to use it

Use this component on pages with two or more H2’s. You’ll probably use page navigation on most of your pages.

How not to use it

Do not use this component to replace or duplicate site navigation.

Demo and sample markup

<aside>
  <cagov-page-navigation data-selector=".main" data-type="wordpress" data-label="On this page"></cagov-page-navigation>
</aside>

<div class="main">
  <h2>First heading</h2>
  <h2>Second heading</h2>
  <h2>Third heading</h2>
</div>

Specs

PropertyValue
Machine nameds-page-navigation
JavaScriptyes
SCSS./src/index.scss

Project installation

The instructions assume familiarity with npm package management tool, modern JavaScript techniques, and Sass.

  1. npm i @cagov/ds-page-navigation
  2. Use import¹ or require to include the component’s JavaScript in your page or compiler.
  3. Add the sample markup to your HTML.
  4. Refer to the Content model section for notes on mapping your data to the sample markup.

CDN installation

We recommend using a build system and bundling your JavaScript for faster performance. If you do not use a build system, you can include the code from our CDN with a script tag.

<script type="module" src="https://cdn.designsystem.webstandards.ca.gov/components/ds-page-navigation/v2.2.2/dist/index.js"></script>

CSS variables

The following CSS variables are used in this component:

  • --gray-300

All CSS variables define their own fallback value so you do not have to use additional CSS unless you want to change them. You may define your own value for the variable by adding your own style rules. Here is an example defining the global hex value for a CSS variable named “--primary-700”:

:root {
  --primary-700: #165ac2;
}

Accessibility

Component-specific accessibility review

  • Make sure that this component uses a navigation landmark (enclosed into nav tag) and has ARIA label (has aria-labelledby attribute).
  • Make sure that this components’s visual heading (which is usually “On this page”) has id attribute that is referenced in nav’s aria-labelledby attribute.
  • Ensure that navigation items are keyboard operable and focus is never hidden from users.
  • Make sure that each navigation item has solid, 2px outline that uses --accent2-500 variable on focused state.

Standard accessibility review

As a component in Alpha status, this component must pass the following accessibility reviews every time a new version is published:

  • Tested with the axe accessibility tool and passes all automated WCAG Level AA checks
  • Reviewed with the VoiceOver screen reader on desktop
  • Verified keyboard navigation and that all actionable elements of the component are reachable via keyboard commands only
  • Reviewed component layout on a variety of screen sizes

Progressive enhancement

This component uses a custom element defined in JavaScript in addition to HTML and CSS. Edge, Firefox, Safari, and Chrome support custom elements. If the JavaScript for this component is not delivered or supported, the component will not display. This is the desired behavior because this component is not critical for site interaction. It uses CSS variables to inherit design token values. Token definitions are not required because these style rules provide fallback values.

Content model

This component uses the following data attributes. We provide this information to help with integrating the component into backend publishing systems or identifying content that may require translation.

NameAttribute nameDescriptionData typeField typeDefault
Labeldata-labelLabel for the page indexstringPlain text“On this page”
Selectordata-selectorHTML selector to parse to locate H2 elementsstringPlain text.main
Editor typedata-typeEditorstringPlain textwordpress (currenly only supports WordPress)
  • Index is auto-generated by JavaScript using H2 elements found within the data-selector.

Contributor/developer documentation

FAQs

Package last updated on 04 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc