Skip to main content

Sidebar

import { Sidebar } from '@enmovil/ui-design-system';

A collapsible side navigation menu built from menus. It uses a dark theme by default; pass theme="light" for a white background with teal accents.

Properties​

PropertyTypeRequiredDefaultAllowed valuesDescription
classNamestringNo——Extra CSS class added to the sidebar container.
menusMenuItem[]No[]—Items of the menu, nested through children. Without it the menu is empty.
openbooleanYes——Whether the sidebar is expanded. When false it shrinks to a 56px icon rail and closes all sub-menus; while open, a click outside the sidebar or on an item without children calls onOpenChange(false).
selectedKeysstring[]No——Keys of the highlighted items. While the sidebar is open, the sub-menus containing the first key are expanded, and an indicator bar marks the active top-level entry.
defaultSelectedKeysstring[]No——Keys highlighted on first render when selectedKeys is not set. Expanding parent sub-menus and the indicator bar only follow selectedKeys.
widthOnOpenstring | numberNo——Width of the open sidebar, in pixels when a number or any CSS length. Defaults to 232px.
headerHeightstring | numberNo——Height of the page header above the sidebar, in pixels when a number or any CSS length; the sidebar is as tall as the viewport minus this. Defaults to 52px.
themestringNo'dark''light', 'dark'Visual theme. Default is "dark" (dark teal background, light text) which is the new look introduced in v0.0.81. Pass "light" to keep the original white background with teal accents.

An array of objects (MenuItem). Each object has these fields:

FieldTypeRequiredDescription
keystringYesUnique identifier of the item across the whole menu, matched by selectedKeys and used to track open sub-menus.
iconReact.ReactNodeNoIcon shown before the label. While the sidebar is closed, it is all that shows of the item.
labelReact.ReactNodeYesText or content of the item.
type"group" | "divider"Nogroup shows the item as a titled section listing its children; divider shows a separator line. While the sidebar is closed, groups are dropped and their children shown at the top level.
isHiddenbooleanNoLeaves the item and all its children out of the menu.
onClick() => voidNoCalled when the item is clicked. Only fires for items without children.
childrenMenuItem[]NoChild items, shown in a sub-menu that expands in place. Opening a sub-menu closes the other open one at the same level.
countnumberNoNumber shown in a badge after the label. No badge when it is absent or 0.
hrefstringNoWraps the label in a link to this URL, so clicking the item navigates the page.

An array of objects (MenuItem). Each object has these fields:

FieldTypeRequiredDescription
keystringYesUnique identifier of the item across the whole menu, matched by selectedKeys and used to track open sub-menus.
iconReact.ReactNodeNoIcon shown before the label.
labelReact.ReactNodeYesText or content of the item.
type"group" | "divider"Nogroup shows the item as a titled section listing its children; divider shows a separator line.
isHiddenbooleanNoLeaves the item and all its children out of the menu.
onClick() => voidNoCalled when the item is clicked. Only fires for items without children.
childrenMenuItem[]NoChild items, shown in a nested sub-menu. Opening a sub-menu closes the other open one at the same level.
countnumberNoNumber shown in a badge after the label. No badge when it is absent or 0.
hrefstringNoWraps the label in a link to this URL, so clicking the item navigates the page.

An array of objects (MenuItem). Each object has these fields:

FieldTypeRequiredDescription
keystringYesUnique identifier of the item across the whole menu, matched by selectedKeys and used to track open sub-menus.
iconReact.ReactNodeNoIcon shown before the label.
labelReact.ReactNodeYesText or content of the item.
type"group" | "divider"Nogroup shows the item as a titled section listing its children; divider shows a separator line.
isHiddenbooleanNoLeaves the item and all its children out of the menu.
onClick() => voidNoCalled when the item is clicked. Only fires for items without children.
childrenMenuItem[]NoChild items, shown in a further nested sub-menu. Items can nest to any depth.
countnumberNoNumber shown in a badge after the label. No badge when it is absent or 0.
hrefstringNoWraps the label in a link to this URL, so clicking the item navigates the page.
Other attributes

Sidebar passes 294 further attributes through to the underlying element. They aren't part of the supported API and may change between releases, so use only the properties listed on this page.

Events​

NameSignatureWhen it fires
onOpenChange(open: boolean) => voidCalled with false when a leaf item is clicked, asking the parent to close the sidebar. Set open from it.
onMouseEnterMouseEventHandler<HTMLUListElement>Fires when the pointer enters the menu list.
onMouseLeaveMouseEventHandler<HTMLUListElement>Fires when the pointer leaves the menu list.
onSelectSelectEventHandlerFires when a menu item is selected.

Children​

Sidebar does not accept children.

Variants​

Loading examples…

Playground​

Change the controls to see how the properties affect the component. Values the controls don't cover come from the Default example.

Loading playground…

Storybook​

Open Sidebar in Storybook to try every story with the full set of controls.