Text Input
TextInput accepts one line of free-form text, such as a search query, email address, amount, or URL.
import { RiSearchLine } from '@remixicon/react';
import { TextInput } from '@/components/ui/wideset/text-input/TextInput';
<TextInput>
<TextInput.Prefix inner>
<TextInput.Icon icon={RiSearchLine} />
</TextInput.Prefix>
<TextInput.Input placeholder="Search projects" />
</TextInput>Installation
pnpm dlx wideset add text-input
Copies the component and any Wideset components it uses into your project.
Examples
Variants
Primary is the default for every field. Danger marks a value that failed validation and sets aria-invalid on the input: switch to it after the user leaves the field or submits. Put the reason in the FormField's errorText, which the field links to the input with aria-describedby, because the red border alone does not tell screen reader users why.
import { TextInput } from '@/components/ui/wideset/text-input/TextInput';
import { useState } from 'react';
export default function TextInputVariants() {
const [email, setEmail] = useState('anna.kowalska@');
return (
<div className="gap-ws-12 flex w-[20rem] max-w-full flex-col">
<TextInput variant="primary" placeholder="Project name" aria-label="Project name" />
<TextInput
variant="danger"
value={email}
onChange={(event) => setEmail(event.target.value)}
aria-label="Email"
/>
</div>
);
}Presets
Border draws the field's own frame, for fields placed straight on the page or in a form. Ghost drops the frame until hover and focus, for a field that sits inside a surface that already has one, such as a toolbar or a table header.
import { TextInput } from '@/components/ui/wideset/text-input/TextInput';
export default function TextInputPresets() {
return (
<div className="gap-ws-12 flex w-[20rem] max-w-full flex-col">
<TextInput preset="border" placeholder="Project name" aria-label="Project name" />
<TextInput preset="ghost" placeholder="Project name" aria-label="Project name" />
</div>
);
}Sizes
Medium is the default for forms. Small fits dense tables and filter bars, large a short form that is the main task on the page. Match the size of the buttons and selects next to the field, and use one size per form.
import { TextInput } from '@/components/ui/wideset/text-input/TextInput';
export default function TextInputSizes() {
return (
<div className="gap-ws-12 flex w-[20rem] max-w-full flex-col">
{(['sm', 'md', 'lg'] as const).map((size) => (
<TextInput key={size} size={size} placeholder="Project name" aria-label="Project name" />
))}
</div>
);
}Affixes
An affix outside the field (Prefix, Suffix) is for fixed text the user does not type, such as a protocol or a unit. With inner it sits inside the frame, for an icon or an icon button. Clicking an affix focuses the input; the clear button only appears while the field holds a value.
import { RiFileCopyLine, RiSearchLine } from '@remixicon/react';
import { TextInput } from '@/components/ui/wideset/text-input/TextInput';
import { useState } from 'react';
export default function TextInputAffixes() {
const [query, setQuery] = useState('Quarterly report');
return (
<div className="gap-ws-12 flex w-[20rem] max-w-full flex-col">
<TextInput>
<TextInput.Prefix>https://</TextInput.Prefix>
<TextInput.Input placeholder="your-company" aria-label="Website" />
<TextInput.Suffix>.com</TextInput.Suffix>
</TextInput>
<TextInput value={query} onChange={(event) => setQuery(event.target.value)}>
<TextInput.Prefix inner>
<TextInput.Icon icon={RiSearchLine} />
</TextInput.Prefix>
<TextInput.Input placeholder="Search files" aria-label="Search files" />
<TextInput.Suffix inner>
<TextInput.ClearButton />
</TextInput.Suffix>
</TextInput>
<TextInput>
<TextInput.Prefix>$</TextInput.Prefix>
<TextInput.Input placeholder="0.00" aria-label="Amount" />
<TextInput.Suffix inner>
<TextInput.IconButton icon={RiFileCopyLine} aria-label="Copy amount" />
</TextInput.Suffix>
</TextInput>
</div>
);
}Search
A search field is a composed TextInput: a search icon in an inner prefix, type="search" on the input and a clear button in an inner suffix. type="search" makes screen readers announce a search field and gives mobile keyboards a search key. Clearing runs onChange with an empty value first, then onClear for anything that only belongs to the button, such as telling the user the full list is back. This composition replaces the deprecated Search component.
import { RiSearchLine } from '@remixicon/react';
import { TextInput } from '@/components/ui/wideset/text-input/TextInput';
import { useState } from 'react';
const invoices = ['Acme Corp', 'Acme Studio', 'Globex', 'Initech'];
export default function TextInputSearch() {
const [query, setQuery] = useState('Acme');
const [cleared, setCleared] = useState(false);
const matches = invoices.filter((name) =>
name.toLowerCase().includes(query.trim().toLowerCase()),
);
return (
<div className="gap-ws-4 flex w-[20rem] max-w-full flex-col">
<TextInput
value={query}
onChange={(event) => {
setQuery(event.target.value);
setCleared(false);
}}
>
<TextInput.Prefix inner>
<TextInput.Icon icon={RiSearchLine} />
</TextInput.Prefix>
<TextInput.Input type="search" placeholder="Search invoices" aria-label="Search invoices" />
<TextInput.Suffix inner>
<TextInput.ClearButton onClear={() => setCleared(true)} />
</TextInput.Suffix>
</TextInput>
<p role="status" className="typography-body-sm text-ws-static-subtle">
{cleared
? `Search cleared. Showing all ${invoices.length} invoices.`
: `${matches.length} of ${invoices.length} invoices match.`}
</p>
</div>
);
}States
A disabled field cannot be focused and is skipped by the keyboard, so use it only when the user can tell why it is unavailable. TextInput.ClearButton in an inner suffix appears once the field holds a value and hides again when it is empty or disabled; after clearing, focus returns to the input.
import { TextInput } from '@/components/ui/wideset/text-input/TextInput';
import { useState } from 'react';
export default function TextInputStates() {
const [name, setName] = useState('Website redesign');
return (
<div className="gap-ws-12 flex w-[20rem] max-w-full flex-col">
<TextInput placeholder="Project name" aria-label="Project name" />
<TextInput disabled placeholder="Project name" aria-label="Project name" />
<TextInput value={name} onChange={(event) => setName(event.target.value)}>
<TextInput.Input placeholder="Project name" aria-label="Project name" />
<TextInput.Suffix inner>
<TextInput.ClearButton />
</TextInput.Suffix>
</TextInput>
</div>
);
}API reference
TextInput
| Name | Description | Default |
|---|---|---|
children | Compound subcomponents (`TextInput.Prefix`, `TextInput.Input`, `TextInput.Suffix`, …). When omitted, a default `<input>` is rendered. Input props and the `ref` given to the root reach `TextInput.Input` too; a prop set on `TextInput.Input` wins. Use one `TextInput.Input` per field. ReactNode | — |
className | Layout/context overrides for the outer container. Visual styling goes through `variant`, `preset` and `size`. string | — |
defaultMotion | Turns the component's built-in animations on or off. When omitted, inherits the value from the nearest `MotionProvider`. boolean | true |
preset | 'border''ghost' | 'border' |
size | 'sm''md''lg' | 'md' |
variant | 'primary''danger' | 'primary' |
<input> is passed through to it. See MDN: <input>.TextInput.Button
| Name | Description | Default |
|---|---|---|
asChild | Whether to render the button styling onto its child element via Radix Slot. boolean | — |
children | Button label or custom content rendered inside the root. ReactNode | — |
className | Additional CSS classes merged with the button root. string | — |
defaultMotion | Turns the component's built-in animations on or off. When omitted, inherits the value from the nearest `MotionProvider`. boolean | true |
disabled | Disables the button visually and functionally. boolean | — |
onClick | Called when the user activates the button. MouseEventHandler<HTMLButtonElement> | — |
preset | 'border''filled''ghost' | — |
size | 'xs''sm''md''lg' | — |
type | Native button type used for form behavior. 'button''submit''reset' | — |
variant | 'primary''secondary''danger''success''inverse' | — |
TextInput.ClearButton
| Name | Description | Default |
|---|---|---|
aria-label | Defines a string value that labels the current element. Accessible action name. Provide this or `aria-labelledby`. Accessible label. Defaults to `'Clear'`. string | — |
aria-labelledby | Identifies the element (or elements) that labels the current element. ID of the element naming the action. Provide this or `aria-label`. string | — |
className | Additional CSS classes merged with the icon button root. Layout/context overrides for the button. string | — |
defaultMotion | Turns the component's built-in animations on or off. When omitted, inherits the value from the nearest `MotionProvider`. boolean | true |
icon | Icon rendered inside the clear button. Defaults to `RiCloseLine`. RemixiconComponentType | — |
iconClassName | Additional CSS classes merged with the rendered icon. Layout/context overrides for the icon. string | — |
onClear | Called after the value is cleared and the input's `onChange` has run with an empty value, in both controlled and uncontrolled modes. Use it for side effects such as resetting filters; validate in `onChange`, which also sees a value deleted by hand. (() => void) | — |
onClick | Called when the user activates the icon button. Runs before the field is cleared. Call `event.preventDefault()` to keep the value, for example while a save is in progress. MouseEventHandler<HTMLButtonElement> | — |
type | Native button type used for form behavior. 'button''submit''reset' | — |
<button> is passed through to it. See MDN: <button>.TextInput.IconButton
| Name | Description | Default |
|---|---|---|
icon* | Icon rendered as the main visible content of the button. RemixiconComponentType | — |
aria-label | Defines a string value that labels the current element. Accessible action name. Provide this or `aria-labelledby`. string | — |
aria-labelledby | Identifies the element (or elements) that labels the current element. ID of the element naming the action. Provide this or `aria-label`. string | — |
asChild | Whether to render onto a child via Radix Slot. Set its accessible name on IconButton; it is forwarded to the child. boolean | — |
children | Optional child element used when `asChild` is enabled. ReactNode | — |
className | Additional CSS classes merged with the icon button root. string | — |
defaultMotion | Turns the component's built-in animations on or off. When omitted, inherits the value from the nearest `MotionProvider`. boolean | true |
disabled | Disables the icon button visually and functionally. boolean | — |
iconClassName | Additional CSS classes merged with the rendered icon. string | — |
onClick | Called when the user activates the icon button. MouseEventHandler<HTMLButtonElement> | — |
preset | 'border''filled''ghost' | — |
size | 'xs''sm''md''lg' | — |
type | Native button type used for form behavior. 'button''submit''reset' | — |
variant | 'primary''secondary''danger''success''inverse' | — |
TextInput.Icon
| Name | Description | Default |
|---|---|---|
icon* | The icon to render inside a `TextInput.Prefix` / `TextInput.Suffix`. Sized automatically from the input's `size`. RemixiconComponentType | — |
className | Layout/context overrides for the icon. string | — |
TextInput.Input
| Name | Description | Default |
|---|---|---|
className | Additional CSS classes merged with the rendered element. string | — |
<input> is passed through to it. See MDN: <input>.Accessibility
- Every field needs a name:
FormFieldwithhtmlFormatching the inputid, oraria-label. TextInput.IconButtonneedsaria-labeloraria-labelledby.TextInput.ClearButtondefaults to “Clear”; translate it witharia-label.TextInput.Iconis hidden from screen readers.- Use
type="search"on a search field: it is announced as search and gets a search key on mobile keyboards.
| Part | Renders | Description |
|---|---|---|
| TextInputRenders no element | <input> | `defaultValue` is omitted: without `value` the field keeps its own value, starting empty. To start with a value, control it with `value` + `onChange`. |
| TextInput.ButtonRenders no element | — | A text action within the input. |
| TextInput.ClearButtonRenders no element | <button> | The action clearing the input value. |
| TextInput.IconButtonRenders no element | — | An icon action within the input. |
| TextInput.IconRenders no element | — | An icon rendered within `TextInput`. |
| TextInput.InputRenders no element | <input> | The native input inside a composed field. |
import { RiSearchLine } from '@remixicon/react';
import { TextInput } from '@/components/ui/wideset/text-input/TextInput';
<TextInput>
<TextInput.Prefix inner>
<TextInput.Icon icon={RiSearchLine} />
</TextInput.Prefix>
<TextInput.Input placeholder="Search projects" />
</TextInput>