GhostButton
GhostButton is a native action control with safe form behavior and a consumer-owned loading state. Import it from @ghostvue/themes for the default visual treatment, as every example on the ordinary path below does. Teams that bring their own styles can use the same contract from @ghostvue/vue; see Advanced: headless composition.
Action area
Primary, secondary, and destructive actions with a pending publish.
Overrides: none, showing the original example
Original source. Playground overrides are not applied here; use Copy props for the current settings.
<script setup lang="ts">
import { onBeforeUnmount, ref } from 'vue'
import { GhostButton, type GhostButtonSize } from '@ghostvue/themes'
/*
* Optional so the sample runs as-is; the docs props playground passes them.
* `size` applies to every action so the row keeps one rhythm. `loading`
* shows the publish action as pending, the same state a click produces.
*/
const { size = 'md', loading } = defineProps<{
size?: GhostButtonSize
loading?: boolean
}>()
const publishing = ref(false)
const status = ref('Draft saved at 10:42')
let publishTimer: ReturnType<typeof setTimeout> | undefined
function saveDraft(): void {
status.value = 'Draft saved at 10:43'
}
function discardDraft(): void {
status.value = 'Changes discarded'
}
// Stands in for a request. The app owns the pending state and the result.
function publish(): void {
publishing.value = true
status.value = 'Publishing to 3 channels…'
publishTimer = setTimeout(() => {
publishing.value = false
status.value = 'Published to 3 channels'
}, 1500)
}
onBeforeUnmount(() => {
clearTimeout(publishTimer)
})
</script>
<template>
<div class="publish-bar">
<div class="publish-bar__summary">
<span class="publish-bar__title">Quarterly product update</span>
<!-- Announces save, discard, and publish results politely. -->
<span class="publish-bar__status" role="status">{{ status }}</span>
</div>
<div class="publish-bar__actions">
<div class="publish-bar__discard">
<GhostButton variant="ghost" tone="danger" :size @click="discardDraft">
Discard changes
</GhostButton>
</div>
<div class="publish-bar__commit">
<GhostButton variant="outline" tone="neutral" :size @click="saveDraft">
Save draft
</GhostButton>
<GhostButton :size :loading="loading || publishing" @click="publish">
Publish
</GhostButton>
</div>
</div>
</div>
</template>
<style scoped>
/*
* The summary sits above the actions. The destructive action lives in its
* own group at the start so it is never the button next to the primary.
* Narrow previews stack the groups and give Save and Publish equal halves;
* wider ones put the groups on one row at opposite ends.
*/
.publish-bar {
display: grid;
gap: var(--ghost-space-stack-md);
}
.publish-bar__summary {
display: grid;
gap: var(--ghost-space-gap-xs);
min-inline-size: 0;
}
.publish-bar__title {
color: var(--ghost-text-default);
font-size: var(--ghost-type-size-md);
font-weight: var(--ghost-type-weight-semibold);
line-height: var(--ghost-type-line-snug);
}
.publish-bar__status {
color: var(--ghost-text-muted);
font-size: var(--ghost-type-size-sm);
line-height: var(--ghost-type-line-normal);
}
.publish-bar__actions {
display: grid;
gap: var(--ghost-space-gap-sm);
}
/* Save and Publish split the row evenly on narrow previews. */
.publish-bar__commit {
display: grid;
gap: var(--ghost-space-gap-sm);
grid-template-columns: 1fr 1fr;
}
@container ghost-demo (min-width: 26rem) {
.publish-bar__actions {
align-items: center;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.publish-bar__commit {
display: flex;
flex-wrap: wrap;
}
}
</style>
A save and publish bar shows the usual hierarchy. Publish is the one solid accent action. Save draft is a neutral outline. Discard changes is a ghost danger action, kept apart from the primary so it is not hit by mistake. Use the controls to change the size of every action or to preview the pending publish. While pending, the button keeps its width and focus, and the status line under the title is a polite live region that reports the result.
The row adapts to the preview width with @container ghost-demo. Narrow previews stack the summary above the actions and put the destructive action on its own row.
The default type is button, so placing the component in a form does not submit accidentally. Set type="submit" or type="reset" explicitly when that native behavior is intended.
Refresh and retry
A keyboard-triggered refresh keeps focus while pending and after a failure, then succeeds on retry.
<script setup lang="ts">
import { onBeforeUnmount, ref } from 'vue'
import { GhostButton } from '@ghostvue/themes'
type RefreshResult = 'idle' | 'pending' | 'failed' | 'updated'
const result = ref<RefreshResult>('idle')
const attempts = ref(0)
let requestTimer: ReturnType<typeof setTimeout> | undefined
const messages: Record<RefreshResult, string> = {
idle: 'Last checked 5 minutes ago.',
pending: 'Checking 3 deployments…',
failed: 'Could not reach the build server. Try again.',
updated: 'All 3 deployments are healthy.',
}
/*
* The application owns the request. `loading` only blocks activation while
* it runs: the button stays focused and keeps its name, so a keyboard user
* can retry from where they are once the failure clears the pending state.
* The first attempt fails so the example shows that recovery path.
*/
function refresh(): void {
attempts.value += 1
const fails = attempts.value === 1
result.value = 'pending'
requestTimer = setTimeout(() => {
result.value = fails ? 'failed' : 'updated'
}, 900)
}
onBeforeUnmount(() => {
clearTimeout(requestTimer)
})
</script>
<template>
<div class="refresh-status">
<div class="refresh-status__summary">
<span class="refresh-status__title">Production deployments</span>
<!-- A polite region announces each outcome without moving focus. -->
<span class="refresh-status__message" :data-result="result" role="status">
{{ messages[result] }}
</span>
</div>
<GhostButton
variant="outline"
tone="neutral"
:loading="result === 'pending'"
@click="refresh"
>
Refresh status
</GhostButton>
</div>
</template>
<style scoped>
.refresh-status {
display: grid;
gap: var(--ghost-space-gap-sm);
justify-items: start;
}
.refresh-status__summary {
display: grid;
gap: var(--ghost-space-gap-xs);
min-inline-size: 0;
}
.refresh-status__title {
color: var(--ghost-text-default);
font-size: var(--ghost-type-size-md);
font-weight: var(--ghost-type-weight-semibold);
line-height: var(--ghost-type-line-snug);
}
.refresh-status__message {
color: var(--ghost-text-muted);
font-size: var(--ghost-type-size-sm);
line-height: var(--ghost-type-line-normal);
}
.refresh-status__message[data-result='failed'] {
color: var(--ghost-text-danger);
}
@container ghost-demo (min-width: 30rem) {
.refresh-status {
align-items: center;
grid-template-columns: minmax(0, 1fr) auto;
}
}
</style>
Focus Refresh status and press Enter. The first request fails on purpose. While it runs, the button is busy: it blocks further activation but keeps focus and the same name. When the failure ends the loading state, focus is still on the button, so pressing Enter again retries from the same place. The status line beside the title is a polite role="status" region: it reports the pending check, the failure, and the recovered result without moving focus. The button does not announce results itself; the application owns the request and its message.
Loading and disabled actions
Pending actions keep their width and focus; disabled ones do not.
<script setup lang="ts">
import { GhostButton } from '@ghostvue/themes'
</script>
<template>
<!--
Loading keeps the label in the layout (only hidden), so the button keeps
its width and the row does not shift when an action becomes pending.
-->
<div class="button-states">
<GhostButton loading>Save changes</GhostButton>
<GhostButton variant="outline" tone="neutral" loading>
Export report
</GhostButton>
<GhostButton disabled>Unavailable action</GhostButton>
</div>
</template>
<style scoped>
.button-states {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: var(--ghost-space-gap-sm);
}
</style>
The themed wrapper hides the label while loading but keeps it in the layout, so a pending button stays the same size and nothing around it moves. Disabled buttons use desaturated action colors rather than a faded rest tone and leave the tab order. A loading button stays focusable and still draws the focus ring.
Loading adds aria-disabled="true", aria-busy="true", and data-state="loading". Activation is blocked while the native button remains focusable, so an action becoming pending does not discard the user's focus position. Slot content remains rendered so the button keeps the same accessible name. The application still owns the asynchronous operation, errors, cancellation, and any success or failure announcement.
Icon-only actions
Icon-only buttons require an accessible name. Hide decorative icon content from assistive technology with aria-hidden="true" (and focusable="false" on inline SVG).
Square treatment with an accessible name from aria-label.
<script setup lang="ts">
import { GhostButton } from '@ghostvue/themes'
</script>
<template>
<GhostButton icon-only aria-label="Close dialog">
<svg
data-part="icon"
aria-hidden="true"
viewBox="0 0 16 16"
width="16"
height="16"
>
<path
d="M3 3l10 10M13 3L3 13"
fill="none"
stroke="currentColor"
stroke-width="1.5"
/>
</svg>
</GhostButton>
</template>
With the themed wrapper, iconOnly is a prop. Text buttons normally receive their accessible name from the slot. You can also forward aria-labelledby or aria-describedby, or compose with GhostVisuallyHidden when the name should be translated as content.
GhostButton ships no icons and has no icon prop or icon slot. Put your own icon component or SVG in the default slot and add data-part="icon" so the themed wrapper sizes it with --ghost-action-icon-size; it inherits the button color through currentColor. A consumer element with data-part="loading-indicator" replaces the themed default loading ring. See ADR 0013: Icon strategy and icons in the default theme.
Variants, tones, and sizes
Visual props on the @ghostvue/themes wrapper.
Overrides: none, showing the original example
Original source. Playground overrides are not applied here; use Copy props for the current settings.
<script setup lang="ts">
import { ref } from 'vue'
import {
GhostButton,
type GhostButtonSize,
type GhostButtonTone,
type GhostButtonVariant,
} from '@ghostvue/themes'
/*
* Optional so the sample runs as-is; the docs props playground passes them
* to try other treatments. The defaults are what this sample renders.
*/
const {
size = 'md',
tone = 'danger',
variant = 'outline',
} = defineProps<{
size?: GhostButtonSize
tone?: GhostButtonTone
variant?: GhostButtonVariant
}>()
const saving = ref(false)
</script>
<template>
<GhostButton :variant :tone :size :loading="saving">Delete</GhostButton>
</template>
Importing the themed component loads the default stylesheet. Visual props exist only on this wrapper; see its generated reference.
Themed size, padding, gap, radius, and type come from density, spacing, and roundness tokens. A medium button at comfortable density is 36px tall, with a 6px radius at --ghost-roundness: 1; compact density makes it 32px and spacious 40px. Compact and spacious nest through data-ghost-density; coarse pointers floor heights to 44px. See density, type, and roundness.
Solid accent (the default), neutral, and danger fills use --ghost-gradient-action-* (a restrained single-hue fill in default, or expressive OKLCH gradients in vibrant) with an inset hairline bevel and elevation-1 shadow. Hover, press, selected, and dragged are state-layer overlays (--ghost-state-layer-*) mixed onto the current tone, so they work in every mode without per-tone hover colors. There are no per-component tokens.
State matrix
Headless GhostButton has no pressed model. The theme still styles aria-pressed and aria-grabbed when a consumer sets them, so later toggle and drag controls can reuse the same overlay tokens.
| State | How it appears | Overlay | Motion | Notes |
|---|---|---|---|---|
| Rest | Default | none | — | Solid: fill, inner hairline bevel, elevation 1. |
| Hover | :hover | --ghost-state-layer-hover | color | Not applied while disabled or loading. |
| Focus-visible | :focus-visible | two-tone ring | ring entrance (--ghost-focus-ring-duration) | Inner --ghost-focus-ring-contrast, outer --ghost-focus-ring-color. Instant under reduced motion. |
| Hover + focus-visible | both | hover overlay + ring | ring entrance | Overlay and ring compose. |
| Pressed | :active | --ghost-state-layer-press | scale --ghost-motion-press-scale (0.98), elevation 0, snappy spring release | No scale under reduced motion; color overlay stays. |
| Pressed + focus | both | press overlay + ring | press + ring | |
| Loading | loading | none | spinner | Fixed width, aria-busy, focusable. Focus-visible still draws the ring. |
| Loading + focus | both | ring | spinner + ring | Activation stays cancelled. |
| Disabled | disabled | none | none | Desaturated --ghost-action-disabled-* colors, cursor: not-allowed. Not a low-opacity rest tone. |
| Selected | aria-pressed="true" | --ghost-state-layer-selected | — | CSS hook only; not a headless API. |
| Dragged | aria-grabbed="true" | --ghost-state-layer-dragged | — | CSS hook for later drag controls. |
Docs and visual snapshots freeze hover/press/focus with data-visual-state. That attribute is not a component prop.
See the default theme guide for tokens and overrides.
Accessibility and environment behavior
Enabled buttons retain native Enter, Space, pointer, touch, and focus behavior. Disabled buttons use native disabled semantics; loading buttons remain focusable while activation is suppressed. The themed wrapper draws the focus ring and floors heights to 44px on coarse pointers; without it, see Advanced: headless composition.
SSR markup is deterministic from props and slot content, and setup does not read browser globals. No listeners, timers, or observers require cleanup.
See the approved GhostButton specification for the complete behavior and compatibility contract.
Advanced: headless composition
Use this section when your team brings its own design system and wants the button contract without the default visual treatment. Import from @ghostvue/vue; nothing here is needed for a themed app.
You can also import the stylesheet and wrap unstyled buttons in .ghost-theme when you want a region of headless components to pick up the defaults.
Basic use
Native action control. The default type is button.
<script setup lang="ts">
import { ref } from 'vue'
import { GhostButton } from '@ghostvue/vue'
const saved = ref(false)
function save(): void {
saved.value = true
}
</script>
<template>
<GhostButton @click="save">Save changes</GhostButton>
</template>
The unstyled component renders the same native <button> with no visual treatment. You own visible focus indication, contrast, and touch target size. For an icon-only unstyled button, set data-icon-only yourself; the themed iconOnly prop sets the same hook.
Composable
Same contract as GhostButton, applied to a native host.
<script setup lang="ts">
import { onBeforeUnmount, ref } from 'vue'
import { useGhostButton } from '@ghostvue/vue'
const saving = ref(false)
const { rootProps } = useGhostButton({ loading: saving })
let resetTimer: ReturnType<typeof setTimeout> | undefined
function save(): void {
saving.value = true
resetTimer = setTimeout(() => {
saving.value = false
}, 1200)
}
onBeforeUnmount(() => {
clearTimeout(resetTimer)
})
</script>
<template>
<button v-bind="rootProps" @click="save">Save</button>
</template>
useGhostButton applies the same contract to a native host element you render yourself.
Component refs
Template refs expose element, focus, and blur.
<script setup lang="ts">
import { useTemplateRef } from 'vue'
import { GhostButton, type GhostButtonExposed } from '@ghostvue/vue'
const saveButton = useTemplateRef<GhostButtonExposed>('saveButton')
function returnFocus(): void {
saveButton.value?.focus()
}
</script>
<template>
<GhostButton ref="saveButton">Save changes</GhostButton>
<button type="button" @click="returnFocus">Move focus to save</button>
</template>
The ref exposes three members, and the themed wrapper exposes the same ones:
element: the native button, ornullbefore mount and after unmount.focus(options?): focuses the button when it is mounted and enabled.blur(): removes focus from the button.
Before mount and after unmount, the methods are safe no-ops.
Styling
The unstyled component renders one native button with class ghost-button and data-part="root". There is no internal wrapper to target.
While pending, the button sets data-state="loading". While disabled and not loading, it sets data-state="disabled".
.ghost-button[data-state='loading'] {
/* Applies only while the action is pending. */
}These hooks are the stable styling API (see the styling hook contract), so utility CSS can target them directly. With Tailwind CSS data variants:
<template>
<GhostButton
:loading="saving"
class="rounded-md bg-blue-600 px-3 py-2 text-white data-[state=disabled]:opacity-50 data-[state=loading]:cursor-progress"
>
Save
</GhostButton>
</template>The themed wrapper adds a data attribute for each visual prop, such as data-variant and data-size. The themed props below name each one, and the generated reference lists their values.
API
See the generated component references for props, emits, slots, exposed members, styling hooks, CSS variables, and executable examples.
| Prop | Type | Default | Description |
|---|---|---|---|
disabled | boolean | false | Applies native disabled semantics, prevents activation, and removes the button from sequential focus order. |
loading | boolean | false | Consumer-owned pending state. Prevents activation while remaining focusable, sets aria-disabled and aria-busy, and preserves slot content so the accessible name does not change. |
type | GhostButtonType | "button" | Native button behavior. Defaults to button so a control inside a form does not submit unless the consumer opts in. |
| Slot | Slot props | Description |
|---|---|---|
default | — | Button label and optional decorative content such as an icon. Icon-only use requires aria-label, aria-labelledby, or hidden text. |
@ghostvue/themes adds these to the headless GhostButton API, which it forwards:
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'solid' | 'soft' | 'outline' | 'ghost' | "solid" | Visual treatment. The default omits data-variant so CSS can treat a missing hook as solid. |
tone | 'accent' | 'neutral' | 'danger' | "accent" | Semantic color intent, independent of variant. The default omits data-tone. |
size | 'sm' | 'md' | 'lg' | "md" | Control size. The default omits data-size so CSS can treat a missing hook as md. |
block | boolean | false | Stretch to the available inline size via data-block. |
iconOnly | boolean | false | Square icon-button treatment via data-icon-only. Still requires an accessible name. |
interactive | 'spotlight' | — | Opt-in pointer spotlight. Off by default. Sets data-interactive and tracks on data-interactive-state so loading/disabled keep data-state. |
All native button attributes and event listeners fall through to the root button. The default slot is the only content slot. The component does not generate an id; pass one as a native attribute when you need it. There is no toggle/pressed model.