Skip to content

Field

Shared parts for form fields: the label, the field shell, inset buttons, and a hint line that trades places with the error without moving anything.

Label, shell, inset buttons and a message line

The table seats 12.The table seats 12. Remove a guest or add a table.

Go above 12: the hint and the error trade places and nothing below moves.

Installation

With UI Polish connected, ask your agent:

Add the UI Polish field to this project.

Or with the shadcn CLI:

npx shadcn@latest add https://uipolish.com/r/field.json
Brings inIcons

The shared parts of the form fields that hold more than one input: combobox, date picker, number input, phone input and radio group use it. It has no look of its own beyond what those fields share.

  • FieldMessage: the line under a field. Hint and error share one grid cell and crossfade, so an error appearing moves nothing. The line is reserved whenever the field renders it; set --field-message-lines on the field to reserve more when a longer error can arrive. Text field and select use it too.
  • field.module.css, composed into a component's classes: field, label: the stack and its label (8px apart, label 14px). shell: the edge of a field that holds buttons or a picker. Focus anywhere inside fills it with --ui-field-focus-fill, at once, and the edge stays as it rests; data-open holds the fill while a popover is open; data-invalid turns the edge to danger. Sets --shell-inset, the gap from the edge to a 32px button. bare: a text input with no edge, for inside a shell. 16px on touch screens so iOS doesn't zoom. inset: a 32px icon button for inside a field, panel or banner. The fill is a layer under the icon, so a press shrinks only the fill (--ui-scale-press). 40px hit area on touch screens. Set its radius to the outer radius less the inset.
TSX
<div className={styles.field}>  <label className={styles.label} htmlFor={id}>Guests</label>  <div className={styles.shell} data-invalid={error ? "" : undefined}>…</div>  <FieldMessage id={`${id}-message`} hint="The table seats 12." error={error} /></div>

Link the message with aria-describedby only while it has text.

Layout

A field is one column as wide as its container: the input narrows with it rather than holding its default width of about 20 characters.