Skip to contents

Input

A native input element that automatically works with Field.

Usage guidelines

  • Form controls must have an accessible name: It can be created using a <label> element or the Field component. See the forms guide.

Anatomy

Import the component and use it as a single part:

Anatomy

API reference

value string | number | null —
Name
Description

Current value. Use bind:value to share it with the parent.

Type
string | number | null
Binding
bind:value
defaultValue string | number | null —
Description

The value an empty value starts from, as on an HTML input.

Type
string | number | null
onValueChange function —
Description

Called when the user edits the control. eventDetails.cancel() vetoes the change.

Type
(value: string, eventDetails: FieldControlChangeEventDetails) => void
render Snippet<[props: HTMLAttributes<HTMLElement>, state: FieldControlState, children: Snippet | undefined]> —
Name
Description

Replace the default <input>. Spread props onto the host element.

Type
Snippet<[props: HTMLAttributes<HTMLElement>, state: FieldControlState, children: Snippet | undefined]>
disabled boolean
Name
disabled
Description

Whether the component should ignore user interaction.

Type
boolean
touched boolean
Name
touched
Description

Whether the field has been touched.

Type
boolean
dirty boolean
Name
dirty
Description

Whether the field value has changed from its initial value.

Type
boolean
valid boolean | null
Name
valid
Description

Whether the field is valid. null means validity is not known yet.

Type
boolean | null
filled boolean
Name
filled
Description

Whether the field has a value.

Type
boolean
focused boolean
Name
focused
Description

Whether the field is focused.

Type
boolean
data-disabled
Present when the input is disabled.
data-valid
Present when the input is in a valid state (when wrapped in Field.Root).
data-invalid
Present when the input is in an invalid state (when wrapped in Field.Root).
data-dirty
Present when the input's value has changed (when wrapped in Field.Root).
data-touched
Present when the input has been touched (when wrapped in Field.Root).
data-filled
Present when the input is filled (when wrapped in Field.Root).
data-focused
Present when the input is focused (when wrapped in Field.Root).