# Sidebar

> A collapsible, grouped navigation rail with labelled sections, a current-item accent, and badges folded into each item's accessible name.

- Package: `fancy-ui-react` (React 18/19 + Tailwind CSS v4)
- Category: Navigation
- Tags: sidebar, nav, rail, collapsible, compound, badge
- Types: `SidebarProps`, `SidebarGroupProps`, `SidebarItemProps`, `SidebarSeparatorProps`, `SidebarFooterProps`, `SidebarContext`
- Docs: https://fancy-ui.rama.app/docs/components/sidebar
- Source: https://github.com/RamaHerbin/fancy-ui/tree/main/react/src/components/sidebar

## Import

```tsx
import { Sidebar } from 'fancy-ui-react';
```

Setup (once per project): `npm install fancy-ui-react`, then put these lines in your main CSS file (the stylesheet import goes right after `@import "tailwindcss";`):

```css
@import "tailwindcss";
@import "fancy-ui-react/tailwind.css";
```

and import the component styles once in the app entry: `import "fancy-ui-react/styles.css";`. Full guide: https://fancy-ui.rama.app/llms.txt

The names below are the ones to write in React; when one differs from the Svelte name, the Svelte name follows in parentheses. `class` becomes `className`, a callback takes the name the React port declares (`onclick` becomes `onClick`), snippets become `ReactNode` props (render functions when they take arguments) and the default snippet is `children`. Divergences: https://github.com/RamaHerbin/fancy-ui/tree/main/react#divergences-from-the-svelte-api

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `label` | `string` | `"Sidebar"` | Accessible name for the nav landmark. |
| `collapsed` | `boolean` | `false` | Whether the sidebar is collapsed to an icon-only rail. Plain, not bindable — nothing inside the compound ever changes it itself. |
| `className` (Svelte `class`) | `string` | — | Additional CSS classes, merged onto the root. |
| `ref` | `HTMLElement \| null` | `null` | Bindable reference to the root nav element. |
| `SidebarGroup.label` (required) | `string` | — | The section heading, e.g. "General". |
| `SidebarGroup.className` (Svelte `SidebarGroup.class`) | `string` | — | Additional CSS classes, merged onto the group. |
| `SidebarItem.href` | `string` | — | Renders an <a> when set; a <button type="button"> otherwise. |
| `SidebarItem.current` | `boolean` | `false` | Marks this as the current item — aria-current="page" plus the accent left bar. |
| `SidebarItem.badge` | `string \| number` | — | A count or short flag, e.g. 4, rendered as a pill. |
| `SidebarItem.badgeLabel` | `string` | — | What the badge means, folded into the accessible name. Defaults to just the badge value. |
| `SidebarItem.disabled` | `boolean` | `false` | Disables both the click and keyboard-activation paths. |
| `SidebarItem.onClick` (Svelte `SidebarItem.onclick`) | `(event: MouseEvent) => void` | — | Native click handler, for the button branch. Never called while disabled. |
| `SidebarItem.className` (Svelte `SidebarItem.class`) | `string` | — | Additional CSS classes, merged onto the item. |
| `SidebarItem.ref` | `HTMLAnchorElement \| HTMLButtonElement \| null` | `null` | Bindable reference to the item's interactive element. |
| `SidebarItem.sound` | `boolean` | `false` | Plays select when a sidebar item that is not already current is activated, once the user has enabled sound |
| `SidebarSeparator.className` (Svelte `SidebarSeparator.class`) | `string` | — | Additional CSS classes, merged onto the hairline. |
| `SidebarSeparator.ref` | `HTMLHRElement \| null` | `null` | Bindable reference to the <hr> element. |
| `SidebarFooter.className` (Svelte `SidebarFooter.class`) | `string` | — | Additional CSS classes, merged onto the footer row. |
| `SidebarFooter.ref` | `HTMLDivElement \| null` | `null` | Bindable reference to the footer's root element. |

## Node props

| Prop | Description |
| --- | --- |
| `children` | SidebarGroup, SidebarSeparator and SidebarFooter. |
| `SidebarGroup.children` | The SidebarItems in this section. |
| `SidebarItem.icon` | A decorative glyph or icon, shown even while the sidebar is collapsed. |
| `SidebarItem.children` | The item's label. Moves to sr-only text while collapsed — never removed. |
| `SidebarFooter.avatar` | A decorative avatar, shown even while the sidebar is collapsed. |
| `SidebarFooter.children` | The name / text next to the avatar. sr-only while collapsed. |

## Example

No React example is published for this component yet: start from the import above and the props table. The full examples are Svelte-only, on https://fancy-ui.rama.app/docs/components/sidebar.md.
