Sidebar
Sidebar is a component used to display a list of items in a sidebar.
<Sidebar.Root>
<Sidebar.SidePanel bg="bg.panel">
<Sidebar.Header>
<Menu.Root
animationScheme={{ base: "inline-start", md: "block-start" }}
gutter={{ base: 16, md: 8 }}
matchWidth={{ base: false, md: true }}
placement={{ base: "center-end-start", md: "end" }}
>
<Menu.Trigger>
<Sidebar.MenuButton>
<Center
bg="colorScheme.solid"
color="colorScheme.contrast"
fontSize="{side-panel-item-icon-size}"
minBoxSize="{side-panel-item-size}"
rounded="l2"
>
<GalleryVerticalEndIcon />
</Center>
<Grid flex="1" gap="xs" lineHeight="1" textAlign="start">
<Text truncated>Documentation</Text>
<Text color="fg.muted" truncated>
v2.2.0
</Text>
</Grid>
<ChevronsUpDownIcon
color="fg.muted"
fontSize="{side-panel-item-icon-size}"
/>
</Sidebar.MenuButton>
</Menu.Trigger>
<Menu.Content
items={[
{ label: "v0.9.10", value: "v0.9.10" },
{ label: "v1.7.8", value: "v1.7.8" },
{ label: "v2.2.0", value: "v2.2.0" },
]}
/>
</Menu.Root>
</Sidebar.Header>
<Sidebar.Content>
<Sidebar.Group>
<Sidebar.GroupLabel>Get Started</Sidebar.GroupLabel>
<Sidebar.GroupContent>
<Sidebar.Item
label="Installation"
value="/get-started/installation"
/>
<Sidebar.Item label="Frameworks" value="/get-started/frameworks">
<Sidebar.Item
label="Next.js (App)"
value="/get-started/frameworks/next-app"
/>
<Sidebar.Item
label="Next.js (Pages)"
value="/get-started/frameworks/next-pages"
/>
<Sidebar.Item label="Vite" value="/get-started/frameworks/vite" />
<Sidebar.Item
label="React Router"
value="/get-started/frameworks/react-router"
/>
<Sidebar.Item
label="TanStack Start"
value="/get-started/frameworks/tanstack-start"
/>
<Sidebar.Item
label="TanStack Router"
value="/get-started/frameworks/tanstack-router"
/>
</Sidebar.Item>
</Sidebar.GroupContent>
</Sidebar.Group>
<Sidebar.Group>
<Sidebar.GroupLabel>Styling</Sidebar.GroupLabel>
<Sidebar.GroupContent>
<Sidebar.Item label="Overview" value="/styling/overview" />
<Sidebar.Item label="Style Props" value="/styling/style-props" />
</Sidebar.GroupContent>
</Sidebar.Group>
<Sidebar.Group>
<Sidebar.GroupLabel>Theming</Sidebar.GroupLabel>
<Sidebar.GroupContent>
<Sidebar.Item label="Overview" value="/theming/overview" />
<Sidebar.Item label="Customization" value="/theming/customization" />
</Sidebar.GroupContent>
</Sidebar.Group>
</Sidebar.Content>
<Sidebar.Footer>
<Menu.Root
animationScheme={{ base: "inline-start", md: "block-end" }}
gutter={{ base: 16, md: 8 }}
matchWidth={{ base: false, md: true }}
placement={{ base: "center-end-end", md: "start" }}
>
<Menu.Trigger>
<Sidebar.MenuButton>
<Avatar
name="Hirotomo Yamada"
src="https://avatars.githubusercontent.com/u/84060430?v=4"
size="xs"
shape="rounded"
/>
<Grid flex="1" gap="xs" lineHeight="1" textAlign="start">
<Text truncated>Hirotomo Yamada</Text>
<Text color="fg.muted" truncated>
hirotomo.yamada@avap.co.jp
</Text>
</Grid>
<ChevronsUpDownIcon
color="fg.muted"
fontSize="{side-panel-item-icon-size}"
/>
</Sidebar.MenuButton>
</Menu.Trigger>
<Menu.Content
items={[
{ label: "Upgrade to Pro", value: "Upgrade to Pro" },
{ type: "separator" },
{ label: "Account", value: "Account" },
{ label: "Billing", value: "Billing" },
{ label: "Notification", value: "Notification" },
{ type: "separator" },
{ label: "Logout", value: "Logout" },
]}
/>
</Menu.Root>
</Sidebar.Footer>
</Sidebar.SidePanel>
<Sidebar.MainPanel p="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
</Sidebar.MainPanel>
</Sidebar.Root>
Usage
import { Sidebar } from "@yamada-ui/react"
import { Sidebar } from "@/components/ui"
import { Sidebar } from "@workspaces/ui"
<Sidebar.Root>
<Sidebar.SidePanel>
<Sidebar.Header>
<Sidebar.Menu />
<Sidebar.MenuButton />
</Sidebar.Header>
<Sidebar.Content>
<Sidebar.Item>
<Sidebar.Item />
</Sidebar.Item>
<Sidebar.Item />
<Sidebar.Group>
<Sidebar.GroupLabel />
<Sidebar.GroupContent>
<Sidebar.Item>
<Sidebar.Item />
</Sidebar.Item>
<Sidebar.Item />
</Sidebar.GroupContent>
</Sidebar.Group>
</Sidebar.Content>
<Sidebar.Footer>
<Sidebar.Menu />
<Sidebar.MenuButton />
</Sidebar.Footer>
<Sidebar.Handle />
</Sidebar.SidePanel>
<Sidebar.MainPanel>
<Sidebar.Trigger />
</Sidebar.MainPanel>
</Sidebar.Root>
Integrate with Next.js
When integrating with frameworks such as Next.js, set the link component provided by the framework to linkProps.as. To sync routing, set selectedValue to the current path obtained from the framework's function or hook.
"use client"
import { usePathname } from "next/navigation"
import Link from "next/link"
function Layout({ children }: { children: React.ReactNode }) {
const pathname = usePathname()
return (
<Sidebar.Root>
<Sidebar.SidePanel linkProps={{ as: Link }} selectedValue={pathname} />
</Sidebar.Root>
)
}
Use items
const items = useMemo<Sidebar.Item[]>(
() => [
{
children: [
{ label: "Installation", value: "/get-started/installation" },
{ label: "CLI", value: "/get-started/cli" },
{
children: [
{
label: "Next.js (App)",
value: "/get-started/frameworks/next-app",
},
{
label: "Next.js (Pages)",
value: "/get-started/frameworks/next-pages",
},
{ label: "Vite", value: "/get-started/frameworks/vite" },
{
label: "React Router",
value: "/get-started/frameworks/react-router",
},
{
label: "TanStack Start",
value: "/get-started/frameworks/tanstack-start",
},
{
label: "TanStack Router",
value: "/get-started/frameworks/tanstack-router",
},
],
label: "Frameworks",
value: "/get-started/frameworks",
},
],
group: true,
label: "Get Started",
},
{
children: [
{ label: "Overview", value: "/styling/overview" },
{ label: "Style Props", value: "/styling/style-props" },
],
group: true,
label: "Styling",
},
{
children: [
{ label: "Overview", value: "/theming/overview" },
{ label: "Customization", value: "/theming/customization" },
],
group: true,
label: "Theming",
},
],
[],
)
return (
<Sidebar.Root>
<Sidebar.SidePanel
bg="bg.panel"
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
items={items}
/>
<Sidebar.MainPanel p="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
</Sidebar.MainPanel>
</Sidebar.Root>
)
Change Variant
<Sidebar.Root variant="solid" defaultSelectedValue="/get-started/installation">
<Sidebar.SidePanel
bg="bg.panel"
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
items={sidebarItems}
/>
<Sidebar.MainPanel p="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
</Sidebar.MainPanel>
</Sidebar.Root>
<Sidebar.Root variant="subtle" defaultSelectedValue="/get-started/installation">
<Sidebar.SidePanel
bg="bg.panel"
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
items={sidebarItems}
/>
<Sidebar.MainPanel p="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
</Sidebar.MainPanel>
</Sidebar.Root>
Change Color Scheme
<Sidebar.Root defaultSelectedValue="/get-started/installation">
<Sidebar.SidePanel
colorScheme="blue"
bg="bg.panel"
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
items={sidebarItems}
/>
<Sidebar.MainPanel p="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
</Sidebar.MainPanel>
</Sidebar.Root>
Change Mode
To change the mode, set mode to "offcanvas" or "icon". The default is "offcanvas".
<Sidebar.Root mode="offcanvas">
<Sidebar.SidePanel
bg="bg.panel"
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
items={sidebarItems}
/>
<Sidebar.MainPanel p="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
</Sidebar.MainPanel>
</Sidebar.Root>
const items = useMemo<Sidebar.ItemType[]>(
() => [
{
children: [
{
label: "Installation",
startElement: <ImportIcon />,
value: "/get-started/installation",
},
{
label: "CLI",
startElement: <SquareTerminalIcon />,
value: "/get-started/cli",
},
],
label: "Get Started",
startElement: <RocketIcon />,
value: "/get-started",
},
{
children: [
{
label: "Overview",
startElement: <TextAlignStartIcon />,
value: "/styling/overview",
},
{
label: "Style Props",
startElement: <SwatchBookIcon />,
value: "/styling/style-props",
},
],
label: "Styling",
startElement: <PaintbrushIcon />,
value: "/styling",
},
{
children: [
{
label: "Overview",
startElement: <TextAlignStartIcon />,
value: "/theming/overview",
},
{
label: "Customization",
startElement: <WrenchIcon />,
value: "/theming/customization",
},
],
label: "Theming",
startElement: <PaletteIcon />,
value: "/theming",
},
],
[],
)
return (
<Sidebar.Root mode="icon">
<Sidebar.SidePanel
bg="bg.panel"
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
items={items}
/>
<Sidebar.MainPanel p="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
</Sidebar.MainPanel>
</Sidebar.Root>
)
Change Shape
<Sidebar.Root
defaultExpandedValue={["/get-started"]}
defaultSelectedValue="/get-started/installation"
shape="square"
>
<Sidebar.SidePanel
bg="bg.panel"
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
items={sidebarItems}
/>
<Sidebar.MainPanel p="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
</Sidebar.MainPanel>
</Sidebar.Root>
<Sidebar.Root
defaultExpandedValue={["/get-started"]}
defaultSelectedValue="/get-started/installation"
shape="rounded"
>
<Sidebar.SidePanel
bg="bg.panel"
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
items={sidebarItems}
/>
<Sidebar.MainPanel p="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
</Sidebar.MainPanel>
</Sidebar.Root>
<Sidebar.Root
defaultExpandedValue={["/get-started"]}
defaultSelectedValue="/get-started/installation"
shape="circle"
>
<Sidebar.SidePanel
bg="bg.panel"
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
items={sidebarItems}
/>
<Sidebar.MainPanel p="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
</Sidebar.MainPanel>
</Sidebar.Root>
Change Placement
To change the placement, set placement to "start" or "end". The default is "start".
<Sidebar.Root placement="end">
<Sidebar.SidePanel
bg="bg.panel"
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
items={sidebarItems}
/>
<Sidebar.MainPanel p="md">
<VStack alignItems="flex-start" gap="md">
<Sidebar.Trigger alignSelf="flex-end">
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
</VStack>
</Sidebar.MainPanel>
</Sidebar.Root>
To override the placement on mobile, set drawerProps to placement.
<Sidebar.Root>
<Sidebar.SidePanel
bg="bg.panel"
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
items={sidebarItems}
drawerProps={{ placement: "inline-end" }}
/>
<Sidebar.MainPanel p="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
</Sidebar.MainPanel>
</Sidebar.Root>
Change Breakpoint
To change the breakpoint for mobile, set breakpoint to the value. This value refers to Breakpoints.
<Sidebar.Root breakpoint="lg">
<Sidebar.SidePanel
bg="bg.panel"
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
items={sidebarItems}
/>
<Sidebar.MainPanel p="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
</Sidebar.MainPanel>
</Sidebar.Root>
Disable Breakpoint
To disable the breakpoint for mobile, set breakpoint to false.
<Sidebar.Root breakpoint={false}>
<Sidebar.SidePanel
bg="bg.panel"
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
items={sidebarItems}
/>
<Sidebar.MainPanel p="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
</Sidebar.MainPanel>
</Sidebar.Root>
Set Default Closed
To have the sidebar closed by default, set disclosure.desktop.defaultOpen to false.
<Sidebar.Root disclosure={{ desktop: { defaultOpen: false } }}>
<Sidebar.SidePanel
bg="bg.panel"
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
items={sidebarItems}
/>
<Sidebar.MainPanel p="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
</Sidebar.MainPanel>
</Sidebar.Root>
Set Default Selected Item
To have a specific item selected by default, set defaultSelectedValue.
<Sidebar.Root
defaultExpandedValue={["/get-started"]}
defaultSelectedValue="/get-started/installation"
>
<Sidebar.SidePanel
bg="bg.panel"
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
items={sidebarItems}
/>
<Sidebar.MainPanel p="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
</Sidebar.MainPanel>
</Sidebar.Root>
Set Default Expanded Items
To have specific items expanded by default, set defaultExpandedValue.
<Sidebar.Root defaultExpandedValue={["/get-started/frameworks"]}>
<Sidebar.SidePanel
bg="bg.panel"
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
items={sidebarItems}
/>
<Sidebar.MainPanel p="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
</Sidebar.MainPanel>
</Sidebar.Root>
Disable an Item
To disable specific items, set disabled.
const items = useMemo<Sidebar.ItemType[]>(
() => [
{
children: [
{ label: "Installation", value: "/get-started/installation" },
{ label: "CLI", value: "/get-started/cli" },
{
children: [
{
label: "Next.js (App)",
value: "/get-started/frameworks/nextjs-app",
},
{
label: "Next.js (Pages)",
value: "/get-started/frameworks/nextjs-pages",
},
{ label: "Vite", value: "/get-started/frameworks/vite" },
{
label: "React Router",
value: "/get-started/frameworks/react-router",
},
{
label: "TanStack Start",
value: "/get-started/frameworks/tanstack-start",
},
{
label: "TanStack Router",
value: "/get-started/frameworks/tanstack-router",
},
],
label: "Frameworks",
value: "/get-started/frameworks",
},
],
disabled: true,
label: "Get Started",
value: "/get-started",
},
{
children: [
{ label: "Overview", value: "/styling/overview" },
{ disabled: true, label: "Style Props", value: "/styling/style-props" },
],
label: "Styling",
value: "/styling",
},
{
children: [
{ label: "Overview", value: "/theming/overview" },
{ label: "Customization", value: "/theming/customization" },
],
label: "Theming",
value: "/theming",
},
],
[],
)
return (
<Sidebar.Root defaultExpandedValue={["/styling"]}>
<Sidebar.SidePanel
bg="bg.panel"
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
items={items}
/>
<Sidebar.MainPanel p="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
</Sidebar.MainPanel>
</Sidebar.Root>
)
Save Values to LocalStorage
const [defaultOpen, setDefaultOpen] = useLocalStorage({
key: "sidebar-expanded",
defaultValue: true,
getInitialValueInEffect: false,
})
const disclosure = useDisclosure({
defaultOpen,
onClose: () => setDefaultOpen(false),
onOpen: () => setDefaultOpen(true),
})
return (
<Sidebar.Root disclosure={{ desktop: disclosure }}>
<Sidebar.SidePanel
bg="bg.panel"
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
items={sidebarItems}
/>
<Sidebar.MainPanel p="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
</Sidebar.MainPanel>
</Sidebar.Root>
)
"use client" to the top of the file.Save Values to Cookie
const key = "sidebar-expanded"
const getStorage = useCallback(() => {
const match = document.cookie.match(new RegExp(`(^| )${key}=([^;]+)`))
return match ? match[2] === "true" : true
}, [])
const setStorage = useCallback((value: boolean) => {
document.cookie = `${key}=${value}; max-age=31536000; path=/`
}, [])
const disclosure = useDisclosure({
defaultOpen: getStorage(),
onClose: () => setStorage(false),
onOpen: () => setStorage(true),
})
return (
<Sidebar.Root disclosure={{ desktop: disclosure }}>
<Sidebar.SidePanel
bg="bg.panel"
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
items={sidebarItems}
/>
<Sidebar.MainPanel p="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
</Sidebar.MainPanel>
</Sidebar.Root>
)
"use client" to the top of the file.Show Group Guide Line
To show group guide lines, set withGroupGuideLine to true.
<Sidebar.Root withGroupGuideLine>
<Sidebar.SidePanel
bg="bg.panel"
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
items={sidebarItems}
/>
<Sidebar.MainPanel p="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
</Sidebar.MainPanel>
</Sidebar.Root>
Show Guide Line
To show guide lines, set withGuideLine to true.
<Sidebar.Root withGuideLine>
<Sidebar.SidePanel
bg="bg.panel"
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
items={sidebarItems}
/>
<Sidebar.MainPanel p="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
</Sidebar.MainPanel>
</Sidebar.Root>
Add Separator
const items = useMemo<Sidebar.ItemType[]>(
() => [
{
children: [
{ label: "Installation", value: "/get-started/installation" },
{ label: "CLI", value: "/get-started/cli" },
{
children: [
{
label: "Next.js (App)",
value: "/get-started/frameworks/nextjs-app",
},
{
label: "Next.js (Pages)",
value: "/get-started/frameworks/nextjs-pages",
},
{ label: "Vite", value: "/get-started/frameworks/vite" },
{
label: "React Router",
value: "/get-started/frameworks/react-router",
},
{
label: "TanStack Start",
value: "/get-started/frameworks/tanstack-start",
},
{
label: "TanStack Router",
value: "/get-started/frameworks/tanstack-router",
},
],
label: "Frameworks",
value: "/get-started/frameworks",
},
],
label: "Get Started",
value: "/get-started",
},
{
children: [
{ label: "Overview", value: "/styling/overview" },
{ label: "Style Props", value: "/styling/style-props" },
],
label: "Styling",
value: "/styling",
},
{
children: [
{ label: "Overview", value: "/theming/overview" },
{ label: "Customization", value: "/theming/customization" },
],
label: "Theming",
value: "/theming",
},
],
[],
)
return (
<Sidebar.Root>
<Sidebar.SidePanel
bg="bg.panel"
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
items={items}
withHandle={false}
contentProps={{
css: {
"& > li": {
_after: {
borderBottomWidth: "1px",
mt: "{side-panel-space}",
mx: "calc({side-panel-space} * -1)",
},
},
},
gap: "{side-panel-space}",
py: "{side-panel-space}",
}}
footerProps={{ borderTopWidth: "1px" }}
headerProps={{ borderBottomWidth: "1px" }}
/>
<Sidebar.MainPanel p="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
</Sidebar.MainPanel>
</Sidebar.Root>
)
Hide Indicator
To hide the indicator, set indicatorHidden to true.
<Sidebar.Root>
<Sidebar.SidePanel
bg="bg.panel"
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
indicatorHidden
items={sidebarItems}
/>
<Sidebar.MainPanel p="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
</Sidebar.MainPanel>
</Sidebar.Root>
Disable Animation
To disable animation when expanding and collapsing, set animated to false.
<Sidebar.Root>
<Sidebar.SidePanel
animated={false}
bg="bg.panel"
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
items={sidebarItems}
/>
<Sidebar.MainPanel p="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
</Sidebar.MainPanel>
</Sidebar.Root>
Disable Resize Handle
To disable the resize handle, set withHandle to false. The default is true.
<Sidebar.Root>
<Sidebar.SidePanel
bg="bg.panel"
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
items={sidebarItems}
withHandle={false}
/>
<Sidebar.MainPanel p="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
</Sidebar.MainPanel>
</Sidebar.Root>
Async Loading
To load child items asynchronously, use asyncChildren instead of children.
const items = useMemo<Sidebar.ItemType[]>(
() => [
{
asyncChildren: async () => {
await wait(1000)
return [
{ label: "Installation", value: "/get-started/installation" },
{ label: "CLI", value: "/get-started/cli" },
{
asyncChildren: async () => {
await wait(1000)
return [
{
label: "Next.js (App)",
value: "/get-started/frameworks/nextjs-app",
},
{
label: "Next.js (Pages)",
value: "/get-started/frameworks/nextjs-pages",
},
{ label: "Vite", value: "/get-started/frameworks/vite" },
{
label: "React Router",
value: "/get-started/frameworks/react-router",
},
{
label: "TanStack Start",
value: "/get-started/frameworks/tanstack-start",
},
{
label: "TanStack Router",
value: "/get-started/frameworks/tanstack-router",
},
]
},
label: "Frameworks",
value: "/get-started/frameworks",
},
]
},
label: "Get Started",
value: "/get-started",
},
{
asyncChildren: async () => {
await wait(1000)
return [
{ label: "Overview", value: "/styling/overview" },
{ label: "Style Props", value: "/styling/style-props" },
]
},
label: "Styling",
value: "/styling",
},
{
asyncChildren: async () => {
await wait(1000)
return [
{ label: "Overview", value: "/theming/overview" },
{ label: "Customization", value: "/theming/customization" },
]
},
label: "Theming",
value: "/theming",
},
],
[],
)
return (
<Sidebar.Root>
<Sidebar.SidePanel
bg="bg.panel"
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
items={items}
/>
<Sidebar.MainPanel p="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
</Sidebar.MainPanel>
</Sidebar.Root>
)
"use client" to the top of the file.Change Loading Scheme
const items = useMemo<Sidebar.ItemType[]>(
() => [
{
asyncChildren: async () => {
await wait(1000)
return [
{ label: "Installation", value: "/get-started/installation" },
{ label: "CLI", value: "/get-started/cli" },
]
},
label: "Get Started",
value: "/get-started",
},
{
asyncChildren: async () => {
await wait(1000)
return [
{ label: "Overview", value: "/styling/overview" },
{ label: "Style Props", value: "/styling/style-props" },
]
},
label: "Styling",
value: "/styling",
},
{
asyncChildren: async () => {
await wait(1000)
return [
{ label: "Overview", value: "/theming/overview" },
{ label: "Customization", value: "/theming/customization" },
]
},
label: "Theming",
value: "/theming",
},
],
[],
)
return (
<Sidebar.Root>
<Sidebar.SidePanel
bg="bg.panel"
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
items={items}
loadingScheme="dots"
/>
<Sidebar.MainPanel p="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
</Sidebar.MainPanel>
</Sidebar.Root>
)
"use client" to the top of the file.Expand/Collapse All
To expand or collapse all items, use controlRef.
const controlRef = useRef<Sidebar.Control>(null)
const items = useMemo<Sidebar.ItemType[]>(
() => [
{
children: [
{ label: "Installation", value: "/get-started/installation" },
{ label: "CLI", value: "/get-started/cli" },
{
children: [
{
label: "Next.js (App)",
value: "/get-started/frameworks/nextjs-app",
},
{
label: "Next.js (Pages)",
value: "/get-started/frameworks/nextjs-pages",
},
{ label: "Vite", value: "/get-started/frameworks/vite" },
{
label: "React Router",
value: "/get-started/frameworks/react-router",
},
{
label: "TanStack Start",
value: "/get-started/frameworks/tanstack-start",
},
{
label: "TanStack Router",
value: "/get-started/frameworks/tanstack-router",
},
],
label: "Frameworks",
value: "/get-started/frameworks",
},
],
label: "Get Started",
value: "/get-started",
},
{
children: [
{ label: "Overview", value: "/styling/overview" },
{ label: "Style Props", value: "/styling/style-props" },
],
label: "Styling",
value: "/styling",
},
{
children: [
{ label: "Overview", value: "/theming/overview" },
{ label: "Customization", value: "/theming/customization" },
],
label: "Theming",
value: "/theming",
},
],
[],
)
return (
<Sidebar.Root controlRef={controlRef}>
<Sidebar.SidePanel
bg="bg.panel"
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
items={items}
/>
<Sidebar.MainPanel p="md">
<VStack alignItems="flex-start" gap="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
<ButtonGroup.Root px="sm">
<ButtonGroup.Item onClick={() => controlRef.current?.expand()}>
Expand All
</ButtonGroup.Item>
<ButtonGroup.Item onClick={() => controlRef.current?.collapse()}>
Collapse All
</ButtonGroup.Item>
</ButtonGroup.Root>
</VStack>
</Sidebar.MainPanel>
</Sidebar.Root>
)
Customize Element
<Sidebar.Root>
<Sidebar.SidePanel
bg="bg.panel"
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
items={sidebarItems}
startElement={{
group: ({ expanded }) =>
expanded ? <FolderOpenIcon /> : <FolderClosedIcon />,
item: <FileIcon />,
}}
/>
<Sidebar.MainPanel p="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
</Sidebar.MainPanel>
</Sidebar.Root>
"use client" to the top of the file.<Sidebar.Root>
<Sidebar.SidePanel
bg="bg.panel"
endElement={{ item: <SquareArrowOutUpRightIcon /> }}
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
items={sidebarItems}
/>
<Sidebar.MainPanel p="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
</Sidebar.MainPanel>
</Sidebar.Root>
Customize Indicator
<Sidebar.Root>
<Sidebar.SidePanel
bg="bg.panel"
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
indicator={({ expanded }) => (expanded ? <MinusIcon /> : <PlusIcon />)}
items={sidebarItems}
indicatorProps={{ _expanded: { transform: "rotate(0deg)" } }}
/>
<Sidebar.MainPanel p="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
</Sidebar.MainPanel>
</Sidebar.Root>
"use client" to the top of the file.Control
const [selectedValue, setSelectedValue] = useState<string>(
"/get-started/installation",
)
const [expandedValue, setExpandedValue] = useState<string[]>(["/get-started"])
const desktopDisclosure = useDisclosure({ defaultOpen: true })
const mobileDisclosure = useDisclosure()
return (
<Sidebar.Root
disclosure={{ desktop: desktopDisclosure, mobile: mobileDisclosure }}
expandedValue={expandedValue}
selectedValue={selectedValue}
onExpandedChange={setExpandedValue}
onSelectedChange={setSelectedValue}
>
<Sidebar.SidePanel
bg="bg.panel"
footer={<SidebarUserMenuButton />}
header={<SidebarDocumentMenuButton />}
items={sidebarItems}
/>
<Sidebar.MainPanel p="md">
<VStack alignItems="flex-start" gap="md">
<Sidebar.Trigger>
<IconButton
size="xs"
variant="ghost"
fontSize="md"
icon={<PanelLeftIcon />}
/>
</Sidebar.Trigger>
<VStack gap="0" px="sm">
<Text>Selected Value: {selectedValue}</Text>
<Text>Expanded Value: {expandedValue.join(", ")}</Text>
<Text>Desktop Open: {desktopDisclosure.open.toString()}</Text>
<Text>Mobile Open: {mobileDisclosure.open.toString()}</Text>
</VStack>
</VStack>
</Sidebar.MainPanel>
</Sidebar.Root>
)
"use client" to the top of the file.Props
Similar Components
Tabs
Tabs is a component for switching between different display areas.
Breadcrumb
Breadcrumb is a component that helps users understand the hierarchy of a website.
LinkBox
LinkBox is a component that allows elements such as articles or cards to function as a single link.
NativeAccordion
NativeAccordion is a component for a list that displays information in an expandable or collapsible manner using the HTML details element.
Pagination
Pagination is a component for managing the pagination and navigation of content.
Accordion
Accordion is a component for a list that displays information in an expandable or collapsible manner.
Steps
Steps is a component that displays the progress of a multi-step process.
Tree
Tree is a component used to display hierarchical data structures in an expandable tree format.
Uses Components & Hooks
Collapse
Collapse is a component that allows you to expand or collapse an element for display.
Loading
Loading is a component displayed during waiting times, such as when data is being loaded.
Motion
Motion is a convenient component that extends the Yamada UI Style Props to Motion.
Drawer
Drawer is a component for a panel that appears from the edge of the screen.
Icon
Icon is a general icon component that can be used in your projects.
Tooltip
Tooltip is a component that displays short information, such as supplementary details for an element.
useBreakpoint
useBreakpoint is a custom hook that returns the current breakpoint. This hook monitors changes in the window size and returns the appropriate value.
useValue
useValue is a custom hook that combines useBreakpointValue and useColorModeValue.
useAsyncCallback
useAsyncCallback is a custom hook for managing asynchronous callbacks.
useDescendants
useDescendants is a custom hook that manages descendants.
useDisclosure
useDisclosure is a custom hook that helps handle common open/close or toggle scenarios. It can be used to control components such as Modal, Dialog, Drawer, etc.
useWindowEvent
useWindowEvent is a custom hook that assigns an event listener to window.