Skip to content

Side navigation API

import {
SideNav,
SideNavList,
SideNavListItem,
SideNavListSection,
UNSTABLE_SideNavListGroup,
} from '@cimpress-ui/react';

Use the isActive prop on SideNavListItem to indicate the current page.

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>;

Side nav renders a navigation landmark.

Displays persistent side navigation for applications with multiple sections or pages.

See side nav usage guidelines.

SideNavProps
ReactNode

The contents of the side navigation. Typically a <SideNavList>.

boolean | ({ defaultCollapsed?: true; isCollapsed?: boolean; onCollapseChange?: (isCollapsed: boolean) => void })

Determines if the side navigation can be collapsed down to an icon-only rail, allowing for more screen space when needed.

Setting to true will enable collapsibility. Passing an object allows for more advanced configuration, including fully controlled usage outside app shell context.

Renders a list of navigation items within SideNav.

SideNavListProps
ReactNode

Navigation items and sections belonging to the list.

Renders a single navigation item within SideNavList.

SideNavListItemProps
StringLikeChildren

The text to display as the navigation item label.

string

A URL to link to.

boolean

Whether the navigation item represents the current page.

ReactNode

An icon displayed before the navigation item label. Required when the side nav is collapsible.

Renders an expandable group of navigation items within SideNavList.

When the side nav is collapsed to an icon-only rail, top-level groups open their items in a menu instead.

UNSTABLE_SideNavListGroupProps
ReactNode

Navigation items and nested groups belonging to the group.

StringLikeChildren

The text to display as the group label.

ReactNode

An icon displayed before the group label. Required for top-level groups when the side nav is collapsible.

boolean

Whether the group is expanded (controlled).

boolean

Whether the group is expanded by default (uncontrolled).

(isExpanded: boolean) => void

Handler that is called when the group's expanded state changes.

boolean

Whether the group is disabled.

Renders a section of navigation items within SideNavList.

SideNavListSectionProps
ReactNode

Navigation items belonging to the section.

string

The content to display as the section title.