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:
Anatomy
import { Input } from '@base-ui/react/input';
<Input />API reference
defaultValueUnion—
Union- Name
- Type
string | number | string[] | undefined
onValueChangefunction—
function- Name
- Description
Callback fired when the
valuechanges. Use when controlled.- Type
| (( value: string, eventDetails: Input.ChangeEventDetails, ) => void | undefined) | undefined
classNamestring | function—
string | 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—
React.CSSProperties | function- Name
- Type
| React.CSSProperties | (( state: Input.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
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
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).
Additional Types
Input.Props
Re-Export of Input props as InputProps
Input.State
type InputState = {
disabled: boolean;
touched: boolean;
dirty: boolean;
valid: boolean | null;
filled: boolean;
focused: boolean;
};Input.ChangeEventReason
type InputChangeEventReason = 'none';Input.ChangeEventDetails
type InputChangeEventDetails = {
reason: 'none';
event: Event;
cancel: () => void;
allowPropagation: () => void;
isCanceled: boolean;
isPropagationAllowed: boolean;
trigger: Element | undefined;
};