---
title: "Build on the composables"
description: "Build your own markup on the composables the packaged UI runs on: state, actions and bindings that carry the accessibility attributes and handlers, the helpers from #backend/a11y, and any UI library around them."
canonical_url: "https://nuxt-backend.dev/docs/build/ui/customize/headless"
---
# Build on the composables

> Build your own markup on the composables the packaged UI runs on: state, actions and bindings that carry the accessibility attributes and handlers, the helpers from #backend/a11y, and any UI library around them.

Version: nuxt-backend 0.6.x · Tab: Build · Kind: how-to · Status: stable

Every page: [llms.txt](https://nuxt-backend.dev/llms.txt) · Skill for coding agents: [nuxt-backend](https://nuxt-backend.dev/.well-known/skills/nuxt-backend/SKILL.md)

Commands use npm; use your project's package manager.

- [Source](https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/a11y.ts)

Write a sign-in form in your own markup, with your design system's inputs, and keep every behaviour of the packaged one: the steps, the refusals, the passkey prompt, the focus moves and the announcements. Every packaged component runs on a composable you can call yourself. Each returns its state, its actions and `bind`: attribute and handler bags you spread on your own elements, so the accessibility attributes come with them. The helpers the packaged components use for busy buttons, focus and live regions are exported from `#backend/a11y`.

## Bind a composable to your markup

`useLoginFlow()` is the sign-in step machine `<AuthForm>` runs on. Spread its bindings on your elements:

```vue [app/pages/login.vue]
<script setup lang="ts">
const flow = useLoginFlow()
const { t } = useLabels('auth')
</script>

<template>
  <main>
    <h1>{{ t('title') }}</h1>

    <form v-if="flow.step.value === 'choose' || flow.step.value === 'request-code'" @submit.prevent="flow.sendCode()">
      <label>
        {{ t('email') }}
        <input v-model="flow.email.value" v-bind="flow.bind.emailInput">
      </label>
      <button v-bind="flow.bind.submit">{{ t('sendCode') }}</button>
      <button v-bind="flow.bind.passkeyButton">{{ t('passkeySignIn') }}</button>
    </form>

    <form v-else-if="flow.step.value === 'verify-code'" @submit.prevent="flow.verifyCode()">
      <label>
        {{ t('code') }}
        <input v-model="flow.otp.value" v-bind="flow.bind.codeInput">
      </label>
      <button v-bind="flow.bind.submit">{{ t('verify') }}</button>
    </form>

    <section v-else-if="flow.step.value === 'passkey-offer'">
      <p>{{ t('passkeyOffer') }}</p>
      <button type="button" @click="flow.addPasskey()">{{ t('addPasskey') }}</button>
      <button type="button" @click="flow.skipPasskey()">{{ t('skip') }}</button>
    </section>

    <p v-bind="flow.bind.status" />
  </main>
</template>
```

What the bindings carry:

<table>
<thead>
  <tr>
    <th>
      Binding
    </th>
    
    <th>
      Spread on
    </th>
    
    <th>
      Carries
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        bind.emailInput
      </code>
    </td>
    
    <td>
      The email <code>
        <input>
      </code>
    </td>
    
    <td>
      <code>
        type
      </code>
      
      , <code>
        autocomplete="username webauthn"
      </code>
      
       for passkey autofill, <code>
        aria-invalid
      </code>
      
       and <code>
        aria-describedby
      </code>
      
       when refused
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        bind.codeInput
      </code>
    </td>
    
    <td>
      The code <code>
        <input>
      </code>
    </td>
    
    <td>
      <code>
        inputmode="numeric"
      </code>
      
      , <code>
        autocomplete="one-time-code"
      </code>
      
      , the refusal's description, and focus when the step opens
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        bind.submit
      </code>
    </td>
    
    <td>
      The step's submit button
    </td>
    
    <td>
      <code>
        type="submit"
      </code>
      
      , and <code>
        aria-disabled
      </code>
      
       while a step runs, so focus stays on it
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        bind.passkeyButton
      </code>
    </td>
    
    <td>
      The passkey button
    </td>
    
    <td>
      The click handler, <code>
        aria-disabled
      </code>
      
       while the browser's prompt is open, and the "Last used" mark as its description
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        bind.back
      </code>
    </td>
    
    <td>
      The button that returns to the previous step
    </td>
    
    <td>
      <code>
        type="button"
      </code>
      
      , the click handler, and focus on the field it returns to
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        bind.status
      </code>
    </td>
    
    <td>
      An empty element
    </td>
    
    <td>
      A polite live region that announces a sent code, and an alert for a failure
    </td>
  </tr>
</tbody>
</table>

Your page sits at `/login`, so it replaces the packaged sign-in page ([Swap a part](https://nuxt-backend.dev/docs/build/ui/customize/parts#replace-a-page)). Labels and translations still apply through `useLabels`.

## Spread a binding by its shape

A binding is one of three shapes, and the shape says how a template spreads it. A composable binds mostly one way, and some add functions of an item beside it:

- **A computed ref**, spread with its `.value`: `v-bind="form.bind.root.value"`. A template unwraps a top-level ref, never one nested in `bind`, so without `.value` nothing lands on the element. `useContactForm`, `useReportForm`, `useSignInAlerts`, `useUploadField`, `useNotificationInbox`, `useActivation` and `useAiLabel` bind mostly this way.
- **A plain object**, spread as it is: `v-bind="flow.bind.submit"`. `useLoginFlow`, `usePricing` and `useWaitlist` bind mostly this way.
- **A function of an item**, spread with what it returns for that item: `v-bind="report.bind.reason('spam')"`, `v-bind="pricing.bind.planCard(plan)"`, `v-bind="signIns.bind.alert(alert)"`.

[Headless bindings](https://nuxt-backend.dev/docs/reference/nuxt/composables#headless-bindings) lists every binding with its shape, generated from the composables' types.

## Show a plan list on your own cards

`usePricing()` gives the plans from your live catalog, and `bind.planCard(plan)` names the card's group after the plan, so a row of the same buttons reads apart:

```vue [app/pages/pricing.vue]
<script setup lang="ts">
const pricing = usePricing()
const billing = useBilling()
</script>

<template>
  <main>
    <h1>Plans</h1>
    <div v-for="plan in pricing.plans.value" :key="plan.key" v-bind="pricing.bind.planCard(plan)">
      <h2>{{ plan.name }}</h2>
      <button v-bind="pricing.bind.planAction(plan)">Subscribe</button>
    </div>
  </main>
</template>
```

`bind.planAction(plan)` opens checkout, or changes the plan for a subscriber, keeps focus while it opens, and hides the button from a member who manages no billing: the server would refuse them anyway.

The other pricing bindings follow the same shape:

<table>
<thead>
  <tr>
    <th>
      Binding
    </th>
    
    <th>
      Spread on
    </th>
    
    <th>
      Carries
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        bind.periodSwitch
      </code>
    </td>
    
    <td>
      The monthly and yearly toggle
    </td>
    
    <td>
      <code>
        role="switch"
      </code>
      
      , <code>
        aria-checked
      </code>
      
       on yearly, and the click handler
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        bind.planCard(plan)
      </code>
    </td>
    
    <td>
      One plan's container
    </td>
    
    <td>
      <code>
        role="group"
      </code>
      
      , named by the plan
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        bind.planAction(plan)
      </code>
    </td>
    
    <td>
      The plan's button
    </td>
    
    <td>
      The checkout or plan-change handler, <code>
        aria-disabled
      </code>
      
       while it opens
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        bind.packCard(pack)
      </code>
    </td>
    
    <td>
      One credit pack's container
    </td>
    
    <td>
      <code>
        role="group"
      </code>
      
      , named by the pack
    </td>
  </tr>
</tbody>
</table>

## Use the accessibility helpers

For your own components, the same helpers the packaged ones use come from `#backend/a11y`:

```vue [app/components/RenameStrip.vue]
<script setup lang="ts">
import { useActionState, useFocusReturn, useLiveRegion } from '#backend/a11y'
import { api } from '#backend/api'

const props = defineProps<{ id: string }>()
const rename = useMutation(api.strips.rename)
const title = ref('')
const action = useActionState(() => rename({ id: props.id, title: title.value }), { busy: 'Saving…' })
const live = useLiveRegion()
const focus = useFocusReturn()

async function save() {
  await action.run()
  live.announce(action.error.value ? action.error.value.message : 'Title saved.', { alert: !!action.error.value })
  focus.restore()
}
</script>

<template>
  <input v-model="title" aria-label="Strip title">
  <button v-bind="action.bind" @click="save">{{ action.pending.value ? 'Saving…' : 'Save title' }}</button>
  <p v-bind="live.bind" />
</template>
```

<table>
<thead>
  <tr>
    <th>
      Helper
    </th>
    
    <th>
      Does
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        useActionState(fn, { busy })
      </code>
    </td>
    
    <td>
      Runs an action once at a time; <code>
        bind
      </code>
      
       keeps the button focusable with <code>
        aria-disabled
      </code>
      
       and says what it waits for; <code>
        pending
      </code>
      
       and <code>
        error
      </code>
      
       as refs
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useFocusReturn()
      </code>
    </td>
    
    <td>
      Remembers the element that had focus, and <code>
        restore()
      </code>
      
       returns it there, after a dialog closes or a row is removed
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        useLiveRegion()
      </code>
    </td>
    
    <td>
      A region that stays mounted; <code>
        announce(text, { alert })
      </code>
      
       speaks a polite status or an alert
    </td>
  </tr>
</tbody>
</table>

## Use it beside any UI library

The package depends on no UI library and brings no theme bridge. Put your library's components in your markup and spread the bindings on them: most kits pass unknown attributes through to their root element. Two habits of component kits work against accessibility:

- **Do not use a kit's loading or disabled prop for a busy button.** A disabled button drops focus to the page. Spread `bind.submit` or `action.bind` instead, which keep it focusable with `aria-disabled`.
- **Keep words in the button.** An icon-only button needs an accessible name that starts with the words a person would say to press it.

To keep the packaged pages and your kit in one look, set the `--bk-*` tokens from your kit's variables ([Restyle with tokens](https://nuxt-backend.dev/docs/build/ui/customize/tokens)), or load no package CSS with `css: false`.

## What happens when…

The refusals are the composables' own, read with [`getBackendError`](https://nuxt-backend.dev/docs/build/data/read-write/errors): a wrong or expired code is [`invalid_input`](https://nuxt-backend.dev/docs/reference/backend/errors#invalid_input) on `otp`, too many tries is [`rate_limited`](https://nuxt-backend.dev/docs/reference/backend/errors#rate_limited) with `flow.retryAfter` as a countdown, and a passkey-only account asked for a code is [`forbidden`](https://nuxt-backend.dev/docs/reference/backend/errors#forbidden). The bindings put each refusal on its field and in the live region; your markup only has to render them.

## Limits

- **No separate unstyled kit.** The package ships styled components and headless composables, not a third tier of unstyled primitives. `css: false` drops the styles and keeps the packaged markup; the [Customization ladder](https://nuxt-backend.dev/docs/build/ui/customize#why-it-works-this-way) explains why.
- **Your markup, your duty.** A binding you leave out takes its guarantee with it. Keep what each region promised ([Accessibility](https://nuxt-backend.dev/docs/build/ui/accessibility#what-a-replacement-must-keep)).
- **Composables, not pages.** A page of yours at a private path declares its own guard ([Protect pages and routes](https://nuxt-backend.dev/docs/build/auth/access/pages)).

## Test it

Run an axe check on your page in your end-to-end suite, in both colour schemes, and walk it with the keyboard: Tab reaches every control, a busy button keeps focus, and a wrong code is announced. [Run end-to-end tests](https://nuxt-backend.dev/docs/develop/testing/e2e) shows reading the sign-in code from `nuxt-backend inbox --json`.

## Related

- [Build a custom sign-in page](https://nuxt-backend.dev/docs/build/auth/sign-in/custom-page): the sign-in flow in full.
- [Composables](https://nuxt-backend.dev/docs/reference/nuxt/composables): every composable and its bindings.
- [Accessibility](https://nuxt-backend.dev/docs/build/ui/accessibility): what a replacement keeps.
- [Eject a part, page or email](https://nuxt-backend.dev/docs/build/ui/customize/eject): when you want the packaged source instead.


## Sitemap

See the full [sitemap](https://nuxt-backend.dev/sitemap.md) for all pages.
