Input
A native input element that automatically works with Field.
View as MarkdownUsage guidelines
- Form controls must have an accessible name: It can be created using a
<label>element or theFieldcomponent. See the forms guide.
Anatomy
Import the component and use it as a single part:
import { Input } from '@base-ui/react/input';
<Input />API reference
defaultValueUnion—
- Name
- Description
The default value of the input. Use when uncontrolled.
- Type
string | number | string[] | undefined
valueUnion—
- Name
- Description
The value of the input. Use when controlled.
- Type
string | string[] | number | undefined
onValueChangefunction—
- Name
- Description
Callback fired when the
valuechanges. Use when controlled.- Type
| (( value: string, eventDetails: Input.ChangeEventDetails, ) => void) | undefined
classNamestring | function—
- Name
- 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) | undefined
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | (( state: Input.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | ((props: HTMLProps, state: Input.State) => ReactElement) | undefined
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).
| Attribute | Description | |
|---|---|---|
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). | |
Input.StateHide
type InputState = {
/** Whether the component should ignore user interaction. */
disabled: boolean;
/** Whether the field has been touched. */
touched: boolean;
/** Whether the field value has changed from its initial value. */
dirty: boolean;
/** Whether the field is valid. */
valid: boolean | null;
/** Whether the field has a value. */
filled: boolean;
/** Whether the field is focused. */
focused: boolean;
}Input.ChangeEventReasonHide
type InputChangeEventReason = 'none'Input.ChangeEventDetailsHide
type InputChangeEventDetails = {
/** The reason for the event. */
reason: 'none';
/** The native event associated with the custom event. */
event: Event;
/** Cancels Base UI from handling the event. */
cancel: () => void;
/** Allows the event to propagate in cases where Base UI will stop the propagation. */
allowPropagation: () => void;
/** Indicates whether the event has been canceled. */
isCanceled: boolean;
/** Indicates whether the event is allowed to propagate. */
isPropagationAllowed: boolean;
/** The element that triggered the event, if applicable. */
trigger: Element | undefined;
}