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 aField.Labelin aField. 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
| Prop | Type | Default | Description |
|---|---|---|---|
defaultValue | string | number | string[] | undefined | The 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. | |
disabled | boolean | undefined | false | Disables the input. A disabled field or fieldset around the input also disables it. |
id | string | undefined | The id of the input. With no id, the input has an id of its own. | |
modelValue | string | number | readonly string[] | undefined | The text of the input. Bind it with v-model. With no modelValue, the input keeps its own
text. | |
name | string | undefined | The name of the input in the data of the form. The name of a Field.Root around it wins. | |
readonly | boolean | undefined | false | The 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
| Slot | Slot props | Description |
|---|---|---|
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: InputState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Events
| Event | Arguments | Description |
|---|---|---|
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
| Member | Type | Description |
|---|---|---|
element | TextElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
:disabled | The input is disabled. |
:read-only | The 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 UI | Vase UI |
|---|---|
Input | v-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
The handbook gives the differences that all components share: Styling, Animation, Composition, Customization, Forms and TypeScript.