import {NavList} from '@primer/react'
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.
We only allow for up to 4 levels of nested subnavs. If more than 4 levels is required, it's a good sign that the navigation design needs to be rethought.
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.pathnamereturn (<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 | ||
| ref | React.RefObject<HTMLElement> | ||
| as | React.ElementType | "nav" | The underlying element to render — either a HTML element name or a React component. |
| sx | SystemStyleObject |
| Name | Type | Default | Description |
|---|---|---|---|
| href | string | The URL that the item navigates to. | |
| aria-current | | 'page' | 'step' | 'location' | 'date' | 'time' | true | false | false | Set |
| defaultOpen | boolean | The open state of the item when it is initially rendered if the item has a SubNav. | |
| ref | React.RefObject<HTMLAnchorElement> | ||
| as | React.ElementType | "a" | The underlying element to render — either a HTML element name or a React component. |
| sx | SystemStyleObject | ||
Additional props are passed to the <a> element. See a docs for a list of props accepted by the <a> element. | |||
| Name | Type | Default | Description |
|---|---|---|---|
| sx | SystemStyleObject | ||
| ref | React.RefObject<HTMLElement> | A ref to the element rendered by this component. |
| Name | Type | Default | Description |
|---|---|---|---|
| sx | SystemStyleObject | ||
| ref | React.RefObject<HTMLElement> | A ref to the element rendered by this component. |
| Name | Type | Default | Description |
|---|---|---|---|
| sx | SystemStyleObject | ||
| ref | React.RefObject<HTMLElement> | A ref to the element rendered by this component. |
| Name | Type | Default | Description |
|---|---|---|---|
| sx | SystemStyleObject | ||
| ref | React.RefObject<HTMLElement> | A ref to the element rendered by this component. |
| Name | Type | Default | Description |
|---|---|---|---|
| sx | SystemStyleObject | ||
| ref | React.RefObject<HTMLElement> | A ref to the element rendered by this component. |