COMPONENT

Button

Version: 1.1.0
Size: 38.29 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.
Example
import { Button } from '@sprocketui/react';

export default function App() {
return <Button>Initialize</Button>;
}

Installation

terminal

Anatomy

Import from collection package and use Root component.

import { Button } from "@sprocketui/react";
 
export default () => (
  <Button.Root>
    Click Me
  </Button.Root>
);

You can also import pre-defined aliases for when there are namespace issues.

import { SprocketButton } from "@sprocketui/react";
 
export default () => (
  <SprocketButton.Root>
    Click Me
  </SprocketButton.Root>
);

States

{/* Loading state */}
<Button isPending>Loading...</Button>
 
{/* Disabled state */}
<Button isDisabled>Disabled</Button>

API Reference

Root

Contains the content for the button.

Props(6)
NameTypeDescription
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.
childrenReactNodeThe content to display inside the button.
classNamestringAdditional CSS classes to apply to the button.
styleCSSPropertiesInline styles to apply to the button.
Events(10)
NameTypeDescription
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)
NameTypeDescription
slotstringA slot name for the component. Slots allow the component to receive props from a parent component.
Accessibility(10)
NameTypeDescription
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-expandedUnionTypeiIndicates whether the element, or another grouping element it controls, is currently expanded or collapsed.
aria-haspopupUnionTypeiIndicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an element.
aria-pressedUnionTypeiIndicates the current "pressed" state of toggle buttons.
Data attributes(6)
NameTypeDescription
[data-hover]boolean
[data-pressed]boolean
[data-focused]boolean
[data-focused-visible]boolean
[data-disabled]boolean
[data-pending]boolean

Accessibility

This component is based on the native button element and supports all of its props. It handles press interactions across mouse, touch, pen, and keyboard, normalizing behavior across browsers and platforms. It includes support for pressed states, disabled states, and accessible labelling via ARIA attributes.

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 March 11, 2026

Components