Skip to main content

Sidenav

The Sidenav component is a collapsible vertical navigation menu for app layouts, ideal for organizing primary sections and saving space. Use the collapsed variant to minimize the sidebar, showing only icons, and expand it for full text labels. Ensure the component is placed within a flexible container that adjusts to its width changes.

Import

// with @dhl-official/react-library:
import { DhlSidenav } from "@dhl-official/react-library"
// with @dhl-official/ui-libraries/react-library:
import { DhlSidenav } from "@dhl-official/ui-libraries/react-library"

Code

<DhlSidenav
appName="Express"
activeIndex="main.0"
onDhlActiveIndexChange={(e) => setActiveIndex(e.detail)}
logo={{
title: "Express",
alt: "Express",
href: "https://www.dhl.com/",
external: "_blank",
}}
mainItems={[
{
label: "Nav Item",
icon: icons.PlaneTakeOff,
isPrimary: true,
items: [
{ label: "Sub Item" },
{ label: "Sub Item" },
{ label: "Sub Item" },
],
},
{
label: "Nav Item",
icon: icons.Parcel,
items: [
{ label: "Sub Item" },
{ label: "Sub Item" },
{ label: "Sub Item" },
],
},
{
label: "Nav Item",
icon: icons.LiveTracking,
items: [
{ label: "Sub Item" },
{ label: "Sub Item" },
{ label: "Sub Item" },
],
},
{
label: "Nav Item",
icon: icons.DeliveryVan,
items: [
{ label: "Sub Item" },
{ label: "Sub Item" },
{ label: "Sub Item" },
],
},
{
label: "Nav Item",
icon: icons.CurrencyChange,
items: [
{ label: "Sub Item" },
{ label: "Sub Item" },
{ label: "Sub Item" },
],
},
{
label: "Nav Item",
icon: icons.EmergingMarketSolutions,
},
{
label: "Nav Item",
icon: icons.Group,
},
]}
bottomItems={[
{
label: "Nav Item",
icon: icons.LocationPin,
},
{
label: "Nav Item",
icon: icons.Questionmark,
},
]}
></DhlSidenav>

Type Definitions

DhlSideNavOptionType

type DhlSideNavOptionType = {
label: string;
icon?: string; // SVG string from @dhl-official/icons
isPrimary?: boolean; // Pins item above the scrollable list with a divider
clickEvent?: () => void; // Called on item click in addition to internal navigation
items?: DhlSideNavSubItemType[];
};

type DhlSideNavSubItemType = {
label: string;
clickEvent?: () => void;
};
type ItemLink = {
href?: string;
title?: string;
external?: boolean;
clickEvent?: (e: Event) => void;
};

// logo prop type:
type LogoProp = ItemLink & { alt: string };

activeIndex format

The activeIndex prop uses dot-notation to identify navigation items:

ValueMeaning
"main.0"First item in the main list
"main.1"Second item in the main list
"main.0.0"First sub-item of the first main item
"main.0.1"Second sub-item of the first main item
"bottom.0"First bottom item
"bottom.1"Second bottom item

Note: the item marked isPrimary: true is rendered outside the scrollable list and has no activeIndex value.

Interactive Demo

Readme

Properties

PropertyAttributeDescriptionTypeDefault
activeIndexactive-indexAn optional prop to control the currently active navigation item from the parent. Uses dot-notation: "main.0", "main.1.0" (sub-item), "bottom.0". Mutable — updated internally on click so the reflected attribute always mirrors the current state.string""
allowMultipleDrawersToggleallow-multiple-drawers-toggleAn optional flag to define if component can toggle multiple drawers at the same time.booleanfalse
appNameapp-nameIf present shows the application name next to the DHL logo.stringundefined
bottomItemsbottom-itemsAn optional prop to pass the list of bottom navigation items.DhlSideNavOptionType[][]
dataAriaLabeldata-aria-labelAn optional prop defining the text read by the screen reader to represent the component; use this if you need different text to be read from label.stringundefined
dataTestiddata-testidAn optional prop. The test id attached to the component as a data-testid attribute.stringundefined
isCollapsedis-collapsedAn optional prop to define if component is in collapsed state.booleanfalse
logologoThis is optional prop of the below shape that controls the behavior of the DHL Logo i.e. the title, alternate text, href etc.ItemLink & { alt: string; }undefined
mainItemsmain-itemsAn optional prop to pass the list of main navigation items.DhlSideNavOptionType[][]

Events

EventDescriptionType
dhlActiveIndexChangeEmitted whenever the active navigation item changes (via click or external prop update). event.detail contains the new activeIndex string.CustomEvent<string>

Dependencies

Depends on

Graph


Built by DHL User Interface Library Team!