Skip to main content

Sidebar

The editor comes with a default sidebar on the right in LTR (Left to Right) mode which contains the library. You can also add your own custom sidebar(s) by rendering this component as a child of <Excalidraw>.

Props

PropTypeRequiredDescription
namestringYesSidebar name that uniquely identifies it.
childrenReact.ReactNodeYesContent you want to render inside the sidebar.
onStateChange(state: AppState["openSidebar"]) => voidNoInvoked on open/close or tab change. No need to act on this event, as the editor manages the sidebar open state on its own.
onDock(docked: boolean) => voidNoInvoked when the user toggles the dock button. Passed the current docked state.
dockedbooleanNoIndicates whether the sidebar is docked. By default, the sidebar is undocked. If passed, the docking becomes controlled.
classNamestringNo
styleReact.CSSPropertiesNo

At minimum, each sidebar needs to have a unique name prop, and render some content inside it, which can be either composed from the exported sidebar sub-components, or custom elements.

Unless docked={true} is passed, the sidebar will close when the user clicks outside of it. It can also be closed using the close button in the header, if you render the <Sidebar.Header> component.

Further, if the sidebader doesn't comfortably fit in the editor, it won't be dockable. To decide the breakpoint for docking you can use UIOptions.dockedSidebarBreakpoint.

To make your sidebar user-dockable, you need to supply props.docked (current docked state) alongside props.onDock callback (to listen for and handle docked state changes). The component doesn't track local state for the docked prop, so you need to manage it yourself.

Sidebar.Header

PropTypeRequiredDescription
childrenReact.ReactNodeNoContent you want to render inside the sidebar header next to the close / dock buttons.
classNamestringNo

Renders a sidebar header which contains a close button, and a dock button (when applicable). You can also render custom content in addition.

Can be nested inside specific tabs, or rendered as direct child of <Sidebar> for the whole sidebar component.

Sidebar.Tabs

PropTypeRequiredDescription
childrenReact.ReactNodeNoContainer for individual tabs.

Sidebar may contain inner tabs. Each <Sidebar.Tab> must be rendered inside this <Sidebar.Tabs> container component.

Sidebar.Tab

PropTypeRequiredDescription
tabstringYesUnique tab name.
childrenReact.ReactNodeNoTab content.

Content of a given sidebar tab. It must be rendered inside <Sidebar.Tabs>.

Sidebar.TabTriggers

PropTypeRequiredDescription
childrenReact.ReactNodeNoContainer for individual tab triggers.

Container component for tab trigger buttons to switch between tabs.

Sidebar.TabTrigger

PropTypeRequiredDescription
tabstringYesTab name to toggle.
childrenReact.ReactNodeNoTab trigger content, such as a label.

A given tab trigger button that switches to a given sidebar tab. It must be rendered inside <Sidebar.TabTriggers>.

Sidebar.Trigger

PropTypeRequiredDescription
namestringYesSidebar name the trigger will control.
tabstringNoOptional tab to open.
onToggle(open: boolean) => voidNoCallback invoked on toggle.
titlestringNoA11y title.
childrenReact.ReactNodeNoContent (usually label) you want to render inside the button.
iconJSX.ElementNoTrigger icon if any.
classNamestringNo
styleReact.CSSPropertiesNo

You can use the ref.toggleSidebar({ name: "custom" }) api to control the sidebar, but we export a trigger button to make UI use cases easier.

Example

Live Editor
Result
Loading...