Skip to content
Slotted

Field

Names a control, says whether it is required, and carries the description and the error a reader hears with it.

Invoices are sent to this address.

Installation

The packages are a 0.x beta on npm, and their public API changes between beta releases without deprecation. One line installs the binding and the default theme.

bash
pnpm add @slotted/react @slotted/theme @slotted/themes
tsx
import { Field, FieldAction, FieldControl, FieldCounter,  FieldDefaultsProvider, FieldDescription, FieldError, FieldHeader,  FieldHelp, FieldIndicator, FieldLabel } from '@slotted/react';

Necessity

A required field draws an asterisk after its label by default, and the control carries aria-required, so a screen reader announces “required” and never reads the asterisk. In a form where most fields are required, set necessity="optional" to mark the exception instead: (optional) appears on the fields a reader may skip and nothing appears on the rest. necessity="words" writes (required) and (optional) in full.

Label placement

labelPlacement="side" puts the label in a column beside its control, so the labels of a settings form line up and the controls start on one edge. A description stays under the control, not under the label.

Invoices and payment receipts are sent here.

Narrow containers

A side label stacks above its control when the field itself is narrower than 320 pixels. The field measures its own width, not the window’s, so the same field keeps its side label in a page and stacks in a two-column row, a drawer or a phone screen without a prop change.

Sizes

size sets the label, the messages and the counter to the step of the control they belong to: sm for dense tables and toolbars, md for most forms, lg for sparse forms. The library’s controls inside a field take the same size, so one prop sizes both.

States

invalid sets aria-invalid on the control and draws it in the danger tone; the label keeps its color, because the error already says what is wrong. readOnly sets the native readonly, so the value stays focusable and copyable. disabled sets the native disabled, which takes the control out of the tab order and out of form submission. Set the state on the field, not on the control.

Error:Six digits are missing.

Quote this ID when you contact support.

Only the workspace owner can change the URL.

Description and error

A description says what to enter, and an error says what is wrong with what was entered. Both sit under the control and join its accessible description, in that order. An error that does not block submission takes tone="warning".

Printed on the invoice so your accounts team can match it.

Five digits, as on the shipping label.

Error:Enter all five digits.

Warning:Above 40% the order waits for a manager's approval.

Validation on submit

Validate when the form is submitted, then set invalid and write the error. live="polite" announces the error once when it appears, and reserve keeps a line open for it, so the button below does not move. Submit the empty form, then type a valid address and submit again.

Error:

Help

A help button beside the label holds guidance that would crowd the description line. It opens a tooltip on hover and on keyboard focus, and a press keeps it open until a second press, Escape or a press elsewhere. A disabled field keeps its help operable, so it can say why the field is off.

Label row

A header holds the label with the parts that stand beside it: an indicator such as a Beta badge, and an action such as a link or a button at the end of the row. The action keeps type="button", so it never submits the form, and it stays operable when the field is disabled.

Beta

Counter

A text field or textarea with showCount publishes its length and the field draws the count at the end of the label row. For any other measure, such as words or tags, write the counter yourself and set its invalid when the count passes its limit. The count joins the control’s accessible description.

65/140
3/5 tags

Separate tags with commas.

Controls

Select, number field, date picker, textarea and text field read the field they sit in: they take its identifiers, its description and its states with no wiring.

Cases of 24 bags.

mm
dd
yyyy

Your own control

A control the library does not ship takes the same wiring through the field’s control part: the identifier the label points at, the accessible description and the states. An attribute written on the control wins over the one the field would set.

Used on invoices and in the customer portal.

Defaults for a section

A defaults provider sets size, labelPlacement, necessity, disabled and readOnly once for every field under it. A field that states a value of its own keeps it.

Accessibility

  • No WAI-ARIA Authoring Practices pattern covers a field. Four sources cover it together: the Authoring Practices’ Providing Accessible Names and Descriptions practice (w3.org/WAI/ARIA/apg/practices/names-and-descriptions/) for the label and the description, the HTML specification for label[for] and fieldset[disabled], and WCAG 2.2 Understanding 3.3.1 Error Identification and 3.3.2 Labels or Instructions for the error and the help.
  • The label is associated explicitly. The naming practice records that some combinations of assistive technology and browser do not treat the implicit form, a label wrapping its control, as an accessible name, so the field derives an identifier and points for at it instead of nesting.
  • Field writes aria-required, never the native required. The native attribute turns on browser constraint validation and changes how the form submits, which describing a field must not do as a side effect. To get it, write required on the control: an explicit value on the control always wins. disabled and readonly are native, because taking a control out of the tab order and out of submission is what those attributes mean.
  • The accessible description is the indicator, the help, the description, the count and the error, in that order, whatever order the page writes them in. Each slot has one correct reading order, and deriving the order from registration would make what a reader hears depend on when an effect ran. The count is included so a counter is related to its control by identifier.
  • The help, the indicator and the action stand beside the label, never inside it. HTML forbids labelable content such as a button inside a label other than the control it labels, and a press on it would reach the label and move focus to the control instead of opening the hint.
  • The help is a toggletip. A tooltip alone opens on a touch screen only on a long press, because a tap triggers the element’s own action; the help button has no other action, so a press opens the hint and a second press closes it. The help text also sits in a hidden node inside the button, which describes the button and the control while the tooltip is closed, because a hidden element referenced directly still enters the description. The tooltip describes nothing, so the hint is never read twice.
  • A disabled field leaves its help and its action operable, because the help often explains why the field is disabled.
  • The necessity asterisk is hidden from assistive technology and the necessity words are not. A reader working through a form of twenty required fields does not need to hear “asterisk” twenty times, and aria-required already states the fact; (optional) is information no other attribute supplies.
  • The error is text in the page, as WCAG 2.2 SC 3.3.1 requires, never a tooltip. As an InlineMessage it also carries the severity as visually hidden text, so a reader who cannot see the red ink hears “Error:” before the sentence.
  • live defaults to off, because a message present when the page finishes loading is not announced whatever role it carries. A form that shows the error after submit sets live="polite", and the reader hears it once rather than on every render.

API

Field

Props

size'sm' | 'md' | 'lg'Default md
The type step, matching the control the field wraps. The label, the messages and the counter read the control type scale, which the theme restates per density.
labelPlacement'top' | 'side'Default top
Where the label sits. side reflows to top when the field’s own inline size is below 320 pixels; the query is a container query, not a viewport query.
necessity'mark' | 'optional' | 'words' | 'none'Default mark
How necessity is written: an asterisk on a required field, (optional) on a field a reader may skip, both words, or nothing, for a form that says once that every field is required.
width'short' | 'medium' | 'full'Default full
The longest the control stands, as a cue to the length of its answer: short (--slotted-field-width-short, 6rem) for an integer of up to four digits, medium (--slotted-field-width-medium, 15rem) for an amount, a code or a short word, full for free text, a name or a picker of records. The control still shrinks below the bound in a narrower field.
messagesPartial<FieldMessages>
Words that replace the active language’s, key by key: the necessity words (optional, required) and the help button’s name (help).
requiredboolean
Unset rather than false. Writes aria-required on the control, never the native required, which would turn on browser constraint validation and change how the form submits.
invalidboolean
On Field, FieldCounterOn Field: unset rather than false; writes aria-invalid on the control and data-invalid on the field, and leaves the label’s color unchanged. On FieldCounter: the count has passed its limit, which can happen before validation runs, so it is the counter’s own state and defaults to false.
disabledbooleanDefault from the group, then the provider
On Field, FieldDefaultsProviderUnset rather than false, so a field follows the FieldGroup around it. A stated value wins, and it reaches the control as the native attribute.
readOnlybooleanDefault from the group, then the provider
On Field, FieldDefaultsProviderUnset rather than false. Reaches the control as the native readonly, which keeps the value focusable and copyable.
idstringDefault generated
The base of every identifier the field derives: <id>-control, <id>-label, <id>-indicator, <id>-help, <id>-description, <id>-counter and <id>-error. Generated with useId when unset.
childrenReactNode
On FieldHelpThe help text. Written once, it reaches the tooltip and the hidden node that describes the button and the control.
openboolean
On FieldHelpWhether the hint is showing, controlled. Pair it with onOpenChange; leave both unset and FieldHelp owns the state.
defaultOpenbooleanDefault false
On FieldHelpWhether the hint starts open, read once when FieldHelp owns the state.
presentation'toggletip' | 'auto'Default toggletip
On FieldHelpauto draws the hint as a bottom sheet under (max-width: 480px) and (pointer: coarse): modal, headed by the field’s label beside a close control, dismissed by its grip, its scrim, Escape and the platform’s way back, with focus given back to the help button. Anywhere else it is the toggletip.
helpPresentation'toggletip' | 'auto'Default toggletip
On FieldDefaultsProviderThe presentation of every FieldHelp inside, unless a FieldHelp states its own.
side'top' | 'bottom' | 'inline-start' | 'inline-end' | 'left' | 'right'Default top
On FieldHelpWhere the hint opens. It flips to the opposite side when there is no room.
aria-labelstringDefault messages.help
On FieldHelpThe accessible name of the help button. Unset, it is the field’s help message; set, it applies to this button alone.
type'button' | 'submit' | 'reset'Default button
On FieldActionbutton by default, so the action never submits the form it sits in. A link rendered through render receives the props without it.
tone'accent' | 'secondary' | 'success' | 'warning' | 'danger'Default secondary on FieldDescription, danger on FieldError
On FieldDescription, FieldErrorBoth messages are InlineMessage roots and take its five tones, so a warning that does not block submission is FieldError with tone="warning".
mark'glyph' | 'dot' | 'none'Default none
On FieldDescription, FieldErrorThe mark the message draws. A field’s messages draw none by default: an icon repeated under every control of a form reads as texture, and the ink and the sentence already state the tone. glyph draws the tone’s icon at the text size, and dot draws one neutral bullet.
live'off' | 'polite' | 'assertive'Default off
On FieldDescription, FieldErrorWhether the message announces itself. off by default, because a message present when the page loads is not announced whatever role it carries.
reservebooleanDefault false
On FieldDescription, FieldErrorKeeps one line open whether or not there is a message, so a form that renders its error unconditionally does not move when the error appears.

Events

NamePayloadWhen
onOpenChange(open: boolean, request: TooltipChangeRequest)On FieldHelp, before the hint opens or closes, once per transition. request.reason is pointer for a hover or a press; keyboard for focus, Enter or Space; or escape, blur or programmatic. The sheet of presentation="auto" also reports outsidePress for a press on its scrim, and dismiss for its close control and the platform’s way back. request.cancel() refuses the change.

Composition

render(props) => ReactNode
On Field, FieldHeader, FieldLabel, FieldIndicator, FieldAction, FieldControl, FieldCounterReplaces the rendered element and hands it every attribute: a textarea as the control, an output as the counter, a link as the action, a fieldset as the field. The props are typed as HTMLAttributes<HTMLElement>, so they spread onto any element. FieldHelp has no render: its button carries the name, the description and the tooltip control, and all three belong to Field.
onClick and the pointer and focus handlersnative
On FieldHelp, FieldActionThe consumer’s handler runs first and the field’s after it, unless the consumer called preventDefault.
useField()() => FieldContextValue | undefined
On any component inside a FieldReturns the identifiers, the description and the four states, so a control Slotted does not ship wires itself without a wrapper. Returns undefined outside a field, so the same control also works alone.
FieldDefaultsProvider{ size, labelPlacement, necessity, disabled, readOnly }
On a subtreeThe five decisions an application takes once for every field under it. FieldGroup renders one for the fields inside it, so a compact or disabled section is one prop instead of one per field.
refRef<HTMLElement>
On every partReaches the default element; on FieldHelp, the button. A part rendered through render is the consumer’s element, so the consumer attaches its ref there. There is no imperative handle: the one state Field holds, the hint, is controlled through open and onOpenChange.

Parts

PartElementRequiredPurpose
rootdiv, or the element render returnsYesThe field. It carries data-ui="field", the three axes, and data-disabled, data-invalid, data-required and data-readonly. It is its own size container, so a side label reflows on the field’s width rather than the window’s.
headerdiv, or the element render returnsNoThe label row, written when the label has company: the help, an indicator, an action and the counter. It aligns them on the label’s first baseline, wraps when it runs out of room, and puts the action and the count at its end. A field whose label stands alone writes the label on the root and no header.
labellabelNoNames the control through for, which points at the derived control identifier. The WAI-ARIA Authoring Practices name the explicit association as the one with the broadest support; some assistive technologies fail to treat the implicit one, a label wrapping its control, as a name.
markspan, inside the labelNoThe necessity marker the label draws: an asterisk on a required field, (optional) on a field a reader may skip, or both words. The asterisk is aria-hidden because aria-required already states the fact; the words are read, because they carry information.
helpbutton, fixedNoA circle-question button beside the label that shows the field’s help in a tooltip. It opens on hover and on keyboard focus, and a press keeps it open until a second press, Escape or a press elsewhere. A hidden node inside the button carries the same words, so the button and the control are described by the help whether the tooltip is open or not.
indicatorspan, or the element render returnsNoWhat qualifies the field, such as Beta, Pro or New, as one or more Badges after the label. It sits outside the label, so the necessity mark stays against the last word, and it joins the control’s description, so a reader on the control hears it.
actionbutton type="button", or the element render returnsNoA link or a button at the end of the label row, such as Forgot password? or Generate. Its accent ink darkens by a third on hover, with the underline drawn, and by two thirds on press. The field does not disable it with the control.
controlinput, or the element render returnsNoA control Slotted does not ship, wired by FieldControl. Slotted’s own controls read the field themselves and need no wrapper. The field gives the control an identifier, a description, aria-invalid, aria-required, disabled and readonly, and overwrites nothing the consumer stated.
counterspan, or the element render returnsNoThe count, at the end of the label row, where IBM Carbon also places it, and inside the header when there is one. A control with showCount publishes its count and the field draws it; a page that counts words or bytes writes its own FieldCounter. The count joins the control’s description and carries its own data-invalid, because a count can pass its limit before validation runs.

Theming

Each token is a CSS custom property: set it in a theme, or on any element to retune every field inside it.

Field tokens

TokenDefault
--slotted-field-action-colorvar(--slotted-tone-accent-text, LinkText)
--slotted-field-action-color-activecolor-mix(in oklab, var(--_rest) 35%, var(--slotted-text, CanvasText))
--slotted-field-action-color-hovercolor-mix(in oklab, var(--_rest) 65%, var(--slotted-text, CanvasText))
--slotted-field-action-radiusvar(--slotted-control-radius, 4px)
--slotted-field-column-gapvar(--slotted-space-5, 0.75rem)
--slotted-field-counter-colorvar(--slotted-text-muted)
--slotted-field-counter-invalid-colorvar(--slotted-tone-danger-text)
--slotted-field-font-familyvar(--slotted-control-font-family, sans-serif)
--slotted-field-header-gapvar(--slotted-space-3, 0.375rem)
--slotted-field-help-colorvar(--slotted-text-muted)
--slotted-field-help-radiusvar(--slotted-control-radius, 4px)
--slotted-field-help-surface-activevar(--slotted-tone-secondary-subtle-active, ButtonFace)
--slotted-field-help-surface-hovervar(--slotted-tone-secondary-subtle-hover, ButtonFace)
--slotted-field-icon-size-min14px
--slotted-field-label-colorvar(--slotted-text)
--slotted-field-label-font-weightvar(--slotted-font-weight-medium, 500)
--slotted-field-label-inline-size12rem
--slotted-field-line-heightvar(--slotted-line-height-sm, 1.45)
--slotted-field-mark-colorvar(--slotted-tone-danger-text)
--slotted-field-mark-gap0
--slotted-field-mark-text-colorvar(--slotted-text-muted)
--slotted-field-row-gapvar(--slotted-space-3, 0.375rem)
--slotted-field-width-medium15rem
--slotted-field-width-short6rem

Theme tokens it reads

TokenDefault
--slotted-control-font-familyvar(--slotted-font-family-sans)
--slotted-control-font-size-lgcomfortable 14px · compact 13px · dense 12px
--slotted-control-font-size-mdcomfortable 13px · compact 12px · dense 12px
--slotted-control-font-size-smcomfortable 12px · compact 12px · dense 12px
--slotted-control-height-lgcomfortable 38px · compact 32px · dense 30px
--slotted-control-height-mdcomfortable 34px · compact 28px · dense 26px
--slotted-control-height-smcomfortable 30px · compact 26px · dense 24px
--slotted-control-icon-size-mdcomfortable 16px · compact 14px · dense 13px
--slotted-control-icon-size-smcomfortable 14px · compact 13px · dense 12px
--slotted-control-inner-size-mdcomfortable 24px · compact 20px · dense 18px
--slotted-control-inner-size-smcomfortable 22px · compact 18px · dense 16px
--slotted-control-radiusvar(--slotted-radius-sm)
--slotted-control-transition-durationvar(--slotted-duration-short)
--slotted-control-transition-easingvar(--slotted-easing-standard)
--slotted-disabled-foregroundSet per scheme by the theme
--slotted-focus-ring-colorSet per scheme by the theme
--slotted-focus-ring-offsetvar(--slotted-border-width-thick)
--slotted-focus-ring-widthvar(--slotted-border-width-thick)
--slotted-font-size-xs0.75rem
--slotted-font-weight-medium500
--slotted-font-weight-regular400
--slotted-line-height-sm1.45
--slotted-space-10.125rem
--slotted-space-20.25rem
--slotted-space-30.375rem
--slotted-space-50.75rem
--slotted-target-comfortable44px
--slotted-target-min24px
--slotted-textSet per scheme by the theme
--slotted-text-mutedSet per scheme by the theme
--slotted-tone-accent-textSet per scheme by the theme
--slotted-tone-danger-textSet per scheme by the theme
--slotted-tone-secondary-subtle-activeSet per scheme by the theme
--slotted-tone-secondary-subtle-hoverSet per scheme by the theme