Skip to main content

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 main Button component is a generic button that accepts all standard HTML button props and adds Excalidraw styling.

Basic Usage

Props

function
required
Callback function executed when the button is clicked.
boolean
Whether the button is in an active/selected state. Adds visual styling to indicate selection.
React.ReactNode
required
The button content (text, icons, or other elements).
'button' | 'submit' | 'reset'
default:"'button'"
The HTML button type attribute.
string
Additional CSS class names to apply to the button.
HTMLButtonElement props
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

JSX.Element
required
The icon element to display in the button.
string
required
Tooltip text shown on hover (also used for accessibility).
function
required
Callback function when the button is clicked.
boolean
Whether the button is in an active state (e.g., tool currently selected).
boolean
When true, applies standalone styling that may be better suited for isolated buttons outside of toolbars.
string
Additional CSS class names to apply.
string
Test identifier for automated testing (sets data-testid attribute).
React.CSSProperties
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-label for screen readers
  • Responds to Enter and Space keys
  • :focus styles for keyboard users

ButtonIcon

  • Uses title prop for tooltip and aria-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