Skip to main content

Starwind UI v3.7 is here with stable Vue and Svelte, the new Chart component, and full RTL support. Read the release notes

Button Primitive

Use Button to run an action or submit a form. It behaves like a native button and can keep a disabled button in the tab order when you need to explain why it is disabled.

Your draft is ready.

Anatomy

Use the Astro primitive adapter to render Button anatomy with the Runtime wiring included.

---
import { Button } from "@starwind-ui/astro/button";
---
<Button.Root type="button" focusableWhenDisabled={true}>Button</Button.Root>

Astro, React, Vue, and Svelte components use the same underlying interactions. Each framework has its own way to read and update state. See the examples and your installed package’s types for the available props and events. Plain HTML uses DOM events and Runtime methods.

API Reference

Root

The native button. It owns a Runtime instance only when focusableWhenDisabled opts into mutable focusable-disabled behavior.

Default element
button
Discovery hook
data-sw-button
Role
-

Props

Prop Type Default Toggle
disabled boolean false
Description
Disables the button natively unless focusableWhenDisabled keeps it focusable through Runtime.
Kind
option
Targets
-
Full type
boolean
focusableWhenDisabled boolean false
Description
Opts the native button into Runtime so disabled state can suppress activation without removing focusability.
Kind
option
Targets
-
Full type
boolean
type button | submit | reset -
Description
Sets the native button type; adapters default an omitted value to button.
Kind
attribute
Targets
root
Full type
button | submit | reset

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-button - Runtime discovery hook for an opted-in native button.
Metadata
Attribute Value Description
data-focusable-when-disabled - Opts the native button into focusable-disabled Runtime behavior.
data-disabled - Present while an opted-in button is disabled through Runtime.

Runtime API

Factory
createButton
Import
@starwind-ui/runtime/button
Root hook
root data-sw-button
Option props
disabled

Option Lifecycles

OptionLifecycle
disabledsetter-backed

Runtime Setters

Method Target Description
setDisabled prop: disabled Updates the opted-in button between enabled and focusable-disabled state without replacing it.
Component Relationship
Button Mixed conditional

Changelog

View version history v1.0.4 8 releases

v1.0.4

  • In Vue, this component now needs Vue 3.5.21 or newer.

v1.0.3

  • In Astro, an attribute that you set on a Button part now wins over the part's own default for the same attribute, such as `role` or `aria-label`.
  • In Svelte, the props from a trigger `child` snippet now spread onto a Styled Button without a type error.

v1.0.2

  • Internal maintenance. No change to how the component behaves.
  • Updated the shared setup file included with the Astro Primitive. Its public API and behavior are unchanged.

v1.0.1

  • Removed old comments from the Vue Primitive files that said the code was internal and not for release. The CLI also removes the blank line that these comments left in the Vue Primitive `index.ts` files that it copies into your project.

v1.0.0

  • This Primitive is now stable at version `1.0.0`. Its API and behavior stay the same as in the previous release.

v0.1.2

  • The React Primitive files that the CLI copies into your project are now marked with `"use client"`, so they stay client components in React server frameworks.

v0.1.1

  • Button now adds its script only to a native `<button>` that sets `focusableWhenDisabled`. In Astro and React, a `focusableWhenDisabled` button can now change between enabled and disabled and keep focus.

v0.1.0

  • First release. Starwind Runtime handles clicks and keys on a disabled button. The button still renders as a native button or link.