Input
A native input element that automatically works with Field.
import { Input } from 'base-ui-solid/input';
import styles from './index.module.css';
export default function ExampleInput() {
return (
<label class={styles.Label}>
Name
<Input placeholder="e.g. Colm Tuite" class={styles.Input} />
</label>
);
}
Usage 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-solid/input';
<Input />;
API reference
Prop
Type
Default
defaultValueUnion—
The default value of the input. Use when uncontrolled.
string | number | string[]valueUnion—
The value of the input. Use when controlled.
string | string[] | numberonValueChangefunction—
Callback fired when the
value changes. Use when controlled.((value: string, eventDetails: Input.ChangeEventDetails) => void)classfunction—
CSS class applied to the element, or a function that
returns a class based on the component’s state.
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
Style applied to the element, or a function that
returns a style object based on the component’s state.
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
Replace the default element with a tag name, component, or render function.
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Data attributes
Name
Type
Default
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).
-Attribute | Description | |
|---|---|---|
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). | |
Input.State
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.ChangeEventReason
type InputChangeEventReason = 'none';Input.ChangeEventDetails
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;
};