Skip to content

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 ​

Publish action bar

Primary, secondary, and destructive actions with a pending publish.

Quarterly product updateDraft saved at 10:42

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 ​

Refresh with a failed attempt

A keyboard-triggered refresh keeps focus while pending and after a failure, then succeeds on retry.

Production deploymentsLast checked 5 minutes ago.

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 ​

Loading and disabled

Pending actions keep their width and focus; disabled ones do not.

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).

Icon only

Square treatment with an accessible name from aria-label.

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 ​

Themed

Visual props on the @ghostvue/themes wrapper.

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.

StateHow it appearsOverlayMotionNotes
RestDefaultnone—Solid: fill, inner hairline bevel, elevation 1.
Hover:hover--ghost-state-layer-hovercolorNot applied while disabled or loading.
Focus-visible:focus-visibletwo-tone ringring entrance (--ghost-focus-ring-duration)Inner --ghost-focus-ring-contrast, outer --ghost-focus-ring-color. Instant under reduced motion.
Hover + focus-visiblebothhover overlay + ringring entranceOverlay and ring compose.
Pressed:active--ghost-state-layer-pressscale --ghost-motion-press-scale (0.98), elevation 0, snappy spring releaseNo scale under reduced motion; color overlay stays.
Pressed + focusbothpress overlay + ringpress + ring
LoadingloadingnonespinnerFixed width, aria-busy, focusable. Focus-visible still draws the ring.
Loading + focusbothringspinner + ringActivation stays cancelled.
DisableddisablednonenoneDesaturated --ghost-action-disabled-* colors, cursor: not-allowed. Not a low-opacity rest tone.
Selectedaria-pressed="true"--ghost-state-layer-selected—CSS hook only; not a headless API.
Draggedaria-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 ​

Basic Headless

Native action control. The default type is button.

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 ​

Composable Headless

Same contract as GhostButton, applied to a native host.

useGhostButton applies the same contract to a native host element you render yourself.

Component refs ​

Component ref Headless

Template refs expose element, focus, and blur.

The ref exposes three members, and the themed wrapper exposes the same ones:

  • element: the native button, or null before 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".

css
.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:

vue
<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.

PropTypeDefaultDescription
disabledbooleanfalseApplies native disabled semantics, prevents activation, and removes the button from sequential focus order.
loadingbooleanfalseConsumer-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.
typeGhostButtonType"button"Native button behavior. Defaults to button so a control inside a form does not submit unless the consumer opts in.
SlotSlot propsDescription
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:

PropTypeDefaultDescription
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.
blockbooleanfalseStretch to the available inline size via data-block.
iconOnlybooleanfalseSquare 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.