npm explorer

@spectrum-web-components/top-nav

v0.0.0-20250410163257TypeScript

`<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

design-systemspectrumadobeadobe-spectrumweb componentsweb-componentslit-elementlit-htmlcomponentcss
0/weekUpdated 6 days agoApache-2.0Unpacked: 70.2 KB
Published by Adobe
npm install @spectrum-web-components/top-nav
RepositoryHomepagenpm

Overview

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 should be directly accessible in the tab order, typically as elements. There should only ever be one on a page.

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

$3

![See it on NPM!](https://www.npmjs.com/package/@spectrum-web-components/top-nav)
![How big is this package in your project?](https://bundlephobia.com/result?p=@spectrum-web-components/top-nav)
![Try it on Stackblitz](https://stackblitz.com/edit/vitejs-vite-95xejnti)

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

Import the side effectful registration of and as follows:

`js
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:

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

$3

The component consists of the following parts:

- Container (): The main navigation container component with role="navigation" that manages nav items and selection states
- Navigation items (
): 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

divider that acts as the track for the selection indicator

$3


Default

`html

Site Name

Page 1

Page 2
Page 3
Page with really long name

`


With action menu integration

Other web components, like action menus and/or buttons, can be included in the slots in order to extend functionality.

`html

Site Name

Page 1

Page 2
Page 3
label="Account"
placement="bottom-end"
style="margin-inline-start: auto;"
quiet
>
Account settings
My profile

Help
Sign out


`


With default selection

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.

`html
selected="https://opensource.adobe.com/spectrum-web-components/components/top-nav/"
>
Site Name

Home

Services
href="https://opensource.adobe.com/spectrum-web-components/components/top-nav/"
selected
>
About


`


Ignoring URL parts for selection

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.

`html

Page 1
Page 2

`


Quiet variant

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

`html

Home
Products

`


#### Sizes


Small

`html

Site Name

Page 1

Page 2
Page 3
Page with really long name

`


Medium

`html

Site Name

Page 1

Page 2
Page 3
Page with really long name

`


Large

`html

Site Name

Page 1

Page 2
Page 3
Page with really long name

`


Extra large

`html

Site Name

Page 1

Page 2
Page 3
Page with really long name

`


$3

- 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 elements (e.g., margin-inline-start: auto)

$3

#### ARIA attributes

- role="navigation" is automatically applied to the top nav container
- The
label property set on 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.

@spectrum-web-components/top-nav - npm explorer

Dist Tags

rc1.0.0-rc.10
color-testing1.0.1-color-testing
testing1.3.0-testing.0
calendar0.0.0-20250410163257
beta1.6.1-beta.0
nightly1.9.1-nightly.20251101120150
preview1.11.0-preview-ae61361d.20251203202755
snapshot1.11.1-snapshot.20260129124754
snapshot-test1.11.0-snapshot-test.20260129145631
latest1.11.2