Input
A text field, in a box, in place or over a line.
Installation
pnpm dlx @human-kit/design add inputnpx @human-kit/design add inputyarn dlx @human-kit/design add inputbunx @human-kit/design add inputThe command copies the files to src/lib/components/ui/input. It also
installs the packages that the files import.
Usage
<script lang="ts">
import * as Input from '$lib/components/ui/input';
let email = $state('');
</script>
<label for="email">Email</label>
<Input.Root id="email" type="email" bind:value={email} /> Examples
Invalid
invalid turns the ring red and sets aria-invalid. Link the message with aria-describedby, or put the input in a Field.Root, which does both from its error.
The tax ID needs 9 digits.
Guidelines
- Use
defaultin a form, on the page or on a card. - Use
filledfor a form that should read lighter than a stack of boxes: a soft grey, no edge. - Use
ghostfor a value edited in place, in a row that would jump if a box came and went around it. - Use
underlineon a surface that is already a box, where a boxed field would draw a frame inside a frame. - Use
smin a toolbar or a dense row, andlgfor the one field a screen is about, such as its search. Match the size of the buttons beside it. - Put it in a
Field.Rootin a form: the label, the hint and the error come wired to it.
Accessibility
- It renders a native
<input>, so everytypeand the browser's own behaviour come with it. - It needs a name: a
<label for>, aField.Root, oraria-labelwhen there is no visible label. invalid,requiredandreadonlysetaria-invalid,aria-requiredandaria-readonlywith the native attributes.- The focus ring shows on any focus, not only from the keyboard: the caret lands in the field either way.
- A read-only field drops its box but stays in the tab order, so its value can still be read and copied.
disabledtakes it out.
API reference
| Prop | Type | Default |
|---|---|---|
variant | 'default' | 'filled' | 'ghost' | 'underline' The box around the value, or none. | 'default' |
size | 'sm' | 'default' | 'lg' The height and the type, matching the buttons of the same size. | 'default' |
value | HTMLInputAttributes['value'] The value, a string, or a number for a | — |
invalid | boolean Marks the value as wrong: a red ring and | false |
readonly | boolean | null Shows the value in a grey box. It can be focused and copied, not changed. | — |
required | boolean | null The native | — |
disabled | boolean | null Turns the field off and takes it out of the tab order. | — |
element | HTMLInputElement | null The rendered element. Bindable. | — |
Plus every attribute of a native <input>.