Input
Text inputs in three sizes, with invalid and monospace variants, that a Field wires up.
Demo
Usage
import { Button, ButtonGroup, Field, Input } from '@tuttn/slant'
// Controlled, in a Field: the label, description and error are wired for you.
<Field invalid={name.length < 3} required>
<Field.Label>Workspace name</Field.Label>
<Input value={name} onChange={event => setName(event.target.value)} />
<Field.Description>Shown in the sidebar and in invites.</Field.Description>
<Field.Error>Three characters or more.</Field.Error>
</Field>
// Uncontrolled: a defaultValue (or nothing), read from the form or a ref.
<Input name="workspace" defaultValue="aftur-web" ref={inputRef} aria-label="Workspace" />
// Sizes on the control scale; htmlSize is the native width in characters.
<Input size="sm" aria-label="Filter" />
<Input size="lg" htmlSize={12} aria-label="Code" />
// In an attached ButtonGroup, the input joins the bar.
<ButtonGroup attached>
<Input mono defaultValue="sk_live_7f2a…9c1e" readOnly aria-label="API token" />
<Button>Copy</Button>
</ButtonGroup>Props
| Prop | Type | Default | Description |
|---|---|---|---|
invalid | boolean | — | Sets aria-invalid and a danger border. Inside a Field, the field's `invalid` does this and points the input at its error. |
mono | boolean | — | Monospace text, for tokens, ids and codes. |
size | 'sm' | 'md' | 'lg' | 'md' | Height on the control scale: 28, 34 or 40px at regular density. Inside an InputGroup or a ButtonGroup, the group's size. |
htmlSize | number | — | The native `size` attribute: the input's width in characters. |
…rest | InputHTMLAttributes | — | value, defaultValue, onChange, placeholder, type, name and every other input attribute pass through; the ref reaches the <input>. |
size is the height on the control scale (28, 34 or 40px at regular density), as on Button; the native size attribute, the width in characters, is htmlSize. The input fills its container unless it sits in a bar that sizes it.
Give it a visible label: inside a Field it takes the label, the description, the error (while invalid), and the field's disabled, required and read-only states; on its own, name it with a Label htmlFor or aria-label. Inside an InputGroup it is the bare field between the addons and takes the group's size. In an attached ButtonGroup it shares borders with the buttons beside it and takes the group's size. For one-time codes use Code input; for numbers, Number input; for search, Search field; for several lines, Textarea.