
Product
Introducing Socket Scanning for OpenVSX Extensions
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.
@spectrum-web-components/top-nav
Advanced tools
`<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
<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.
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';
The <sp-top-nav> component consists of the following parts:
<sp-top-nav>): The main navigation container component with role="navigation" that manages nav items and selection states<sp-top-nav-item>): Default slot; individual clickable navigation linksaria-label for the top navigation<div> divider that acts as the track for the selection indicator<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>
With action menu integration
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>
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.
<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>
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.
<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>
Quiet variant
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>
<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>
Medium
<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>
Large
<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>
Extra large
<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>
window.location.hrefignore-url-parts to ignore hash fragments or search parameters when matchingselected propertystyle attribute set on <sp-top-nav-item> elements (e.g., margin-inline-start: auto)role="navigation" is automatically applied to the top nav containerlabel property set on <sp-top-nav> will set an aria-label for screen readersaria-current="page"Tab should move focus between all navigation items in a logical tab orderEnter selects navigation itemshref values that match actual page URLs for automatic selection.FAQs
Did you know?

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.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.

Product
Bringing supply chain security to the next generation of JavaScript package managers

Product
A safer, faster way to eliminate vulnerabilities without updating dependencies