Skip to the content
human-kit design
08 — Form

Input

A text field, in a box, in place or over a line.

Installation

pnpm dlx @human-kit/design add input
npx @human-kit/design add input
yarn dlx @human-kit/design add input
bunx @human-kit/design add input

The 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 default in a form, on the page or on a card.
  • Use filled for a form that should read lighter than a stack of boxes: a soft grey, no edge.
  • Use ghost for a value edited in place, in a row that would jump if a box came and went around it.
  • Use underline on a surface that is already a box, where a boxed field would draw a frame inside a frame.
  • Use sm in a toolbar or a dense row, and lg for the one field a screen is about, such as its search. Match the size of the buttons beside it.
  • Put it in a Field.Root in a form: the label, the hint and the error come wired to it.

Accessibility

  • It renders a native <input>, so every type and the browser's own behaviour come with it.
  • It needs a name: a <label for>, a Field.Root, or aria-label when there is no visible label.
  • invalid, required and readonly set aria-invalid, aria-required and aria-readonly with 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. disabled takes it out.

API reference

PropTypeDefault
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'
valueHTMLInputAttributes['value']

The value, a string, or a number for a type="number". Bindable.

—
invalidboolean

Marks the value as wrong: a red ring and aria-invalid.

false
readonlyboolean | null

Shows the value in a grey box. It can be focused and copied, not changed.

—
requiredboolean | null

The native required, with aria-required.

—
disabledboolean | null

Turns the field off and takes it out of the tab order.

—
elementHTMLInputElement | null

The rendered element. Bindable.

—

Plus every attribute of a native <input>.