COMPONENT

Button

Version: 1.1.0
Size: 40.39 kB

A customizable button component with multiple variants and states.

Features
  • Supports keyboard activation with Enter and Space keys.
  • Automatic aria-disabled handling when disabled.
  • Polymorphic component rendering via Necto <Primitive />.
  • Focus visible styles for keyboard navigation.
  • Loading state with automatic disabled behavior.
Installation
Preview
button.tsx
import { Button } from '@sprocketui/react';

function Example() {
  return (
    <Button
      variant="primary"
      className="px-4 py-2 rounded-lg"
      onPress={() => alert('Clicked!')}
    >
      Click me
    </Button>
  );
}

Anatomy

Buttons consist of a clickable area usually containing a textual label or an icon that users can click to perform an action. In addition, keyboard users may activate buttons using the Space or Enter keys.

States

{/* Loading state */}
<Button isPending>Loading...</Button>
 
{/* Disabled state */}
<Button isDisabled>Disabled</Button>
API Reference
Props(8)
NameTypeDefaultDescription
isPendingbooleanWhether the button is in a pending state. This disables press and hover events while retaining focusability, and announces the pending state to screen readers.
isDisabledbooleanWhether the button is disabled. This prevents the user from interacting with the button.
autoFocusbooleanWhether the element should receive focus on render.
variant'primary' | 'secondary' | 'outline' | 'ghost' | 'danger''primary'The visual style variant of the button.
size'sm' | 'md' | 'lg''md'The size of the button.
childrenReactNodeThe content to display inside the button.
classNamestringAdditional CSS classes to apply to the button.
styleCSSPropertiesInline styles to apply to the button.
Events(10)
NameTypeDefaultDescription
onPress(e: PressEvent) => voidHandler that is called when the press is released over the target.
onPressStart(e: PressEvent) => voidHandler that is called when a press interaction starts.
onPressEnd(e: PressEvent) => voidHandler that is called when a press interaction ends, either over the target or when the pointer leaves the target.
onPressChange(isPressed: boolean) => voidHandler that is called when the press state changes.
onPressUp(e: PressEvent) => voidHandler that is called when a press is released over the target, regardless of whether it started on the target or not.
onFocus(e: FocusEvent) => voidHandler that is called when the element receives focus.
onBlur(e: FocusEvent) => voidHandler that is called when the element loses focus.
onFocusChange(isFocused: boolean) => voidHandler that is called when the element's focus status changes.
onKeyDown(e: KeyboardEvent) => voidHandler that is called when a key is pressed.
onKeyUp(e: KeyboardEvent) => voidHandler that is called when a key is released.
Layout(1)
NameTypeDefaultDescription
slotstringA slot name for the component. Slots allow the component to receive props from a parent component.
Accessibility(10)
NameTypeDefaultDescription
idstringThe element's unique identifier.
excludeFromTabOrderbooleanWhether to exclude the element from the sequential tab order. If true, the element will not be focusable via the keyboard by tabbing.
aria-labelstringDefines a string value that labels the current element.
aria-labelledbystringIdentifies the element (or elements) that labels the current element.
aria-describedbystringIdentifies the element (or elements) that describes the object.
aria-detailsstringIdentifies the element (or elements) that provide a detailed, extended description for the object.
aria-controlsstringIdentifies the element (or elements) whose contents or presence are controlled by the current element.
aria-expandedboolean | "true" | "false"Indicates whether the element, or another grouping element it controls, is currently expanded or collapsed.
aria-haspopupboolean | "menu" | "listbox" | "tree" | "grid" | "dialog"Indicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an element.
aria-pressedboolean | "true" | "false" | "mixed"Indicates the current "pressed" state of toggle buttons.

Accessibility

The Button component follows WAI-ARIA best practices:

  • Uses semantic <button> element
  • Supports all ARIA attributes for enhanced accessibility
  • Disabled and pending states are properly communicated to assistive technologies
  • Keyboard navigation works as expected (Space/Enter to activate)
  • Focus management is handled automatically

Styling

The Button component is built with Tailwind CSS and supports full customization through the className prop. You can extend or override any of the default styles.

Last updated on December 1, 2025

Components

Form