npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@spectrum-web-components/top-nav

v1.12.1

Published

`<sp-top-nav>` delivers site navigation, particularly for when that navigation will change the majority of the page's content and/or the page's URL when selected. All primary elements of an `<sp-top-nav>` should be directly accessible in the tab order, ty

Downloads

32,642

Readme

Overview

<sp-top-nav> delivers site navigation, particularly for when that navigation will change the majority of the page's content and/or the page's URL when selected. All primary elements of an <sp-top-nav> should be directly accessible in the tab order, typically as <sp-top-nav-item> elements. There should only ever be one <sp-top-nav> on a page.

Refer to the Spectrum Design System documentation for visual design guidelines and the application frame patterns for usage in application contexts.

Usage

See it on NPM! How big is this package in your project? Try it on Stackblitz

yarn add @spectrum-web-components/top-nav

Import the side effectful registration of <sp-top-nav> and <sp-top-nav-item> as follows:

import '@spectrum-web-components/top-nav/sp-top-nav.js';
import '@spectrum-web-components/top-nav/sp-top-nav-item.js';

When looking to leverage the TopNav or TopNavItem base classes as a type and/or for extension purposes, do so via:

import { TopNav, TopNavItem } from '@spectrum-web-components/top-nav';

Anatomy

The <sp-top-nav> component consists of the following parts:

  • Container (<sp-top-nav>): The main navigation container component with role="navigation" that manages nav items and selection states
  • Navigation items (<sp-top-nav-item>): Default slot; individual clickable navigation links
  • Label: Optional property to set an aria-label for the top navigation
  • Selection indicator: A visual indicator that animates to the selected item
  • Divider: Optional <div> divider that acts as the track for the selection indicator

Options

<sp-top-nav>
  <sp-top-nav-item href="#">Site Name</sp-top-nav-item>
  <sp-top-nav-item href="#page-1" style="margin-inline-start: auto;">
    Page 1
  </sp-top-nav-item>
  <sp-top-nav-item href="#page-2">Page 2</sp-top-nav-item>
  <sp-top-nav-item href="#page-3">Page 3</sp-top-nav-item>
  <sp-top-nav-item href="#page-4">Page with really long name</sp-top-nav-item>
</sp-top-nav>

Other web components, like action menus and/or buttons, can be included in the <sp-top-nav> slots in order to extend functionality.

<sp-top-nav>
  <sp-top-nav-item href="#">Site Name</sp-top-nav-item>
  <sp-top-nav-item href="#page-1" style="margin-inline-start: auto;">
    Page 1
  </sp-top-nav-item>
  <sp-top-nav-item href="#page-2">Page 2</sp-top-nav-item>
  <sp-top-nav-item href="#page-3">Page 3</sp-top-nav-item>
  <sp-action-menu
    label="Account"
    placement="bottom-end"
    style="margin-inline-start: auto;"
    quiet
  >
    <sp-menu-item>Account settings</sp-menu-item>
    <sp-menu-item>My profile</sp-menu-item>
    <sp-menu-divider></sp-menu-divider>
    <sp-menu-item>Help</sp-menu-item>
    <sp-menu-item>Sign out</sp-menu-item>
  </sp-action-menu>
</sp-top-nav>

Setting the selected property to a URL that matches a top navigation item's resolved href value will render that item selected by default. The selected value must match the fully resolved URL, not just the href attribute value.

For demonstration purposes only, the href value of the selected top nav item is hardcoded, as opposed to being a dynamic href or a jump link.

<sp-top-nav
  selected="https://opensource.adobe.com/spectrum-web-components/components/top-nav/"
>
  <sp-top-nav-item href="#">Site Name</sp-top-nav-item>
  <sp-top-nav-item href="#home" style="margin-inline-start: auto;">
    Home
  </sp-top-nav-item>
  <sp-top-nav-item href="#services">Services</sp-top-nav-item>
  <sp-top-nav-item
    href="https://opensource.adobe.com/spectrum-web-components/components/top-nav/"
    selected
  >
    About
  </sp-top-nav-item>
</sp-top-nav>

If implementations wish to ignore certain URL parts when matching for selection, the ignore-url-parts can be defined with a space-separated list. Currently supported values are hash and search, which will remove the #hash and ?search=value respectively.

<sp-top-nav ignore-url-parts="search hash">
  <sp-top-nav-item href="/page1">Page 1</sp-top-nav-item>
  <sp-top-nav-item href="/page2">Page 2</sp-top-nav-item>
</sp-top-nav>

The quiet property renders the top navigation component without the bottom border.

<sp-top-nav quiet>
  <sp-top-nav-item href="#">Home</sp-top-nav-item>
  <sp-top-nav-item href="/products">Products</sp-top-nav-item>
</sp-top-nav>

Sizes

<sp-top-nav size="s">
  <sp-top-nav-item href="#">Site Name</sp-top-nav-item>
  <sp-top-nav-item href="#page-1" style="margin-inline-start: auto;">
    Page 1
  </sp-top-nav-item>
  <sp-top-nav-item href="#page-2">Page 2</sp-top-nav-item>
  <sp-top-nav-item href="#page-3">Page 3</sp-top-nav-item>
  <sp-top-nav-item href="#page-4">Page with really long name</sp-top-nav-item>
</sp-top-nav>
<sp-top-nav size="m">
  <sp-top-nav-item href="#">Site Name</sp-top-nav-item>
  <sp-top-nav-item href="#page-1" style="margin-inline-start: auto;">
    Page 1
  </sp-top-nav-item>
  <sp-top-nav-item href="#page-2">Page 2</sp-top-nav-item>
  <sp-top-nav-item href="#page-3">Page 3</sp-top-nav-item>
  <sp-top-nav-item href="#page-4">Page with really long name</sp-top-nav-item>
</sp-top-nav>
<sp-top-nav size="l">
  <sp-top-nav-item href="#">Site Name</sp-top-nav-item>
  <sp-top-nav-item href="#page-1" style="margin-inline-start: auto;">
    Page 1
  </sp-top-nav-item>
  <sp-top-nav-item href="#page-2">Page 2</sp-top-nav-item>
  <sp-top-nav-item href="#page-3">Page 3</sp-top-nav-item>
  <sp-top-nav-item href="#page-4">Page with really long name</sp-top-nav-item>
</sp-top-nav>
<sp-top-nav size="xl">
  <sp-top-nav-item href="#">Site Name</sp-top-nav-item>
  <sp-top-nav-item href="#page-1" style="margin-inline-start: auto;">
    Page 1
  </sp-top-nav-item>
  <sp-top-nav-item href="#page-2">Page 2</sp-top-nav-item>
  <sp-top-nav-item href="#page-3">Page 3</sp-top-nav-item>
  <sp-top-nav-item href="#page-4">Page with really long name</sp-top-nav-item>
</sp-top-nav>

Behaviors

  • Items are automatically selected based on the current window.location.href
  • Use ignore-url-parts to ignore hash fragments or search parameters when matching
  • Items can be programmatically selected via the selected property
  • The selection indicator automatically resizes based on item content changes
  • Items can be positioned with CSS using CSS via the style attribute set on <sp-top-nav-item> elements (e.g., margin-inline-start: auto)

Accessibility

ARIA attributes

  • role="navigation" is automatically applied to the top nav container
  • The label property set on <sp-top-nav> will set an aria-label for screen readers
  • Selected items receive aria-current="page"

Keyboard interaction

  • Tab should move focus between all navigation items in a logical tab order
  • Enter selects navigation items

Best practices

  • Always provide a label for the navigation container.
  • Use semantic href values that match actual page URLs for automatic selection.
  • Provide meaningful text content for navigation items - avoid icon-only items without labels.