Repeating Fields

Rows of fields to add, remove and reorder by drag or keyboard, with a minimum and a maximum: invites, line items.

Invite teammates

They'll get an email with a link to join Northwind.

People to invite
2 of 10
Press up or down arrow to move this row.

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/repeating-fields

Usage

import { RepeatingFields } from "./ui/uicontext/components/forms/RepeatingFields.ts"
export const Links = <M, C extends View.Children<M>>(	h: Html.H<M>,	rows: ReadonlyArray<{ readonly id: string; readonly url: string }>,	field: (row: { readonly id: string; readonly url: string }, index: number) => C,	on: { readonly add: M; readonly remove: (id: string) => M; readonly move: (id: string, to: number) => M },) =>	RepeatingFields(h, {		id: "links",		legend: "Links",		noun: "link",		rows,		max: 5,		columns: "minmax(0, 1fr)",		row: field,		onAdd: on.add,		onRemove: on.remove,		onMove: on.move,	})

Examples

Invoice line items

Amounts and totals follow each keystroke. Type “ten” as a quantity, or leave a price empty and save.

Invoice INV-2048

Harbor & Pine Studio · due Jan 4, 2027

Line items
  1. $4,800.00
  2. $6,500.00
  3. $2,160.00
3 of 25
Press up or down arrow to move this row.
Subtotal
$13,460.00
Sales tax (8.875%)
$1,194.58
Total
$14,654.58

API reference

Options

RepeatingFields options
NameTypeDefaultDescription
idrequiredstring—The group's id, for its legend and live region
legendrequiredstring—Names the group: "Teammates", "Line items"
descriptionstring—A sentence under the legend
rowsrequiredReadonlyArray<{ readonly id: string }>——
nounrequiredstring—What one row is, for Add and for what's read out: "teammate", "line item"
minnumber0Fewer rows than this can't be removed down to; 0 by default
maxnumber—No more rows can be added past this
columnsrequiredstring—The column widths of a row's fields in a wide group, as a grid template
headingsstring[]—The field labels, once as column headings in a wide group
rowrequired(row: { readonly id: string }, index: number) => View.Children—A row's fields, in the order of columns
onAddrequiredMessage——
onRemoverequired(id: string) => Message——
onMove(id: string, to: number) => Message—Report a move: reordering shows only with it
footerView.Content—After the rows, beside Add: totals, or a note
disabledboolean——
styleStyle——

Source