Field
A component that provides labeling and validation for form controls.
<?phem
use Phem\Attribute\Component;
use Phem\Node;
use Phem\Ui\Field;
use function Phem\Ui\{FieldControl, FieldDescription, FieldError, FieldLabel};
#[Component]
function FieldHeroDemo(): Node
{
return (
<Field id="name">
<FieldLabel>Name</FieldLabel>
<FieldControl required placeholder="Required" />
<FieldError match="valueMissing">Please enter your name</FieldError>
<FieldDescription>Visible on your profile</FieldDescription>
</Field>
);
}
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.
| Prop | Type | Default |
|---|---|---|
validationMode | ?string | null |
validationDebounceTime | int | 0 |
disabled | bool | false |
id | ?string | null |
children | ?Html | null |
...attrs | array | [] |
FieldLabel#
The label of the control of the Field. It points to the control (for).
| Prop | Type | Default |
|---|---|---|
children | ?Html | null |
...rest | mixed | — |
FieldDescription#
The help text of the Field. The control gets it as its aria-describedby.
| Prop | Type | Default |
|---|---|---|
children | ?Html | null |
...rest | mixed | — |
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.
| Prop | Type | Default |
|---|---|---|
match | ?string | null |
children | ?Html | null |
...rest | mixed | — |
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.
| Prop | Type | Default |
|---|---|---|
value | ?Bound | null |
...rest | mixed | — |
FieldItem#
A control of a group of choices in a field, such as a checkbox with its label: Base UI Field.Item.
| Prop | Type | Default |
|---|---|---|
children | ?Html | null |
...rest | mixed | — |
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.
| Prop | Type | Default |
|---|---|---|
validationMode | ?string | null |
children | ?Html | null |
...rest | mixed | — |
The source of the examples: examples/ui/Field.phem.