AuroraUI. Components. Field
(Aurora UI v0.1.1)
View Source
Field family — text input, textarea, and the wiring that binds a label,
help text, and validation message to a control.
A form control is only accessible if its accessible name, its description, and
its error are programmatically associated. field/1 owns that association: it
derives deterministic ids from a single base and hands them down to whatever
control the caller places in its slot, so the label points at the control, the
help is referenced through aria-describedby, and the error is referenced
through aria-errormessage alongside aria-invalid.
Semantics
input/1 and textarea/1 render real <input> / <textarea> elements so
browser and assistive-technology behavior (typing, autofill, form
submission, validation) come from the platform. They integrate with a
Phoenix.HTML.FormField (deriving id/name/value/errors) or with explicit
name/value. Used standalone they can render their own help/error/count;
used inside field/1 they receive the association ids and let the wrapper own
the surrounding text. field_error/1 uses role="alert" so a newly rendered
validation message is announced.
Summary
Functions
Wraps a control with an associated label, help text, and error message.
A validation message. Uses role="alert" so it is announced when it appears;
reference its id from the control's aria-errormessage.
Supporting help text for a control. Give it an id and reference that id from
the control's aria-describedby.
A single-line text control. Supports type (text/email/password/url/tel/number/search),
prefix/suffix adornments, a live-ready character count, and every relevant
state: hover, focus, filled, disabled, readonly, and invalid.
A control label. Renders a real <label for> and, when asked, a required or
optional indicator with a screen-reader-friendly equivalent.
A multi-line text control. Same association, count, and state handling as
input/1. Set autosize to opt into an optional grow-to-fit enhancement.
Functions
Wraps a control with an associated label, help text, and error message.
Splat the slot argument onto the control so the ids line up:
Examples
<.field :let={f} id="email" label="Email" help="We never share it." required>
<.input {f} type="email" name="user[email]" />
</.field>
<.field :let={f} id="bio" label="Bio" error={@errors[:bio]}>
<.textarea {f} name="user[bio]" />
</.field>Attributes
id(:string) - base id; control/label/help/error ids derive from it deterministically. Defaults tonil.label(:string) - visible label text. Defaults tonil.help(:string) - supporting hint rendered under the control. Defaults tonil.error(:string) - validation message; when present the field is marked invalid and wired via aria-errormessage. Defaults tonil.required(:boolean) - shows a required indicator on the label. Defaults tofalse.optional(:boolean) - shows an (optional) hint on the label; ignored when required. Defaults tofalse.- Global attributes are accepted.
Slots
inner_block(required) - The control. Receives a map%{id, invalid, describedby, errormessage, required}that can be splatted ontoinput/1ortextarea/1to complete the wiring.
A validation message. Uses role="alert" so it is announced when it appears;
reference its id from the control's aria-errormessage.
Examples
<.field_error id="email-error">Enter a valid email.</.field_error>Attributes
id(:string) - Defaults tonil.- Global attributes are accepted.
Slots
inner_block(required)
Supporting help text for a control. Give it an id and reference that id from
the control's aria-describedby.
Examples
<.help_text id="pw-help">Use at least 12 characters.</.help_text>Attributes
id(:string) - Defaults tonil.- Global attributes are accepted.
Slots
inner_block(required)
A single-line text control. Supports type (text/email/password/url/tel/number/search),
prefix/suffix adornments, a live-ready character count, and every relevant
state: hover, focus, filled, disabled, readonly, and invalid.
Examples
<.input name="q" type="search" placeholder="Search" />
<.input field={@form[:email]} type="email" autocomplete="email" />
<.input name="handle" show_count maxlength={30} value={@handle}>
<:prefix>@</:prefix>
</.input>Attributes
id(:string) - Defaults tonil.name(:string) - Defaults tonil.value(:any) - Defaults tonil.type(:string) - Defaults to"text". Must be one of"text","email","password","url","tel","number", or"search".field(Phoenix.HTML.FormField) - a form field; derives id/name/value and errors when set. Defaults tonil.placeholder(:string) - Defaults tonil.autocomplete(:string) - Defaults tonil.disabled(:boolean) - Defaults tofalse.readonly(:boolean) - Defaults tofalse.invalid(:boolean) - force the invalid visual + aria-invalid. Defaults tofalse.required(:boolean) - Defaults tofalse.maxlength(:integer) - native max length; also caps the count display. Defaults tonil.show_count(:boolean) - render a character count (needs a value; pairs with maxlength). Defaults tofalse.help(:string) - inline help when used standalone (omit inside <.field>). Defaults tonil.error(:string) - inline error when used standalone (omit inside <.field>). Defaults tonil.describedby(:string) - extra id(s) to reference; supplied by <.field>. Defaults tonil.errormessage(:string) - id of an external error node; supplied by <.field>. Defaults tonil.- Global attributes are accepted. Supports all globals plus:
["autocapitalize", "autocorrect", "spellcheck", "inputmode", "pattern", "min", "max", "step", "list", "form", "phx-debounce", "phx-change", "phx-blur", "phx-focus", "phx-keyup", "phx-keydown"].
Slots
prefix- leading adornment (icon/text); decorative.suffix- trailing adornment (icon/text); decorative.
A control label. Renders a real <label for> and, when asked, a required or
optional indicator with a screen-reader-friendly equivalent.
Examples
<.label for="email" required>Email</.label>Attributes
for(:string) - id of the control this labels. Defaults tonil.id(:string) - Defaults tonil.required(:boolean) - Defaults tofalse.optional(:boolean) - Defaults tofalse.- Global attributes are accepted.
Slots
inner_block(required)
A multi-line text control. Same association, count, and state handling as
input/1. Set autosize to opt into an optional grow-to-fit enhancement.
Examples
<.textarea name="notes" rows={5} placeholder="Notes" />
<.textarea field={@form[:bio]} show_count maxlength={280} autosize />Attributes
id(:string) - Defaults tonil.name(:string) - Defaults tonil.value(:any) - Defaults tonil.field(Phoenix.HTML.FormField) - Defaults tonil.placeholder(:string) - Defaults tonil.rows(:integer) - Defaults to3.disabled(:boolean) - Defaults tofalse.readonly(:boolean) - Defaults tofalse.invalid(:boolean) - Defaults tofalse.required(:boolean) - Defaults tofalse.maxlength(:integer) - Defaults tonil.show_count(:boolean) - Defaults tofalse.autosize(:boolean) - adds data-aui-autosize so an optional JS hook can grow the box; height still works without JS. Defaults tofalse.help(:string) - Defaults tonil.error(:string) - Defaults tonil.describedby(:string) - Defaults tonil.errormessage(:string) - Defaults tonil.- Global attributes are accepted. Supports all globals plus:
["spellcheck", "wrap", "form", "phx-debounce", "phx-change", "phx-blur", "phx-focus", "phx-keyup"].