Button Components
Excalidraw provides several button components that follow the editor’s design system. These components ensure visual consistency and provide common button patterns used throughout the editor.Button
The mainButton component is a generic button that accepts all standard HTML button props and adds Excalidraw styling.
Basic Usage
Props
Callback function executed when the button is clicked.
Whether the button is in an active/selected state. Adds visual styling to indicate selection.
The button content (text, icons, or other elements).
The HTML button type attribute.
Additional CSS class names to apply to the button.
All standard HTML button attributes are supported (disabled, title, aria-label, etc.).
Styling
The Button component uses the.excalidraw-button CSS class:
ButtonIcon
A specialized button component for icon-only buttons, commonly used in toolbars.Basic Usage
Props
The icon element to display in the button.
Tooltip text shown on hover (also used for accessibility).
Callback function when the button is clicked.
Whether the button is in an active state (e.g., tool currently selected).
When true, applies standalone styling that may be better suited for isolated buttons outside of toolbars.
Additional CSS class names to apply.
Test identifier for automated testing (sets
data-testid attribute).Inline styles to apply to the button.
Complete Examples
Accessibility
Both button components follow accessibility best practices:Button
- Native
<button>element for proper keyboard navigation - Accepts
aria-labelfor screen readers - Responds to Enter and Space keys
:focusstyles for keyboard users
ButtonIcon
- Uses
titleprop for tooltip andaria-label - Icon-only buttons always have descriptive titles
- Active state is communicated visually and semantically
- Supports keyboard navigation
Best Practices
Styling Patterns
Primary Action Button
Danger/Destructive Button
Ghost Button (Minimal)
Icon Button with Badge
See Also
- Excalidraw - Main component documentation
- MainMenu - Using buttons in menus
- Sidebar - Using buttons in sidebars
- Footer - Using buttons in footer