Skip to main content
Version: Next

Input

import { Input } from '@editora/ui-react';

Composition Pattern​

Input follows a composition pattern. Use Input.Prefix, Input.Suffix, and Input.Error as named sub-components to compose the field layout declaratively:

Live Editor
function InputDemo() {
  return (
    <ThemeProvider>
      <Input
        label="Email"
        type="email"
        placeholder="name@company.com"
        required
        clearable
        validation="error"
        onChange={(value) => console.log(value)}
      >
        <Input.Prefix>✉️</Input.Prefix>
        <Input.Suffix>
          <button type="button">Verify</button>
        </Input.Suffix>
        <Input.Error>Enter a valid email address</Input.Error>
      </Input>
    </ThemeProvider>
  );
}
Result
Loading...

Sub-components​

Sub-componentSlotDescription
Input.PrefixprefixContent rendered on the left side of the input
Input.SuffixsuffixContent rendered on the right side of the input
Input.ErrorerrorError message shown when validation="error"
Changed in this release

onChange now fires on every keystroke, like React's onChange on <input>. The old behaviour (only when the edit is committed, on blur or Enter) is onCommit. Use defaultValue for a starting value; value together with onChange makes the field controlled.

Sign-in fields and password managers​

Password managers and browser autofill look for real inputs in the page, and an input inside a shadow root is found unreliably. For credential fields, put your own native input in the input slot: the component keeps its label, styling, clear and show/hide buttons around it, but the field itself is an ordinary input with your name and autocomplete, part of the form like any other.

<form method="post" action="/login">
<Input label="Email">
<input slot="input" name="email" type="email" autoComplete="username" />
</Input>
<PasswordField label="Password">
<input slot="input" name="password" autoComplete="current-password" />
</PasswordField>
<Button type="submit">Sign in</Button>
</form>

The component does not change the input's name, type (except the show/hide toggle), autocomplete or placeholder. It names the input after the label unless you labelled it yourself. Enter submits the form natively, and the value is submitted once.

Props​

PropTypeDefaultDescription
valuestring—Controlled value when onChange/onInput is passed (a change you do not store is undone); without a handler it is the initial value
defaultValuestring—Starting value of an uncontrolled field (written once, on mount)
onChange(value: string) => void—Fires on every keystroke, like React's onChange on <input>
onCommit(value: string) => void—Fires when the edit is committed (blur, or Enter in a single-line field)
onInput(value: string) => void—Fires on every keystroke (same as onChange)
onDebouncedInput(value: string) => void—Fires after debounce ms of inactivity
onClear() => void—Fires when the clear button is clicked
debouncenumber—Debounce delay in ms for onDebouncedInput
clearablebooleanfalseShows a clear button when the field has a value
validation'error' | 'success' | 'none''none'Visual validation state
counterbooleanfalseShows character count (requires maxlength)
typestring'text'Native input type (email, password, number, etc.)
namestring—Form field name
requiredbooleanfalseMarks field as required
patternstring—Native validation pattern
inputModestring—Virtual keyboard hint (numeric, email, etc.)
autoCompletestring—Browser autocomplete hint
minlengthnumber—Minimum character length
maxlengthnumber—Maximum character length
minstring | number—Minimum value (for type="number")
maxstring | number—Maximum value (for type="number")
stepstring | number—Step increment (for type="number")
spellCheckboolean—Enable/disable browser spell check
placeholderstring—Placeholder text
labelstring—Visible label rendered by the web component
descriptionstring—Helper text below the field
readOnlybooleanfalseMakes the field read-only
autofocusbooleanfalseFocuses the field on mount
disabledbooleanfalseDisables the field
size'sm' | 'md' | 'lg' | '1' | '2' | '3''md'Input size
variant'classic'Visual style
tone'default'Color tone
density'default' | 'compact' | 'comfortable''default'Vertical spacing
shape'default' | 'square' | 'soft''default'Border-radius preset
radius'none' | 'large' | 'full' | string—Custom border-radius override
colorstring—Custom color token
floatingLabelbooleanfalseAnimates label above the field on focus/fill
headlessbooleanfalseStrips all default styles

Examples​

Search with prefix and debounce​

<Input
placeholder="Search..."
debounce={300}
onDebouncedInput={(value) => fetchResults(value)}
>
<Input.Prefix>🔍</Input.Prefix>
</Input>

Character counter​

<Input label="Bio" maxlength={160} counter />

Number input with constraints​

<Input type="number" min={0} max={100} step={5} label="Score" />

Validation with error message​

<Input label="Username" validation="error">
<Input.Error>Username is already taken</Input.Error>
</Input>

Notes​

  • Input.Error is only visible when validation="error" is set on the root.
  • counter requires maxlength to display the limit.
  • minlength / maxlength and autofocus map directly to the underlying <ui-input> web component attributes.