Skip to content
TopClass UI

Input

A native input that renders on the server and ships 0 KB of JavaScript. The types refuse one with no name.

server - 0 KB

Input

server - 0 KB

A native input that renders on the server and ships 0 KB of JavaScript. The types refuse one with no name.

Install

Try it

size
invalid
fullWidth

The code

input.tsx
import { Input } from 'topclassui/input'

<div className="grid max-w-sm gap-1">
  <label htmlFor="input-playground" className="text-sm font-medium text-body">Email</label>
  <Input id="input-playground" name="email" type="email" autoComplete="email" />
</div>

Outside a Field, Input needs id, aria-label or aria-labelledby: the types reject an unlabelled one.

Every state

6 states

Import from the package

topclassui/input
import { Input } from 'topclassui/input'

Install once:npm i topclassui@beta zod

Examples

  • maxLength has a default per type: text 512, email 254, tel 32, url 2048, search and password 256. Pass your own number, or maxLength={null} for no cap.
  • A number, a date or a checkbox takes no character cap: a number is bounded by min, max and step.
  • It keeps its own width, --tc-input-width, and less in a narrow row. fullWidth fills the container; beside a Button, give the Input flex-1.
  • size="custom" emits no size classes, so your own classes set the height, the padding and the type step.
  • A parent with overflow-hidden needs 4px of padding, or it cuts the focus ring off.
labelled
We never share it
types
sizes
full-width
row
custom-size
skeleton
In Arabic, right to left

Props

The props of Input
PropTypeDefaultLimitsDescription
aria-labelstring--The name read out when no visible label names the control.
aria-labelledbystring--The id of the visible text that names the control.
idstring--The id a <label htmlFor> points at.
fullWidthbooleanfalse-Stretches the input to the width of its container.
invalidbooleanfalse-Marks the value as wrong: sets aria-invalid, and the border turns to danger and thickens.
maxLengthnumber | null--The character cap: your number, the default of the type, or null for none.
sizexs | sm | md | lg | xl | custom"md"-The shared control scale; custom emits no size classes.

Keyboard and accessibility

The keyboard of Input
KeysWhat it does
TabMoves the focus to the field, and on to the next control.
EnterSubmits the form the field is in, as a native input does.
  • A name is required: a <label htmlFor> pointing at id, or aria-label, or aria-labelledby.
  • invalid sets aria-invalid, and the border turns to danger and thickens, so the error does not rest on colour alone.
  • On a touch screen the text is at least 16px, so iOS does not zoom the page on focus.

Right to left

The text starts at the right. Email, number, tel and url fields stay left to right, on the form's side.

Server and client

Renders on the server and ships no JavaScript.

Files: index.tsx.

On the chip: server - 0 KB.