Input
updatedYou type, it holds. That's the whole deal.
Open Props in the corner of the example to try variant, size, disabled and aria-invalid. size runs from xs, 28px, to xl, 48px, as tall as the button of the same name, so an input and a button line up in a row; from 768px up xs sets 12px text and xl 16px, below that every size keeps 16px. A disabled input takes its colours from --foreground, like a disabled button. An invalid one turns its line --destructive: when aria-invalid is set, by a Field or by hand, and when the browser's own validation fails after the user has interacted with it, through :user-invalid, so required or type="email" work without any script and an empty form does not start out red.
outline: a bordersoft: a tinted surface, no bordersubtle: a tinted surface with a borderfilled: a tinted surface with a line underneathghost: invisible until hover or focus, for editing in place (like a title)
soft and ghost barely show where the field is. Fine for a search box in a toolbar, but in forms use outline, filled or subtle.
Installation
Usage
<script setup lang="ts">
import { Input } from '@/components/ui/input'
const email = ref('')
</script>
<template>
<Input v-model="email" type="email" placeholder="Email" />
</template>
Works like a native <input>: every attribute goes straight to it.
Inside a Field it gets its label, error and state for free. On its own, give it a Label or aria-label.
Text is 16px on phones and 14px on desktop. Any smaller, and iOS zooms in on focus.
Want the label inside the input? That's Input Floating.
Input's variants, states and sizes come from Text Control, the frame Textarea, Select, Combobox and the other text fields share, so a field of your own can wear it too.
Examples
File
v-model on a file input gives you the browser's fake path, not the files. For a File or File[] model, drag and drop or a list of what was picked, use File Upload.
PNG or JPG, up to 2 MB.
API Reference
class is also accepted and lands on the input, so width classes work.
Input
| Prop | Default | Type and description |
|---|---|---|
| id | — | stringOverrides the |
| defaultValue | — | string | numberThe starting value when |
| variant | — | "outline" | "soft" | "filled" | "ghost" | "subtle" | null
|
| size | "md" | "md" | "xs" | "sm" | "lg" | "xl"Height, from 28px for |
| disabled | — | booleanDisables the input. Also set by a disabled field. |
| required | — | booleanMarks the input required. Also set by a required field. |
| modelValue | — | string | numberThe value, bound with |
| Event | Payload and description |
|---|---|
| update:modelValue | [value: string | number | undefined]Fires as the value changes. |
Props
- id
stringOverrides theidtaken from a surrounding field.- defaultValue
string | numberThe starting value whenv-modelis not used.- variant
"outline" | "soft" | "filled" | "ghost" | "subtle" | nulloutlinedraws a border,softa tinted surface without one,filleda tinted surface with a line underneath,ghostnothing until hovered or focused, andsubtlea tinted surface with a border.- size
"md" "md" | "xs" | "sm" | "lg" | "xl"Height, from 28px forxsto 48px forxl,mdby default. Each size matches the button size of the same name.- disabled
booleanDisables the input. Also set by a disabled field.- required
booleanMarks the input required. Also set by a required field.- modelValue
string | numberThe value, bound withv-model.
Emits
- update:modelValue
[value: string | number | undefined]Fires as the value changes.
Data attributes
| data-slot | Attributes | Description |
|---|---|---|
| input | data-variant, data-size | The input. Both attributes are set even when left at their defaults, outline and md. |