Input

A native input element that automatically works with Field.

View as Markdown

Usage guidelines

  • Form controls must have an accessible name: The input must have a meaningful label. Prefer using <Field> to provide a visible text label and description, or use the aria-label attribute as an alternative. See the forms guide for more on building form controls.

Anatomy

Import the component and use it as a single part:

Anatomy

API reference

defaultValue

Union

Type
string | number | string[] | undefined
onValueChange

function

Description

Callback fired when the value changes. Use when controlled.

Type
| ((
    value: string,
    eventDetails: Field.Control.ChangeEventDetails,
  ) => void)
| undefined
className

string | function

Description

CSS class applied to the element, or a function that returns a class based on the component’s state.

Type
| string
| ((state: Input.State) => string | undefined)
style

React.CSSProperties | function

Name
Type
| React.CSSProperties
| ((state: Input.State) => CSSProperties | undefined)
| undefined
render

ReactElement | function

Name
Description

Allows you to replace the component’s HTML element with a different tag, or compose it with another component.

Accepts a ReactElement or a function that returns the element to render.

Type
| ReactElement
| ((props: HTMLProps, state: Input.State) => ReactElement)
data-disabled

Present when the input is disabled.

data-valid

Present when the input is in valid state (when wrapped in Field.Root).

data-invalid

Present when the input is in 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).