Skip to content

Input ​

A native input element that works with Field.

vue
<script setup lang="ts">
import { Input } from '@vase-ui/vue/input';
import styles from './index.module.css';
</script>

<template>
  <label :class="styles.Label">
    Name
    <Input placeholder="e.g. Colm Tuite" :class="styles.Input" />
  </label>
</template>
css
.Label {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
  font-size: 0.875rem;
  line-height: 1.25rem;
  font-weight: 700;
  color: oklch(14.5% 0 0deg);

  @media (prefers-color-scheme: dark) {
    color: white;
  }
}

.Input {
  box-sizing: border-box;
  padding: 0 0.5rem;
  margin: 0;
  border-radius: 0;
  border: 1px solid oklch(14.5% 0 0deg);
  width: 10rem;
  height: 2rem;
  font-family: inherit;
  font-size: 0.875rem;
  line-height: 1.25rem;
  font-weight: 400;
  background-color: white;
  color: oklch(14.5% 0 0deg);

  @media (any-pointer: coarse) {
    font-size: 1rem;
    line-height: 1.5rem;
  }

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
    color: white;
  }

  &::placeholder {
    color: oklch(55.6% 0 0deg);

    @media (prefers-color-scheme: dark) {
      color: oklch(70.8% 0 0deg);
    }
  }

  &:focus {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: -1px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}
vue
<script setup lang="ts">
import { Input } from '@vase-ui/vue/input';
</script>

<template>
  <label class="flex flex-col items-start gap-1 text-sm font-bold text-neutral-950 dark:text-white">
    Name
    <Input
      placeholder="e.g. Colm Tuite"
      class="h-8 w-40 border border-neutral-950 dark:border-white bg-white dark:bg-neutral-950 px-2 text-sm any-pointer-coarse:text-base font-normal text-neutral-950 dark:text-white placeholder:text-neutral-500 dark:placeholder:text-neutral-400 focus:outline-2 focus:-outline-offset-1 focus:outline-neutral-950 dark:focus:outline-white"
    />
  </label>
</template>

Usage guidelines ​

  • Form controls must have an accessible name: Give the input a <label> element, or a Field.Label in a Field. See the forms guide.

Anatomy ​

Import the component:

vue
<script setup lang="ts">
import { Input } from '@vase-ui/vue/input';
</script>

<template>
  <Input />
</template>

API reference ​

Input ​

A native input element that works with Field. Renders an <input> element.

Props

PropTypeDefaultDescription
defaultValuestring | number | string[] | undefinedThe text at the mount of an input that has no modelValue. A native reset of the form gives the input the defaultValue that it has at the reset.
disabledboolean | undefinedfalseDisables the input. A disabled field or fieldset around the input also disables it.
idstring | undefinedThe id of the input. With no id, the input has an id of its own.
modelValuestring | number | readonly string[] | undefinedThe text of the input. Bind it with v-model. With no modelValue, the input keeps its own text.
namestring | undefinedThe name of the input in the data of the form. The name of a Field.Root around it wins.
readonlyboolean | undefinedfalseThe user cannot change the text. The input stays in the tab order and in the data of the form, and its field does not validate it.

Slots

SlotSlot propsDescription
element
props: Record<string, unknown>
elementRef: (target: unknown) => void
state: InputState
Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref.

Events

EventArgumentsDescription
valueChange[value: string, details: InputChangeEventDetails]The user changes the text. details.cancel() keeps the text as it was.
update:modelValue[value: string]Comes after the change event with the new value, unless a listener cancels the change. v-model uses it.

Exposed

MemberTypeDescription
elementTextElement | nullThe element of the part, or null while it is not mounted.

Selectors

SelectorDescription
:disabledThe input is disabled.
:read-onlyThe input is read-only or disabled.
[data-filled]In a field, the input has text.
[data-valid]The field of the input is valid.
[aria-invalid="true"]The field of the input is invalid.
[data-touched]In a field, the focus left the input.
[data-dirty]In a field, the text differs from the first text.

Differences from Base UI ​

Vase UI ports Input from Base UI 1.9.0.

API ​

Base UIVase UI
Inputv-model binds the text, and an input with no modelValue keeps its own text. readonly is the native attribute. CSS selects :focus, :disabled and [aria-invalid="true"], so the state has no focused, and the input has no data-focused, data-disabled and data-invalid.

Behavior ​

Vase UIEvidence
Enter has no meaning of its own in a field. Enter in a text control submits its form as the browser does, and the submit validates the field one time. Where the browser does not submit (a field with no form, a form whose submit button is disabled), nothing validates. A developer validates at a key with validate() of Field.Root. Base UI validates the field at Enter also when no submit occurs.
A control in a field keeps the id of the developer in the server HTML when no Field.Label of the field renders before it, and a label that renders after the control has that id in for. When a label renders before the control, the control has the generated id of the field until the hydration, because that label names the generated id. Then the control takes its id, and the label follows. In each order, the label names the control in the server HTML. Base UI gives each control in a field the generated id until the hydration, also where no label needs it.

The handbook gives the differences that all components share: Styling, Animation, Composition, Customization, Forms and TypeScript.