Skip to content

Input

A native input element that automatically integrates with Field for labeling and validation.

We'll never share your email

Introduction

Input is a thin wrapper around Field Control that provides a standalone, semantic API for rendering native <input> elements. When placed inside a FieldRoot, it gains labeling, validation, and state management with zero extra configuration.

You can use Input as a drop-in replacement for FieldControl when your form control is a standard text input.

Anatomy

Import the component and place it inside a FieldRoot:

vue
<script setup>
import {
  FieldDescription,
  FieldError,
  FieldLabel,
  FieldRoot,
  Input,
} from 'base-ui-vue'
</script>

<template>
  <FieldRoot>
    <FieldLabel />
    <Input />
    <FieldDescription />
    <FieldError />
  </FieldRoot>
</template>

Input can also be used standalone without FieldRoot, in which case it renders a plain <input> without Field integration.

Standalone usage

When you don't need labeling or validation, use Input on its own:

vue
<script setup>
import { Input } from 'base-ui-vue'
</script>

<template>
  <Input placeholder="Search…" />
</template>

Controlled value

Use the value prop to control the input's value and the @value-change event to listen for changes:

vue
<script setup>
import { FieldRoot, Input } from 'base-ui-vue'
import { ref } from 'vue'

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

<template>
  <FieldRoot>
    <Input :value="search" @value-change="(v) => search = v" />
  </FieldRoot>
</template>

Rendering a different element

Use the as prop to render a different element, such as a textarea:

vue
<script setup>
import { FieldRoot, Input } from 'base-ui-vue'
</script>

<template>
  <FieldRoot>
    <Input as="textarea" />
  </FieldRoot>
</template>

API reference

Input

Renders a native <input> element. Wraps FieldControl with all of its capabilities.

PropTypeDefaultDescription
asstring | Component'input'The element or component to render.
valuestring--The controlled value of the input.
defaultValuestring''The default value when uncontrolled.
namestring--Identifies the input when a form is submitted.
disabledbooleanfalseWhether the input is disabled.
requiredboolean--Whether the input is required.
typestring--The input's type attribute (e.g., text, email, password).
placeholderstring--Placeholder text shown when the input is empty.
patternstring--A regex pattern the input's value must match.
minlengthnumber--Minimum number of characters.
maxlengthnumber--Maximum number of characters.
minstring | number--Minimum value for number and date inputs.
maxstring | number--Maximum value for number and date inputs.
stepstring | number--Step increment for number and date inputs.
autofocusbooleanfalseWhether to focus the input on mount.
classstring | ((state: State) => string)--CSS class applied to the element, or a function that returns a class based on the component's state.
styleStyleValue | ((state: State) => StyleValue)--Style applied to the element, or a function that returns a style object based on the component's state.
EventTypeDescription
@value-change(value: string, event: Event) => voidFired when the input's value changes.
Data attributeDescription
data-disabledPresent when the input is disabled.
data-validPresent when the input is in a valid state.
data-invalidPresent when the input is in an invalid state.
data-touchedPresent when the input has been touched.
data-dirtyPresent when the input's value has changed.
data-filledPresent when the input contains a value.
data-focusedPresent when the input is focused.