On this page

Input

Live examples of Input, with the exact Vue file that renders each one.

Every example is a complete Vue file. Copy it into an app that has the registry installed, or open it in StackBlitz. Click a field, or Tab to it, to see the focus.

Label and help text

The label sits above the field and the help text under it. The help text is linked with aria-describedby, so screen readers read it after the label.

InputWithLabel.vue
<script setup lang="ts">
import { Field, FieldDescription, FieldLabel } from '@/components/ui/field'
import { Input } from '@/components/ui/input'
</script>

<template>
  <Field class="max-w-sm">
    <FieldLabel for="store-name">Store name</FieldLabel>
    <Input id="store-name" autocomplete="organization" aria-describedby="store-name-help" />
    <FieldDescription id="store-name-help">Shown on invoices and in emails to customers.</FieldDescription>
  </Field>
</template>

Error

aria-invalid="true" turns the edge red, and the message under the field says how to fix it. Add a domain to the address and the error goes away. While the field has focus, the focus edge shows instead of the red one.

InputInvalid.vue
<script setup lang="ts">
import { computed, ref } from 'vue'
import { Field, FieldError, FieldLabel } from '@/components/ui/field'
import { Input } from '@/components/ui/input'

// The error shows under the field and says how to fix it. Add a domain to make it go away.
const email = ref('orders@cornerhardware')
const invalid = computed(() => !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email.value))
</script>

<template>
  <Field class="max-w-sm" :data-invalid="invalid">
    <FieldLabel for="alert-email">Email for sync alerts</FieldLabel>
    <Input
      id="alert-email"
      v-model="email"
      type="email"
      autocomplete="email"
      :aria-invalid="invalid"
      :aria-describedby="invalid ? 'alert-email-error' : undefined"
    />
    <FieldError v-if="invalid" id="alert-email-error">Enter an email address with a domain, like [email protected].</FieldError>
  </Field>
</template>

Disabled until another choice turns it on

A disabled field is for a value that can change in this form, but not right now. The help text says what makes it available.

InputDisabled.vue
<script setup lang="ts">
import { ref } from 'vue'
import { Checkbox } from '@/components/ui/checkbox'
import { Field, FieldDescription, FieldGroup, FieldLabel } from '@/components/ui/field'
import { Input } from '@/components/ui/input'

// Disabled only while another choice in the same form turns it off, and the help text says how to turn it on.
const custom = ref(false)
const prefix = ref('')
</script>

<template>
  <FieldGroup class="max-w-sm">
    <Field orientation="horizontal">
      <Checkbox id="custom-prefix" v-model="custom" />
      <FieldLabel for="custom-prefix">Use my own order number prefix</FieldLabel>
    </Field>
    <Field :data-disabled="!custom">
      <FieldLabel for="order-prefix">Order number prefix</FieldLabel>
      <Input id="order-prefix" v-model="prefix" :disabled="!custom" maxlength="6" aria-describedby="order-prefix-help" />
      <FieldDescription id="order-prefix-help">
        {{ custom ? 'Up to 6 letters, such as WEB.' : 'Select "Use my own order number prefix" to change it.' }}
      </FieldDescription>
    </Field>
  </FieldGroup>
</template>

A code of varying length

An authenticator app gives 6 digits and an emailed code can be longer, so the code goes in one field, not one box per character (Input OTP needs a fixed length). Large size, code font, and autocomplete="one-time-code" so phones can fill it in.

Enter the code from your authenticator app, or the one we emailed you. It has 6 to 8 characters.

InputCode.vue
<script setup lang="ts">
// A code whose length varies (an authenticator app gives 6 digits, an emailed code up to 8), so one field,
// not one box per character (Input OTP). Large (size.control.large), code font, autofill from SMS or email.
import { ref } from 'vue'
import { Input } from '@/components/ui/input'

const code = ref('')
</script>

<template>
  <div class="grid w-full max-w-xs gap-(--bh-space-100)">
    <label for="verify-code" class="text-(--bh-color-text) [font:var(--bh-font-label-default)]">Verification code</label>
    <Input
      id="verify-code"
      v-model="code"
      inputmode="numeric"
      autocomplete="one-time-code"
      maxlength="8"
      spellcheck="false"
      placeholder="6 to 8 characters"
      aria-describedby="verify-code-hint"
      class="h-(--bh-size-control-large) [font:var(--bh-font-code-default)]"
    />
    <p id="verify-code-hint" class="m-0 text-(--bh-color-text-subtle) [font:var(--bh-font-body-small)]">Enter the code from your authenticator app, or the one we emailed you. It has 6 to 8 characters.</p>
  </div>
</template>