Skip to main content

Sidebar Component

The Sidebar 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

name
string
required
Unique identifier for the sidebar. Used to track which sidebar is currently open.
children
React.ReactNode
Content to display in the sidebar. Typically includes Sidebar.Header, Sidebar.Tabs, and custom content.
docked
boolean
Controls whether the sidebar is docked (pinned) or floating. When docked, the sidebar stays open and the canvas adjusts its width accordingly.
onDock
function
Callback fired when the dock button is clicked. Required if you want the sidebar to be user-dockable.
onStateChange
function
Callback fired when the sidebar opens, closes, or changes tabs.
className
string
Additional CSS class name(s) to apply to the sidebar container.

Subcomponents

Displays a header bar with close and optional dock buttons.
Props:
  • children (React.ReactNode) - Custom header content. If not provided, uses the sidebar name.
Features:
  • Automatically includes a close button
  • Shows a dock/undock button when onDock prop is provided to the parent Sidebar
  • Adapts styling based on docked state
Container for tab-based navigation within the sidebar.
Container for tab navigation buttons.
Individual tab button.
Props:
  • tab (string, required) - Unique identifier for the tab
  • children (React.ReactNode) - Tab label
  • icon (JSX.Element) - Optional icon to display
Container for tab panel content.
Props:
  • tab (string, required) - Must match a TabTrigger’s tab prop
  • children (React.ReactNode) - Tab panel content
Button to open the sidebar, typically placed in the UI toolbar.
Props:
  • name (string, required) - Must match the parent Sidebar’s name
  • tab (string) - Optional specific tab to open
  • icon (JSX.Element) - Icon to display in the trigger button
  • title (string) - Tooltip text for the button

Opening/Closing Sidebars

Sidebars are controlled through the Excalidraw app state:
You can also use the imperative API:

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
When a sidebar is floating (not docked):
  • 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 canFitSidebar property in EditorInterface determines 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 onStateChange callback 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

  1. Use meaningful names - Choose descriptive sidebar names that reflect their purpose
  2. Provide dock functionality - Allow users to dock sidebars for persistent access to tools
  3. Organize with tabs - Use tabs when you have multiple related panels
  4. Add trigger buttons - Make sidebars discoverable with visible trigger buttons
  5. Handle state properly - Use onStateChange to sync sidebar state with your app
  6. 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