import {NavList} from '@primer/react'
<NavList><NavList.Item href="/" aria-current="page">Home</NavList.Item><NavList.Item href="/about">About</NavList.Item><NavList.Item href="/contact">Contact</NavList.Item></NavList>
<NavList><NavList.Item href="/" aria-current="page"><NavList.LeadingVisual><HomeIcon /></NavList.LeadingVisual>Dashboard</NavList.Item><NavList.Item href="/pulls"><NavList.LeadingVisual><GitPullRequestIcon /></NavList.LeadingVisual>Pull requests</NavList.Item><NavList.Item href="/issues"><NavList.LeadingVisual><IssueOpenedIcon /></NavList.LeadingVisual>Issues</NavList.Item></NavList>
<NavList><NavList.Item href="/general" aria-current="page"><NavList.LeadingVisual><span aria-hidden>#️⃣</span></NavList.LeadingVisual>General</NavList.Item><NavList.Item href="/q-a"><NavList.LeadingVisual><span aria-hidden>🙏</span></NavList.LeadingVisual>Q&A</NavList.Item><NavList.Item href="/show-and-tell"><NavList.LeadingVisual><span aria-hidden>🙌</span></NavList.LeadingVisual>Show and tell</NavList.Item></NavList>
<NavList><NavList.Item href="/inbox" aria-current="page">Inbox<NavList.TrailingVisual>1,234</NavList.TrailingVisual></NavList.Item><NavList.Item href="/saved">Saved</NavList.Item><NavList.Item href="/done">Done</NavList.Item></NavList>
<><Heading as="h3" id="workflows-heading" sx={{fontSize: 2}}>Workflows</Heading><NavList aria-labelledby="workflows-heading"><NavList.Item href="/" aria-current="page">All workflows</NavList.Item><NavList.Item href="/ci">CI</NavList.Item><NavList.Item href="/deploy">Deploy</NavList.Item><NavList.Item href="/release">Release</NavList.Item></NavList></>
<NavList aria-label="Security"><NavList.Item href="/" aria-current="page">Overview</NavList.Item><NavList.Item href="/policy">Security policy</NavList.Item><NavList.Item href="/advisories">Security advisories</NavList.Item></NavList>
<NavList><NavList.Group title="Overview"><NavList.Item href="/getting-started" aria-current="page">Getting started</NavList.Item></NavList.Group><NavList.Group title="Components"><NavList.Item href="/Avatar">Avatar</NavList.Item><NavList.Item href="/Button">Button</NavList.Item><NavList.Item href="/Label">Label</NavList.Item></NavList.Group></NavList>
<NavList><NavList.Item href="/branches">Branches</NavList.Item><NavList.Item href="/tags">Tags</NavList.Item><NavList.Item>Actions<NavList.SubNav><NavList.Item href="/actions" aria-current="page">General</NavList.Item><NavList.Item href="/actions/runners">Runners</NavList.Item></NavList.SubNav></NavList.Item></NavList>
If a NavList.Item
contains a NavList.SubNav
, the NavList.Item
will render as a <button>
and the as
prop and href
prop will be ignored.
<NavList><NavList.Item href="/" aria-current="page">Dashboard</NavList.Item><NavList.Item href="/pulls">Pull requests</NavList.Item><NavList.Item href="/issues">Issues</NavList.Item><NavList.Divider /><NavList.Item href="/marketplace">Marketplace</NavList.Item><NavList.Item href="/explore">Explore</NavList.Item></NavList>
import {Link, useMatch, useResolvedPath} from 'react-router-dom'import {NavList} from '@primer/react'function NavItem({to, children}) {const resolved = useResolvedPath(to)const isCurrent = useMatch({path: resolved.pathname, end: true})return (<NavList.Item as={Link} to={to} aria-current={isCurrent ? 'page' : undefined}>{children}</NavList.Item>)}function App() {return (<NavList><NavItem to="/">Dashboard</NavItem><NavItem to="/pulls">Pull requests</NavItem><NavItem to="/issues">Issues</NavItem></NavList>)}
import {useRouter} from 'next/router'import Link from 'next/link'import {NavList} from '@primer/react'function NavItem({href, children}) {const router = useRouter()const isCurrent =typeof href === 'string'? router.asPath === href: router.pathname === href.pathname;return (<Link href={href} passHref><NavList.Item aria-current={isCurrent ? 'page' : false}>{children}</NavList.Item></Link>)}function App() {return (<NavList><NavItem href="/">Dashboard</NavItem><NavItem href="/pulls">Pull requests</NavItem><NavItem href="/issues">Issues</NavItem><NavItemhref={{pathname: '/[owner]/[repo]',query: { owner, repo },}}>Summary</NavItem></NavList>)}
Name | Type | Default | Description |
---|---|---|---|
aria-label | string | ||
aria-labelledby | string | ||
sx | SystemStyleObject | Style overrides to apply to the component. See also overriding styles. | |
ref | React.RefObject<HTMLElement> | A ref to the element rendered by this component. | |
Additional props are passed to the <nav> element. See MDN for a list of props accepted by the <nav> element. |
Name | Type | Default | Description |
---|---|---|---|
href | string | The URL that the item navigates to. href is passed to the underlying <a> element. If as is specified, the component may need different props. If the item contains a sub-nav, the item is rendered as a <button> and href is ignored. | |
aria-current | | 'page' | 'step' | 'location' | 'date' | 'time' | true | false | false | Set aria-current to "page" to indicate that the item represents the current page. Set aria-current to "location" to indicate that the item represents the current location on a page. For more information about aria-current , see MDN. |
sx | SystemStyleObject | Style overrides to apply to the component. See also overriding styles. | |
as | React.ElementType | "a" | The underlying element to render — either a HTML element name or a React component. |
ref | React.RefObject<HTMLAnchorElement> | A ref to the element rendered by this component. Because this component is polymorphic, the type will vary based on the value of the as prop. | |
Additional props are passed to the <a> element. See MDN for a list of props accepted by the <a> element. If an as prop is specified, the accepted props will change accordingly. |
Name | Type | Default | Description |
---|---|---|---|
sx | SystemStyleObject | Style overrides to apply to the component. See also overriding styles. | |
ref | React.RefObject<HTMLElement> | A ref to the element rendered by this component. |
Name | Type | Default | Description |
---|---|---|---|
sx | SystemStyleObject | Style overrides to apply to the component. See also overriding styles. | |
ref | React.RefObject<HTMLElement> | A ref to the element rendered by this component. |
Name | Type | Default | Description |
---|---|---|---|
sx | SystemStyleObject | Style overrides to apply to the component. See also overriding styles. | |
ref | React.RefObject<HTMLElement> | A ref to the element rendered by this component. |
Name | Type | Default | Description |
---|---|---|---|
title | string | Title of the group. | |
sx | SystemStyleObject | Style overrides to apply to the component. See also overriding styles. | |
ref | React.RefObject<HTMLElement> | A ref to the element rendered by this component. |
Name | Type | Default | Description |
---|---|---|---|
sx | SystemStyleObject | Style overrides to apply to the component. See also overriding styles. | |
ref | React.RefObject<HTMLElement> | A ref to the element rendered by this component. |