\`) if you use page transitions or require a single root for layout.
Use the `header`, `default` and `footer` slots to customize the sidebar and the `body` or `content` slots to customize the sidebar menu.
```vue [DashboardSidebarExample.vue]
```
\> \[!NOTE]
\> Drag the sidebar near the left edge of the screen to collapse it.
### Resizable
Use the `resizable` prop to make the sidebar resizable.
```vue
```
### Collapsible
Use the `collapsible` prop to make the sidebar collapsible when dragging near the edge of the screen.
\> \[!WARNING]
\> The \[\`DashboardSidebarCollapse\`]\(/docs/components/dashboard-sidebar-collapse) component will have no effect if the sidebar is not collapsible.
```vue
```
\> \[!TIP]
\> See: #slots
\> You can access the \`collapsed\` state in the slot props to customize the content of the sidebar when it is collapsed.
### Size
Use the `min-size`, `max-size`, `default-size` and `collapsed-size` props to customize the size of the sidebar.
```vue
```
\> \[!TIP]
\> See: /docs/components/dashboard-group#props
\> Sizes are calculated as percentages by default. You can change this using the \`unit\` prop on the \`DashboardGroup\` component.
\> \[!NOTE]
\> The \`collapsed-size\` prop is set to \`0\` by default but the sidebar has a \`min-w-16\` to make sure it is visible.
### Side
Use the `side` prop to change the side of the sidebar. Defaults to `left`.
```vue
```
### Mode
Use the `mode` prop to change the mode of the sidebar menu. Defaults to `slideover`.
Use the `body` slot to fill the menu body (under the header) or the `content` slot to fill the entire menu.
\> \[!TIP]
\> See: #props
\> You can use the \`menu\` prop to customize the menu of the sidebar, it will adapt depending on the mode you choose.
```vue [DashboardSidebarModeExample.vue]
```
\> \[!NOTE]
\> These examples contain the \[\`DashboardGroup\`]\(/docs/components/dashboard-group), \[\`DashboardPanel\`]\(/docs/components/dashboard-panel) and \[\`DashboardNavbar\`]\(/docs/components/dashboard-navbar) components as they are required to demonstrate the sidebar on mobile.
### Toggle
Use the `toggle` prop to customize the [DashboardSidebarToggle](https://ui.nuxt.com/docs/components/dashboard-sidebar-toggle) component displayed on mobile.
You can pass any property from the [Button](https://ui.nuxt.com/docs/components/button) component to customize it.
```vue [DashboardSidebarToggleExample.vue]
```
### Toggle Side
Use the `toggle-side` prop to change the side of the toggle button. Defaults to `left`.
```vue [DashboardSidebarToggleSideExample.vue]
```
## Examples
### Control open state
You can control the open state by using the `open` prop or the `v-model:open` directive.
```vue [DashboardSidebarOpenExample.vue]
```
\> \[!NOTE]
\> In this example, leveraging \[\`defineShortcuts\`]\(/docs/composables/define-shortcuts), you can toggle the open state of the DashboardSidebar by pressing .
### Control collapsed state
You can control the collapsed state by using the `collapsed` prop or the `v-model:collapsed` directive.
```vue [DashboardSidebarCollapsedExample.vue]
```
\> \[!NOTE]
\> In this example, leveraging \[\`defineShortcuts\`]\(/docs/composables/define-shortcuts), you can toggle the collapsed state of the DashboardSidebar by pressing .
## API
### Props
```ts
/**
* Props for the DashboardSidebar component
*/
interface DashboardSidebarProps {
/**
* The mode of the sidebar menu.
* @default "\"slideover\" as never"
*/
mode?: T | undefined;
/**
* The props for the sidebar menu component.
*/
menu?: DashboardSidebarMenu
| undefined;
/**
* Customize the toggle button to open the sidebar.
* `{ color: 'neutral', variant: 'ghost' }`{lang="ts-type"}
* @default "true"
*/
toggle?: boolean | Omit | undefined;
/**
* The side to render the toggle button on.
* @default "\"left\""
*/
toggleSide?: "left" | "right" | undefined;
/**
* Automatically close when route changes.
* @default "true"
*/
autoClose?: boolean | undefined;
ui?: { root?: ClassNameValue; header?: ClassNameValue; body?: ClassNameValue; footer?: ClassNameValue; toggle?: ClassNameValue; handle?: ClassNameValue; content?: ClassNameValue; overlay?: ClassNameValue; } | undefined;
/**
* The id of the panel.
*/
id?: string | undefined;
/**
* The side to render the panel on.
* @default "\"left\""
*/
side?: "left" | "right" | undefined;
/**
* The minimum size of the panel.
* @default "10"
*/
minSize?: number | undefined;
/**
* The maximum size of the panel.
* @default "20"
*/
maxSize?: number | undefined;
/**
* The default size of the panel.
* @default "15"
*/
defaultSize?: number | undefined;
/**
* Whether to allow the user to resize the panel.
* @default "false"
*/
resizable?: boolean | undefined;
/**
* Whether to allow the user to collapse the panel.
* @default "false"
*/
collapsible?: boolean | undefined;
/**
* The size of the panel when collapsed.
* @default "0"
*/
collapsedSize?: number | undefined;
/**
* @default "false"
*/
open?: boolean | undefined;
/**
* @default "false"
*/
collapsed?: boolean | undefined;
}
```
### Slots
```ts
/**
* Slots for the DashboardSidebar component
*/
interface DashboardSidebarSlots {
header(): any;
default(): any;
footer(): any;
toggle(): any;
content(): any;
resize-handle(): any;
}
```
## Theme
```ts [app.config.ts]
export default defineAppConfig({
ui: {
dashboardSidebar: {
slots: {
root: 'relative hidden lg:flex flex-col min-h-svh min-w-16 w-(--width) shrink-0',
header: 'h-(--ui-header-height) shrink-0 flex items-center gap-1.5 px-4',
body: 'flex flex-col gap-4 flex-1 overflow-y-auto px-4 py-2',
footer: 'shrink-0 flex items-center gap-1.5 px-4 py-2',
toggle: '',
handle: '',
content: 'lg:hidden',
overlay: 'lg:hidden'
},
variants: {
menu: {
true: {
header: 'sm:px-6',
body: 'sm:px-6',
footer: 'sm:px-6'
}
},
side: {
left: {
root: 'border-e border-default'
},
right: {
root: ''
}
},
toggleSide: {
left: {
toggle: ''
},
right: {
toggle: 'ms-auto'
}
}
}
}
}
})
```
## Changelog
See commit history for \[component]\(https\://github.com/nuxt/ui/commits/v4/src/runtime/components/DashboardSidebar.vue) and \[theme]\(https\://github.com/nuxt/ui/commits/v4/src/theme/dashboard-sidebar.ts).
# DashboardSidebarCollapse
## Usage
The DashboardSidebarCollapse component is used to collapse/expand the [DashboardSidebar](https://ui.nuxt.com/docs/components/dashboard-sidebar) component **when its `collapsible` prop is set**.
```vue
```
It extends the [Button](https://ui.nuxt.com/docs/components/button) component, so you can pass any property such as `color`, `variant`, `size`, etc.
```vue
```
\> \[!NOTE]
\> The button defaults to \`color="neutral"\` and \`variant="ghost"\`.
## Examples
### Within `header` slot
You can put this component in the `header` slot of the [DashboardSidebar](https://ui.nuxt.com/docs/components/dashboard-sidebar) component and use the `collapsed` prop to hide the left part of the header for example:
```vue [layouts/dashboard.vue] {4-8}
```
### Within `leading` slot
You can put this component in the `leading` slot of the [DashboardNavbar](https://ui.nuxt.com/docs/components/dashboard-navbar) component to display it before the title for example:
```vue [pages/index.vue] {11-13}
```
## API
### Props
```ts
/**
* Props for the DashboardSidebarCollapse component
*/
interface DashboardSidebarCollapseProps {
/**
* @default "\"neutral\""
*/
color?: "error" | "neutral" | "primary" | "secondary" | "success" | "info" | "warning" | undefined;
/**
* @default "\"ghost\""
*/
variant?: "ghost" | "solid" | "outline" | "soft" | "subtle" | "link" | undefined;
/**
* The side of the sidebar to collapse.
* @default "\"left\""
*/
side?: "left" | "right" | undefined;
ui?: { base?: any; } | undefined;
/**
* Class to apply when the link is exact active
*/
exactActiveClass?: string | undefined;
/**
* Pass the returned promise of `router.push()` to `document.startViewTransition()` if supported.
*/
viewTransition?: boolean | undefined;
autofocus?: Booleanish | undefined;
disabled?: boolean | undefined;
form?: string | undefined;
formaction?: string | undefined;
formenctype?: string | undefined;
formmethod?: string | undefined;
formnovalidate?: Booleanish | undefined;
formtarget?: string | undefined;
name?: string | undefined;
/**
* The type of the button when not a link.
*/
type?: "reset" | "submit" | "button" | undefined;
onClick?: ((event: MouseEvent) => void | Promise) | ((event: MouseEvent) => void | Promise)[] | undefined;
/**
* The element or component this component should render as when not a link.
*/
as?: any;
label?: string | undefined;
activeColor?: "error" | "neutral" | "primary" | "secondary" | "success" | "info" | "warning" | undefined;
activeVariant?: "ghost" | "solid" | "outline" | "soft" | "subtle" | "link" | undefined;
size?: "xs" | "sm" | "md" | "lg" | "xl" | undefined;
/**
* Render the button with equal padding on all sides.
*/
square?: boolean | undefined;
/**
* Render the button full width.
*/
block?: boolean | undefined;
/**
* Set loading state automatically based on the `@click` promise state
*/
loadingAuto?: boolean | undefined;
/**
* Display an icon based on the `leading` and `trailing` props.
*/
icon?: any;
/**
* Display an avatar on the left side.
*/
avatar?: AvatarProps | undefined;
/**
* When `true`, the icon will be displayed on the left side.
*/
leading?: boolean | undefined;
/**
* Display an icon on the left side.
*/
leadingIcon?: any;
/**
* When `true`, the icon will be displayed on the right side.
*/
trailing?: boolean | undefined;
/**
* Display an icon on the right side.
*/
trailingIcon?: any;
/**
* When `true`, the loading icon will be displayed.
*/
loading?: boolean | undefined;
/**
* The icon when the `loading` prop is `true`.
*/
loadingIcon?: any;
}
```
\> \[!NOTE]
\> See: https\://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attributes
\> This component also supports all native \`\