Skip to content
navius

Form

Collect information from your users with native constraint validation, reported through ARIA (aria-describedby, aria-invalid).

Features

  • Renders a native <form>; Enter-to-submit and tab order come for free.
  • Surfaces the browser's built-in ValidityState (valueMissing, typeMismatch, …) with zero validation code.
  • Messages register into aria-describedby while shown and clear when they stop matching.
  • Server errors via ServerInvalid, or a form-wide Errors map keyed by field name, that auto-clear on the next edit.
  • An invalid submit is blocked and focus moves to the first invalid control automatically.

Installation

Reference the Navius.Primitives package for the headless primitive, or vendor its source with the CLI: navius add copies the brain files it depends on.

Anatomy

Import the parts and assemble them.

API Reference

Wraps the whole form. Renders a native form element and manages the submit, validation and focus flow.

Prop Type Default
OnSubmit EventCallback -
Errors IReadOnlyDictionary<string, string[]>? -
OnClearErrors EventCallback -
PreventDefault bool true
ChildContent RenderFragment? -
Attributes IDictionary<string, object>? -

Groups a label, control and messages under one name. Renders a div.

Prop Type Default
Name string ""
Disabled bool false
Validity FieldValidity? -
Invalid bool false
ServerInvalid bool false
ValidationMode FieldValidationMode OnSubmit
ChildContent RenderFragment? -
Attributes IDictionary<string, object>? -
Data attribute Values
[data-disabled] Present when the field is disabled
[data-valid] Present when the field is valid
[data-invalid] Present when the field is invalid
[data-dirty] Present when the value differs from the control's initial value
[data-touched] Present once the control has been blurred at least once
[data-filled] Present when the control has a non-empty value
[data-focused] Present while the control has focus

The field's label. Renders a native label whose for points at the control.

Prop Type Default
ChildContent RenderFragment? -
Attributes IDictionary<string, object>? -
Data attribute Values
[data-disabled] Present when the field is disabled
[data-valid] Present when the field is valid
[data-invalid] Present when the field is invalid
[data-dirty] Present when the value differs from the control's initial value
[data-touched] Present once the control has been blurred at least once
[data-filled] Present when the control has a non-empty value
[data-focused] Present while the control has focus

The form control. Renders a native input wired with the field id and aria-* by default, or cascades ControlProps to a custom control via the render-fragment child.

Prop Type Default
ChildContent RenderFragment<ControlProps>? -
Attributes IDictionary<string, object>? -
Data attribute Values
[data-disabled] Present when the field is disabled
[data-valid] Present when the field is valid
[data-invalid] Present when the field is invalid
[data-dirty] Present when the value differs from the control's initial value
[data-touched] Present once the control has been blurred at least once
[data-filled] Present when the control has a non-empty value
[data-focused] Present while the control has focus

A validation message tied to a match. Renders a div only while its match fails, and joins aria-describedby while shown.

Prop Type Default
Match string? -
ForceMatch bool false
ChildContent RenderFragment? -
Attributes IDictionary<string, object>? -
Data attribute Values
[data-disabled] Present when the field is disabled
[data-valid] Present when the field is valid
[data-invalid] Present when the field is invalid
[data-dirty] Present when the value differs from the control's initial value
[data-touched] Present once the control has been blurred at least once
[data-filled] Present when the control has a non-empty value
[data-focused] Present while the control has focus

Render-prop exposing the field's live FieldValidity. Renders nothing itself.

Prop Type Default
ChildContent RenderFragment<FieldValidity>? -

The form's submit button. Renders a native button with type=submit.

Prop Type Default
ChildContent RenderFragment? -
Attributes IDictionary<string, object>? -
Data attribute Values
[data-navius-form-submit] Present on the submit button

Accessibility

Built on the native <form>, <label> and form controls, so the browser's own constraint-validation and accessibility semantics apply. The label's for points at the control id; active messages are referenced by aria-describedby; and an invalid control carries aria-invalid="true". A failed submit moves focus to the first invalid control.

Key Description
Enter Submits the form. When a field is invalid, submission is blocked and focus moves to the first invalid control.
Tab Moves focus to the next control in the form.