Sidebar Component
TheSidebar component allows you to add custom side panels to the Excalidraw editor. Sidebars can be docked or floating, contain multiple tabs, and provide a flexible way to extend the editor with custom functionality.
Basic Usage
Props
Unique identifier for the sidebar. Used to track which sidebar is currently open.
Content to display in the sidebar. Typically includes
Sidebar.Header, Sidebar.Tabs, and custom content.Controls whether the sidebar is docked (pinned) or floating. When docked, the sidebar stays open and the canvas adjusts its width accordingly.
Callback fired when the dock button is clicked. Required if you want the sidebar to be user-dockable.
Callback fired when the sidebar opens, closes, or changes tabs.
Additional CSS class name(s) to apply to the sidebar container.
Subcomponents
Sidebar.Header
Displays a header bar with close and optional dock buttons.children(React.ReactNode) - Custom header content. If not provided, uses the sidebar name.
- Automatically includes a close button
- Shows a dock/undock button when
onDockprop is provided to the parent Sidebar - Adapts styling based on docked state
Sidebar.Tabs
Container for tab-based navigation within the sidebar.Sidebar.TabTriggers
Container for tab navigation buttons.Sidebar.TabTrigger
Individual tab button.tab(string, required) - Unique identifier for the tabchildren(React.ReactNode) - Tab labelicon(JSX.Element) - Optional icon to display
Sidebar.Tab
Container for tab panel content.tab(string, required) - Must match aTabTrigger’s tab propchildren(React.ReactNode) - Tab panel content
Sidebar.Trigger
Button to open the sidebar, typically placed in the UI toolbar.name(string, required) - Must match the parent Sidebar’s nametab(string) - Optional specific tab to openicon(JSX.Element) - Icon to display in the trigger buttontitle(string) - Tooltip text for the button
Opening/Closing Sidebars
Sidebars are controlled through the Excalidraw app state:Complete Examples
Behavior
Docking
When a sidebar is docked:- It remains open and pinned to the side
- The canvas adjusts its width to accommodate the sidebar
- The dock button in the header shows an “undock” icon
- The sidebar persists even when clicking outside
- It appears as an overlay on top of the canvas
- Clicking outside the sidebar closes it
- Pressing ESC closes it
- The canvas maintains its full width
Responsive Design
The sidebar automatically adapts to different screen sizes:- On desktop: Can be docked or floating
- On tablet/mobile: Always floating, cannot be docked
- The
canFitSidebarproperty inEditorInterfacedetermines if docking is available
Multiple Sidebars
Only one sidebar can be open at a time. When a new sidebar is opened:- The previous sidebar closes automatically
- The
onStateChangecallback is fired for both sidebars - Sidebar state is tracked in
appState.openSidebar
Styling
The Sidebar uses CSS classes that can be targeted for custom styling:Best Practices
- Use meaningful names - Choose descriptive sidebar names that reflect their purpose
- Provide dock functionality - Allow users to dock sidebars for persistent access to tools
- Organize with tabs - Use tabs when you have multiple related panels
- Add trigger buttons - Make sidebars discoverable with visible trigger buttons
- Handle state properly - Use
onStateChangeto sync sidebar state with your app - Consider mobile - Test your sidebar on different screen sizes
See Also
- Excalidraw - Main component documentation
- MainMenu - Main menu customization
- Button - Button components for sidebar UI