Skip to main content
← All Demos

Button

Button triggers user actions such as submit, confirm, cancel, or state toggles.

1. Basic Button

A standard button that responds to click and keyboard activation (Enter/Space).

Keyboard: Tab to focus → Enter or Space to activate
<Button onClick={() => alert('Clicked')}>
  Click me
</Button>

2. Disabled Button

Disabled buttons cannot be activated. Screen readers announce the disabled state. Focus should skip the disabled button when tabbing.

Expected: Tab should skip the disabled button and focus the enabled one.
<Button disabled>
  Disabled button
</Button>

3. Loading State

Loading button uses aria-busy="true" and aria-live="polite" to announce loading state to screen readers.

Screen reader: Should announce busy state when loading starts.
<Button isLoading={isLoading} onClick={simulateLoading}>
  {isLoading ? 'Saving…' : 'Save changes'}
</Button>

4. Toggle Button

Controlled toggle where parent manages the pressed state.

const [isPressed, setIsPressed] = useState(false);

<Button isPressed={isPressed} onPressedChange={(pressed) => setIsPressed(pressed)}>
  {isPressed ? 'Notifications On' : 'Notifications Off'}
</Button>

5. Polymorphic Rendering (as prop)

Button can render as different HTML elements. When rendered as non-button elements, it adds role="button", tabIndex, and keyboard handlers.

Rendered as <a>Rendered as <span>
Screen reader: All three should be announced as buttons regardless of underlying element.
<Button>Native button</Button>

<Button as='a' href='#polymorphic-link'>
  Rendered as a
</Button>

<Button as='span'>Rendered as span</Button>

6. Auto Focus

This button receives focus automatically on mount. Useful for modal dialogs or important CTAs.

<Button autoFocus>
  I should be focused on page load
</Button>
← All Demos