sidebar

The Sidebar component provides a vertical navigation menu with support for nested links, expandable groups, optional footer content, and consumer-controlled active state matching.

Usage & Examples

default.tsx

  const links = [
    { label: "Dashboard", href: "/demos/dashboard", icon: <FaBook /> },
    {
      label: "Reports",
      href: "/demos/dashboard#analytics",
      children: [
        { label: "Monthly", href: "/demos/dashboard#revenue", icon: <FaCalendar /> },
        { label: "Annual", href: "/demos/dashboard#pipeline", icon: <FaCalendar /> },
      ],
      icon: <FaPaperclip />,
    },
    { label: "Settings", href: "/demos/dashboard#settings", icon: <FaCogs /> },
  ];
  
  const currentPath = "/demos/dashboard#settings";
  
  const normalizePath = (p: string) =>
    p.endsWith("/") && p.length > 1 ? p.slice(0, -1) : p;
  
  const isDescendantPath = (parentPath: string, currentPath: string) => {
    const parent = normalizePath(parentPath);
    const current = normalizePath(currentPath);
  
    if (parent === "/") return current === "/";
    return current === parent || current.startsWith(`${parent}/`);
  };
  
  const isActiveRecursive = (link, matcher) => {
    if (matcher(link)) return true;
    return !!link.children?.some((child) => isActiveRecursive(child, matcher));
  };
  
  const isLinkActive = (link) => {
    if (!link.href) return false;
  
    if (link.children?.length) {
      return isDescendantPath(link.href, currentPath);
    }
  
    return normalizePath(link.href) === normalizePath(currentPath);
  };
  
  const hasActiveChild = (link) =>
    !!link.children?.some((child) => isActiveRecursive(child, isLinkActive));
  
  <Sidebar
    links={links}
    isLinkActive={isLinkActive}
    hasActiveChild={hasActiveChild}
  />
        

Props API

38 props
Columns
sidebar props API
Default
Description
activeClassNamestringNopropsAdditional class name applied when a link/item is active.
aria-describedbystringNoariaID reference to one or more elements that describe the sidebar navigation landmark.
aria-labelstringNoaria"Sidebar navigation"Accessible label for the navigation landmark. Prefer the kebab-case ARIA prop for consistency with other React ARIA props.
aria-labelledbystringNoariaID reference to one or more elements that label the sidebar navigation landmark. Takes precedence over aria-label when both are provided.
chevronClassNamestringNopropsAdditional class name for chevron icons.
chevronOpenClassNamestringNopropsAdditional class name applied when the chevron is open.
childLinkClassNamestringNopropsAdditional class name for child link-style items.
childListClassNamestringNopropsAdditional class name for nested child lists.
classNamestringNostylingAdditional class name(s) for applying custom styles.
data-testidstringNotestingBackward-compatible alias for test ID attributes.
expandButtonClassNamestringNopropsAdditional class name for expandable parent buttons.
expandLabelClassNamestringNopropsAdditional class name for expandable item labels.