Button
A pressable button built on React Aria.
Installation
npx shadcn@latest add @oakoss/buttonUsage
import { Button } from '#/components/ui/inputs/button';
<Button intent="success" variant="soft">
Save
</Button>;Examples
Variants and intents
variant sets the look (solid, soft, outline, ghost, link) and
intent sets the color (primary, neutral, destructive, success,
warning, info). Every look works with every intent.
Custom colors
className can set the --btn-* variables that every look reads. Set them
rather than overriding bg-*, which hover and press would replace. See
CSS variables for each one.
Icon-only
size="icon" (or icon-sm, icon-lg) requires an aria-label or
aria-labelledby, since there's no text to name the button.
Pending
isPending keeps the button's width and focus, blocks presses, and shows a
Spinner. Set pendingLabel to translate the
spinner's name (see
Localization).
Links
buttonStyles styles a link as a button; it stays a link. Here it styles a
TanStack Router link wrapped with createLink.
Accessibility
React Aria renders a native <button> and handles:
- Press: one event for mouse, touch, pen and keyboard, so
onPressfires once however the button is used. - Focus: the focus outline shows for keyboard focus only
(
data-focus-visible). - Pending: the button stays focusable but ignores presses, and screen readers announce the change while it has focus.
This component adds a 44×44 pointer target around every size, and keeps a
visible border in Windows High Contrast, where a disabled button, or a link
styled with buttonStyles, takes the system's disabled color like a native
one. Icon-only sizes require a name in the type.
A pressed button shrinks slightly. React Aria holds a dialog, popover, menu or
select trigger pressed while it's open, so a button with aria-expanded stays
full size then, and its popup stays where it was placed. A trigger you build
yourself sets aria-expanded to get the same.
| Key | Action |
|---|---|
Space | Presses the button |
Enter | Presses the button |
Follows the WAI-ARIA button pattern.
API
Button
Extends React Aria's Button.
Props
Also accepts all React Aria Button props.
Data attributes
| Attribute | Present when |
|---|---|
data-slot | button, unless a wrapper passes its own |
data-variant | Always; the look |
data-intent | Always; the color |
data-size | Always; the size |
data-hovered | A pointer hovers it |
data-pressed | It's being pressed, or its popup is open |
data-focused | It has focus |
data-focus-visible | It has keyboard focus |
data-disabled | isDisabled is set |
data-pending | isPending is set |
CSS variables
| Variable | Sets |
|---|---|
--btn-bg | The solid fill |
--btn-hover | The solid fill on hover and press |
--btn-fg | Text on the solid fill |
--btn-subtle | The soft fill |
--btn-border | The outline border |
--btn-text | Text, and the hover and press tint, for other looks |