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 {NavList} from '@primer/react'import {useRouter} from 'next/router'import Link from 'next/link'import React from 'react'function NavItem({href, children}) {const router = useRouter()const isCurrent = typeof href === 'string' ? router.asPath === href : router.pathname === href.pathnamereturn (<NavList.Item as={Link} href={href} aria-current={isCurrent ? 'page' : false}>{children}</NavList.Item>)}export default function IndexPage() {return (<NavList><NavItem href="/">Dashboard</NavItem><NavItem href="/pulls">Pull requests</NavItem><NavItem href="/issues">Issues</NavItem><NavItemhref={{pathname: '/[owner]/[repo]',query: {owner: 'test', repo: 'test'},}}>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. |
Name | Type | Default | Description |
---|---|---|---|
as | React.ElementType | button | HTML element to render as. |
label Required | string | Acccessible name for the control. | |
icon Required | string | Octicon to pass into IconButton. When this is not set, TrailingAction renders as a | |
href | string | href when the TrailingAction is rendered as a link. |
Name | Type | Default | Description |
---|---|---|---|
label Required | string | Acccessible name for the control. | |
ref | React.RefObject<HTMLButtonElement> | A ref to the element rendered by this component. |