This documentation is under construction. Pages can be missing or change at any time. Follow it on GitHub.

Skip to content

Field

A component that provides labeling and validation for form controls.

API reference#

Import the components of the family:

use Phem\Ui\Field;
use function Phem\Ui\{FieldLabel, FieldControl, FieldDescription, FieldError, FieldItem, Form};

Field#

A form control with a label, a description and errors: Base UI Field.Root, on the phem-field controller. The browser validates the control (required, type="email", pattern…) in the validationMode (onSubmit, onBlur, onChange). An Input in a Field is its control.

Give an id to link the parts with ids, as in Base UI: the control gets <id>-control (in place of an id of the control), the label gets for, and the description and the errors get <id>-description and <id>-error (<id>-error-<match> for an error with match). A field has one control. Give two errors with the same match their own id. With no id, the controller links the parts with element references, and the for, aria-labelledby and aria-describedby attributes stay empty.

PropTypeDefault
validationMode?stringnull
validationDebounceTimeint0
disabledboolfalse
id?stringnull
children?Htmlnull
...attrsarray[]

FieldLabel#

The label of the control of the Field. It points to the control (for).

PropTypeDefault
children?Htmlnull
...restmixed—

FieldDescription#

The help text of the Field. The control gets it as its aria-describedby.

PropTypeDefault
children?Htmlnull
...restmixed—

FieldError#

An error message. With match (a ValidityState key, such as valueMissing), it shows for this error only. With no text, it shows the message of the browser.

PropTypeDefault
match?stringnull
children?Htmlnull
...restmixed—

FieldControl#

The control of the field: an Input with the width of the field. Bind it to a state of the app with phem:bind, as an Input.

PropTypeDefault
value?Boundnull
...restmixed—

FieldItem#

A control of a group of choices in a field, such as a checkbox with its label: Base UI Field.Item.

PropTypeDefault
children?Htmlnull
...restmixed—

Form#

A form that validates its fields before its submit: Base UI Form, on the phem-form controller. An invalid form does not send its onSubmit event, and the first invalid control gets the focus.

PropTypeDefault
validationMode?stringnull
children?Htmlnull
...restmixed—

The source of the examples: examples/ui/Field.phem.

Phem
Esc
↑↓ to navigate↵ to openEsc to close