Sidebar
The column of the primary navigation, a container and its icon items, that the application frame expands, collapses and opens on small viewports.
Hover or focus an icon to see its name. The item for the current page has the primary fill.
The links in these previews point to a section of the same page (#id). They are real anchors, so they can be focused and activated, without sending you to another page. In an app, the item wraps the app’s CustomLink with asChild.
When to use
- For the primary navigation between the main areas of the product: Processos, Tarefas, Petições, Relatórios.
- Inside App shell, which gives it a width, collapses it and moves it into a sheet on small viewports.
When not to use
- Navigation inside one page. Use Tabs.
- The path to the current page. Use Breadcrumb.
- A menu of actions. Use a Dropdown menu or a Button menu.
- More than about 8 entries. Group them under a heading or move rarely used ones into a page.
Anatomy
| Part | Role |
|---|---|
SidebarContainer |
A full-height flex column. Renders an aside, or nav with as="nav". It sets no width. |
SidebarItem |
A Button sized for icons (36px). isActive switches it from ghost to primary. Use asChild for links. |
The container does not collapse or open by itself. The parent controls its width: w-14 (56px) for icons only and w-64 (256px) for icons with labels, as in the app.
Collapsed and expanded
Collapsed
Only icons. Each item needs an aria-label, and a Tooltip shows the name on hover and focus.
Expanded
Icon and label side by side. Items fill the width with className="w-full justify-start".
Behavior in the application frame
App shell wraps the sidebar and decides how it behaves:
- On desktop (768px and wider) the sidebar is a column. It is 256px wide when expanded and 56px when collapsed, with a 300ms width transition. A button at the foot toggles it.
- Below 768px the column is hidden. A menu button in the top bar opens the same content in a sheet from the left, 288px wide, with a close button. The content is always shown expanded in the sheet.
- The content component calls
onNavigatewhen an item is chosen, which closes the sheet.
The content component receives collapsed and onNavigate from the shell.
Content
- Labels are one or two words: “Processos”, “Tarefas”, “Relatórios”.
- Use the same noun in the sidebar and in the page title it leads to.
- Keep the order stable between sessions. Put the most used area first.
- Use Lucide icons with
aria-hidden, and name the item through its label oraria-label.
Do and don’t
Accessibility
- Use
as="nav"so the column is a navigation landmark, and give the landmark a name through the wrapper. The container does not forwardaria-label. - Items are
Buttonelements, or anchors withasChild.Tabmoves between them andEnteractivates them (andSpacefor buttons). - Icon-only items must have an
aria-label. Tooltips come from Radix Tooltip: they show on hover and keyboard focus andEscapehides them. isActivesetsaria-selected, which is not a valid attribute for a button or link (see Known issues). Also setaria-current="page"on the link of the current page.- Items are 36px tall and wide, above the 24px minimum.
Code
import { SidebarContainer, SidebarItem } from "@repo/ui/sidebar";
import { Tooltip, TooltipContent, TooltipTrigger } from "@repo/ui/tooltip";
import { FolderOpen } from "lucide-react";
import CustomLink from "components/CustomLink";
<SidebarContainer as="nav" className="items-start">
<Tooltip>
<TooltipTrigger asChild>
<SidebarItem asChild isActive>
<CustomLink aria-current="page" aria-label="Processos" href="/cases">
<FolderOpen aria-hidden />
</CustomLink>
</SidebarItem>
</TooltipTrigger>
<TooltipContent side="right">Processos</TooltipContent>
</Tooltip>
</SidebarContainer>;
Wrap the sidebar in a TooltipProvider.
Props
SidebarContainer| Prop | Type | Default | Description |
|---|---|---|---|
as | ElementType | aside | Element rendered by `SidebarContainer`. Use `nav` when it holds the main navigation |
SidebarContainer (other props)| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | The items. |
className | string | — | Extra classes. Alignment and layout only. |
SidebarItem| Prop | Type | Default | Description |
|---|---|---|---|
isActive | boolean | — | Marks the item for the current page: `primary` variant instead of `ghost`. |
asChild | boolean | false | Renders the child (the app's link) instead of a button. |
className | string | — | Extra classes. Use `w-full justify-start` for an expanded item. |
...ButtonProps | ButtonProps | — | Every other Button prop. `size` and `variant` are accepted but ignored (see Known issues). |
Known issues
| Issue | Effect |
|---|---|
SidebarItem sets size="xsIcon" and variant after spreading its props. |
size and variant are accepted by the type but ignored. apps/app passes size and gets no effect. |
SidebarItem sets aria-selected for the active item. |
aria-selected is not supported on buttons or links. Assistive technology ignores the active state. |
SidebarContainer does not forward props other than children, className, as and ref. |
A nav cannot get an aria-label, an id or a data-* attribute. |