Components
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.
Anatomy#
Import the component and use it as a single part:
import { Input } from '@egoist/solid-base/input';
<Input />;Examples#
Tracking the value#
onValueChange fires on every keystroke with the input's string value, so you don't need to read
event.currentTarget.value from onInput:
const [query, setQuery] = createSignal('');
<Input value={query()} onValueChange={(value) => setQuery(value)} />;Inside a field#
When placed in a Field, <Input> is labeled by <Field.Label>, described by
<Field.Description>, and takes part in the field's validation and data-* state attributes:
<Field.Root>
<Field.Label>Email</Field.Label>
<Input type="email" required />
<Field.Error />
</Field.Root>API reference#
<Input>
A native input element that automatically works with Field. Renders an <input> element.
idstring—The id of the input. A generated id is used by default.
namestring—Identifies the field when a form is submitted.
disabledbooleanfalseWhether the component should ignore user interaction.
onValueChange((value: string, eventDetails: Input.ChangeEventDetails) => void)—Callback fired when the value changes. Use when controlled.
defaultValueFieldControlProps['defaultValue']—The default value of the input. Use when uncontrolled.
valueFieldControlProps['value']—The value of the input. Use when controlled.
classstring | ClassValue | ((state: State) => ClassValue)—CSS class applied to the element, or a function that returns a class based on the component's state.
styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—Style applied to the element, or a function that returns a style based on the component's state.
renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—Allows you to replace the component's HTML element with a different tag, or compose it with another component.
Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.
data-disabledPresent when the input is disabled.
data-validPresent when the input is in a valid state (when wrapped in Field.Root).
data-invalidPresent when the input is in an invalid state (when wrapped in Field.Root).
data-touchedPresent when the input has been touched (when wrapped in Field.Root).
data-dirtyPresent when the input's value has changed (when wrapped in Field.Root).
data-filledPresent when the input is filled (when wrapped in Field.Root).
data-focusedPresent when the input is focused (when wrapped in Field.Root).