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>Use the React primitive adapter when Button state participates in React rendering.
import { Button } from "@starwind-ui/react/button";
export function Example() { return ( <Button.Root type="button" focusableWhenDisabled={true}>Button</Button.Root> );}Use the Vue components to build Button.
<script setup lang="ts">import Button from "@starwind-ui/vue/button";</script>
<template> <Button.Root type="button" :focusableWhenDisabled="true">Button</Button.Root></template>Use the Svelte components to build Button.
<script lang="ts"> import { Button } from "@starwind-ui/svelte/button";</script>
<Button.Root type="button" focusableWhenDisabled={true}>Button</Button.Root>Render the Button data-sw-* contract yourself, then initialize createButton.
<button data-sw-button type="button" data-focusable-when-disabled="">Button</button>
<script type="module"> import { createButton } from "@starwind-ui/runtime/button";
const root = document.querySelector("[data-sw-button]"); if (root instanceof HTMLButtonElement) { const instance = createButton(root); root.addEventListener("click", () => instance.setDisabled(true), { once: true }); }</script>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
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
Metadata
Runtime API
- Factory
createButton- Import
@starwind-ui/runtime/button- Root hook
- root
data-sw-button - Option props
- disabled
Option Lifecycles
| Option | Lifecycle |
|---|---|
| disabled | setter-backed |
Runtime Setters
Related Styled Components
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.