Input

Text inputs, selects and textareas in a labeled field with a hint and an error.

You can change this later.

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/form-controls

Usage

import { FormField, Input } from "./ui/uicontext/components/FormControls.ts"
const Message = UiSchema.TaggedEnum({ ChangedEmail: { email: Schema.String } })export const EmailField = (h: Html.H<typeof Message.Type>, email: string) =>	FormField(h, { id: "invite-email", label: "Email", description: "We'll send the invitation here." }, (attrs) =>		Input(h)			.attrs({ ...attrs, type: "email", autocomplete: "email" })			.value(email)			.on("input", ({ value }) => Message.ChangedEmail({ email: value })))

Examples

With a hint and an error

The hint stays when an error appears. The input is marked invalid, and both are read with it.

Teammates mention you with @handle.

A handle can't have spaces.

Select

A native select, so the phone's own picker opens on touch screens.

Due dates and digests use it.

Saved as Europe/Lisbon.

Read-only and disabled

Read-only for a value people may copy but not change; disabled for one that doesn't apply right now.

Only an owner can change it.

API reference

InputView function

Options

Input options
NameTypeDescription
invalidbooleanMarks the value as wrong: a red border, and aria-invalid for assistive technology.
styleStyleStyleX styles applied after the control's own.

SelectView function

Options

Select options
NameTypeDescription
invalidbooleanMarks the value as wrong: a red border, and aria-invalid for assistive technology.
styleStyleStyleX styles applied after the control's own.

TextareaView function

Options

Textarea options
NameTypeDescription
invalidbooleanMarks the value as wrong: a red border, and aria-invalid for assistive technology.
styleStyleStyleX styles applied after the control's own.

InputGroupView function

Options

InputGroup options
NameTypeDescription
startstring—
endstring—
styleStyle—

FormFieldView function

Options

FormField options
NameTypeDefaultDescription
idrequiredstring—The control's id. The label, description and error take ids made from it.
labelrequiredstring—The label's text, which names the control.
descriptionstring—A hint under the control, read out with it.
errorstring—What's wrong with the value. Shown under the control, announced, and marks the control invalid.
hintstring—A short note at the end of the label's line: a count such as "12/48", or "Max 5 MB".
hintOverboolean—The hint warns, as a count past its limit does.
requiredboolean—An empty value is an error: a mark after the label, and aria-required on the control.
optionalboolean—May stay empty, said after the label: for a form where most fields are required.
status{ readonly tone: "pending" | "success"; readonly text: string }—Where an async check stands, in the error's place while there's no error: "Checking…", "acme is available".
layout"stacked" | "inline" | "inline-end"stackedWhere the label sits: above the control (text fields, selects, a radio group), or beside it, with the control first (a checkbox) or last (a switch in a settings row); stacked by default
groupboolean—The control is a group of controls (a radio group, a segmented control): a group can't be the target of a <label for>, so the label names it through aria-labelledby instead
labelStyleStyle—StyleX styles for the label: a row field's label that hides behind column headings.
styleStyle—StyleX styles for the field's wrapper.

Accessibility

  • Each field connects its label, hint and error to the control with for, aria-describedby and aria-invalid.
  • Errors are announced as they appear. Forms set novalidate, so your validation decides what to show.

Source