Side navigation API
Import
Section titled “Import”import { SideNav, SideNavList, SideNavListItem, SideNavListSection } from '@cimpress-ui/react';Active item
Section titled “Active item”Use the isActive prop on SideNavListItem to indicate the current page.
import { RouterProvider, SideNav, SideNavList, SideNavListItem } from '@cimpress-ui/react';import { IconPlaceholder } from '@cimpress-ui/react/icons';import { useState } from 'react';
export default function Demo() { const [path, setPath] = useState('#1');
return ( <RouterProvider navigate={setPath}> <SideNav> <SideNavList> <SideNavListItem href="#1" isActive={path === '#1'} icon={<IconPlaceholder />}> Menu item 1 </SideNavListItem> <SideNavListItem href="#2" isActive={path === '#2'} icon={<IconPlaceholder />}> Menu item 2 </SideNavListItem> <SideNavListItem href="#3" isActive={path === '#3'} icon={<IconPlaceholder />}> Menu item 3 </SideNavListItem> </SideNavList> </SideNav> </RouterProvider> );}Controlled/uncontrolled collapsible mode (unstable)
Section titled “Controlled/uncontrolled collapsible mode (unstable)”When using the unstable collapsible mode, collapse state is configured through UNSTABLE_isCollapsible. Inside app shell, uncontrolled usage is recommended so app shell can manage the state for you.
Use defaultCollapsed to seed the initial collapse state on large viewports:
<SideNav UNSTABLE_isCollapsible={{ defaultCollapsed: true }}>{/* ... */}</SideNav>defaultCollapsed is only applied on the initial mount. Omit it when you want the side nav to
start expanded.
To persist the user’s collapse preference, pair defaultCollapsed with onCollapseChange — for example, by saving the preference to localStorage:
<SideNav UNSTABLE_isCollapsible={{ defaultCollapsed, onCollapseChange: (isCollapsed) => { localStorage.setItem(STORAGE_KEY, String(isCollapsed)); }, }}> {/* ... */}</SideNav>Use controlled collapse state when you need to manage it yourself, for example outside of app shell. Pass isCollapsed together with onCollapseChange:
const [isCollapsed, setIsCollapsed] = useState(false);
<SideNav UNSTABLE_isCollapsible={{ isCollapsed, onCollapseChange: setIsCollapsed, }}> {/* ... */}</SideNav>;Accessibility notes
Section titled “Accessibility notes”Side nav renders a navigation landmark.
API reference
Section titled “API reference”SideNav
Section titled “SideNav”Displays persistent side navigation for applications with multiple sections or pages.
SideNavProps
- ReactNode
children *
Section titled “ children * ” -
The contents of the side navigation. Typically a
<SideNavList>. - boolean | ({ defaultCollapsed?: true; isCollapsed?: boolean; onCollapseChange?: (isCollapsed: boolean) => void })
UNSTABLE_isCollapsible
Section titled “ UNSTABLE_isCollapsible ” -
Determines if the side navigation can be collapsed down to an icon-only rail, allowing for more screen space when needed.
Setting to
truewill enable collapsibility. Passing an object allows for more advanced configuration, including fully controlled usage outside app shell context.
SideNavList
Section titled “SideNavList”Renders a list of navigation items within SideNav.
SideNavListProps
- ReactNode
children *
Section titled “ children * ” -
Navigation items and sections belonging to the list.
SideNavListItem
Section titled “SideNavListItem”Renders a single navigation item within SideNavList.
SideNavListItemProps
- StringLikeChildren
children *
Section titled “ children * ” -
The text to display as the navigation item label.
- string
href *
Section titled “ href * ” -
A URL to link to.
- boolean
isActive
Section titled “ isActive ” -
Whether the navigation item represents the current page.
- ReactNode
-
An icon displayed before the navigation item label. Required when the side nav is collapsible.
SideNavListSection
Section titled “SideNavListSection”Renders a section of navigation items within SideNavList.
SideNavListSectionProps
- ReactNode
children *
Section titled “ children * ” -
Navigation items belonging to the section.
- string
label
Section titled “ label ” -
The content to display as the section title.