When to use it#
- Use a Field for every control that asks one question, in a resident form or a staff tool, so the control is never without a visible label.
- Put what people must read before answering in the description, and a format, an example or a limit in the help text under the control.
- Set
requiredandinvalidfrom your own form logic. Field only shows the state: the validation is yours. - On a form with several fields, add an ErrorSummary that lists the errors with a link to each field.
- Not for one question answered with several controls, such as a date or a group of options: use a Fieldset with a legend.
- Not for text that belongs to no control: use Prose.
Example#
import { Field, TextInput } from '@kvirn-ui/react'
import { useFieldTexts } from './texts.ts'
export function DefaultField() {
const { texts } = useFieldTexts()
return (
<Field.Root>
<Field.Label>{texts.fullName}</Field.Label>
<TextInput name="name" autoComplete="name" />
</Field.Root>
)
}Warning: Don't forget
Tell the browser what each field asks for with autoComplete, as the example does for the name. The browser can then fill in the person’s own details, which helps people who find typing hard (1.3.5 Identify Input Purpose). Never block pasting into a field (3.3.8 Accessible Authentication).
Use cases#
Say which questions are optional
Mark required fields required, and the label of every other field ends with “(optional)”. Required fields carry no visible marker. Where the optional text is wrong, such as a lone search field, turn it off.
import { Field, TextInput } from '@kvirn-ui/react'
import { useFieldTexts } from './texts.ts'
export function RequiredAndOptional() {
const { texts } = useFieldTexts()
return (
<>
<Field.Root required>
<Field.Label>{texts.email}</Field.Label>
<TextInput name="email" type="email" autoComplete="email" />
</Field.Root>
<Field.Root>
<Field.Label>{texts.phone}</Field.Label>
<TextInput name="phone" type="tel" autoComplete="tel" />
</Field.Root>
<Field.Root>
<Field.Label marker="none">{texts.search}</Field.Label>
<TextInput name="search" type="search" />
</Field.Root>
</>
)
}Props in this example:
Information: Did you know?
Field sets aria-required, not native required, so the browser shows no validation bubbles in its own words. For native validation, pass required on the control too, and keep it on the Field so the label doesn’t say “(optional)”.
Explain the question and show the format
A description is what people must read before answering, so it goes above the control and may hold a few short paragraphs. A help text is a short instruction, example or limit, so it goes under the control. Both are linked to the control, so a screen reader can read them when the control gets focus, in the order they appear.
We send the decision to this address, so check it before you send.
For example name@example.com
import { Field, TextInput } from '@kvirn-ui/react'
import { useFieldTexts } from './texts.ts'
export function DescriptionAndHelpText() {
const { texts } = useFieldTexts()
return (
<Field.Root required>
<Field.Label>{texts.email}</Field.Label>
<Field.Prose>
<p>{texts.emailDescription}</p>
</Field.Prose>
<TextInput name="email" type="email" autoComplete="email" />
<Field.HelpText>{texts.emailHelpText}</Field.HelpText>
</Field.Root>
)
}Information: Implement like this
Keep a help text to plain text of one or two sentences: no link, list or heading. A screen reader reads the description and the help text as flat text, so anything with structure goes outside the Field.
Show an error after the form is sent
Validate when the form is sent, not on every key. Set invalid, render the error message and move focus to the field, so the error is read with it. Say what is wrong and how to fix it, and repeat the format.
import { Button, Field, TextInput } from '@kvirn-ui/react'
import { useEffect, useRef, useState } from 'react'
import { useFieldTexts } from './texts.ts'
export function ErrorOnSubmit() {
const { texts } = useFieldTexts()
const inputRef = useRef<HTMLInputElement>(null)
const [invalid, setInvalid] = useState(false)
const [focusRequest, setFocusRequest] = useState(0)
useEffect(() => {
if (focusRequest > 0) {
inputRef.current?.focus()
}
}, [focusRequest])
return (
<form
noValidate
onSubmit={(event) => {
event.preventDefault()
const isEmpty = new FormData(event.currentTarget).get('email') === ''
setInvalid(isEmpty)
if (isEmpty) {
setFocusRequest((request) => request + 1)
}
}}
>
<Field.Root required invalid={invalid}>
<Field.Label>{texts.email}</Field.Label>
<TextInput ref={inputRef} name="email" type="email" autoComplete="email" />
<Field.HelpText>{texts.emailHelpText}</Field.HelpText>
<Field.ErrorMessage>{texts.emailError}</Field.ErrorMessage>
</Field.Root>
<Button type="submit" className="kv-button--primary">
{texts.send}
</Button>
</form>
)
}Props in this example:
invalidon Field.Root
Warning: Don't forget
Field never moves focus. When the form is sent, move it to the first invalid field or to an ErrorSummary. See What you need to do.
A field that can’t be changed
A disabled field turns off its control and marks every part as disabled. A disabled control can’t take keyboard focus, so avoid it in a form for residents. Where you can’t, say why in the help text. A read-only control stays reachable with the keyboard, so use that when people only need to read the value.
You can’t change this here. Contact your case worker to correct it.
import { Field, TextInput } from '@kvirn-ui/react'
import { useFieldTexts } from './texts.ts'
export function DisabledWithReason() {
const { texts } = useFieldTexts()
return (
<Field.Root disabled>
<Field.Label>{texts.lockedName}</Field.Label>
<TextInput name="name" defaultValue="Anna Andersson" />
<Field.HelpText>{texts.lockedHelpText}</Field.HelpText>
</Field.Root>
)
}Props in this example:
disabledon Field.Root
Wire your own elements
For a control KvirnUI doesn’t have, or markup of your own, useField gives the ids, aria-describedby and state attributes to spread. Name the descriptions from the first render, so server-rendered markup is complete.
We only use it to tell you about your case.
import { useField } from '@kvirn-ui/react'
import { useFieldTexts } from './texts.ts'
export function OwnElements() {
const { texts } = useFieldTexts()
const field = useField({ required: true, descriptions: ['helpText'] })
return (
<div {...field.rootProps}>
<label {...field.labelProps}>
{texts.contactMethod}
{field.optionalMarker === undefined ? null : (
<>
{' '}
<span className="kv-field-optional">{field.optionalMarker}</span>
</>
)}
</label>
<select {...field.controlProps} className="kv-listbox-native" name="contact">
<option value="email">{texts.contactByEmail}</option>
<option value="phone">{texts.contactByPhone}</option>
</select>
<p {...field.getDescriptionProps('helpText')} className="kv-field-help-text">
{texts.contactHelpText}
</p>
</div>
)
}Props in this example:
descriptionson useField (options)
Accessibility#
What it does for you#
- APG pattern: none. There is no APG pattern for form fields. A field is native HTML:
<label for>, a native control, andaria-describedbyfor the description, the help text and the error. Errors go througharia-describedby, notaria-errormessage. - Deviations: none from APG. A Prose in a Field is the description (there is no Field.Description), and a help text is its own part,
Field.HelpText. Errors are not live, and the optional marker and the error prefix are part of the accessible text. - Native elements used:
<div>(Field.Root),<label for>(Field.Label),<p>(Field.ErrorMessage), a<div class="kv-prose">for the description (Field.Prose), a<p class="kv-field-help-text">for the help text (Field.HelpText), a<span>for the optional marker and one for the error prefix, and a decorative<svg>(theerrorIcon) in the Field.ErrorMessage.
A Field joins one control to its visible label, an optional description (Field.Prose), an optional help text (Field.HelpText) and an error message. The parts register with their Field, so no DOM query and no global id is involved, and the control's aria-describedby never names a part that isn't rendered. The consumer validates and sets invalid: there is no validation engine.
| Part | Element / role | ARIA / state | Notes |
|---|---|---|---|
| Field.Root | <div>, no role | none. data-invalid, data-required, data-disabled | Class kv-field. Props: invalid, required, disabled, controlId, messages. Generates the ids (useId). Inside a group fieldset (Fieldset group) the marker defaults to none |
| Field.Label | <label for>, names the control | htmlFor is the control's id. id is <control id>-label. data-invalid, data-required, data-disabled | Class kv-field-label. Appends <span class="kv-field-optional">(optional)</span> from field.optional after a normal space, inside the label, unless the field is required or marker="none". So the marker is in the name |
| Field.Prose | <div class="kv-prose" id> | In the control's aria-describedby, in DOM order, before the error. data-invalid, data-disabled | The description: what to answer, why we ask, where to find it. Read before answering, so it goes above the control. the body text size wherever it sits. A Field.Prose anywhere inside a Field registers itself: no prop and no extra part. A Field can have several, each with its own id. An id is listed only while its Prose is rendered. There is no Field.Description |
| Field.HelpText | <p class="kv-field-help-text" id>. No role | In the control's aria-describedby, in DOM order (with the Proses), before the error. data-invalid, data-disabled. Never tabindex, role or aria-live | The help text: a short instruction, format example or limit, plain text, always under the control. a step smaller than the body text. A help text rendered before its control gives the dev warning help-text-before-control once; a Fieldset.HelpText before the group's controls gives the same warning. Registers through the same useDescriptionPart as Prose and FileUpload.Limits, so it has its own id and is listed only while rendered. It is outside the <label>, so it is never part of the name (2.5.3 Label in Name (A)). In an option's Field it describes that option's input, not the group. Outside a Field or Fieldset it warns (help-text-outside-field) and renders a plain <p class="kv-field-help-text"> with no id. Fieldset.HelpText, CheckboxGroup.HelpText and RadioGroup.HelpText are the same part under the group's name |
| Field.ErrorMessage | <p id>, rendered only while the field is invalid | In the control's aria-describedby, after every description. data-invalid, and data-disabled while the field is disabled | Class kv-field-error-message. Starts with a decorative error Icon (aria-hidden), then <span class="kv-field-error-prefix">Error:</span> from field.errorPrefix, a space, then the message |
| the control | TextInput (see the TextInput contract) or your element | id, aria-describedby (description id, then error id), aria-invalid="true" when invalid, aria-required="true" when required | Not native required: no browser bubbles. Native disabled when the Field is disabled. data-invalid, data-required, data-disabled |
useField | the same attributes, for your own elements | rootProps, labelProps, descriptionProps, getDescriptionProps(name), errorMessageProps, controlProps | Options: id, invalid, required, disabled, hasDescription, descriptions (names, in render order), hasErrorMessage (default: invalid), marker, messages. Also returns labelId (the label's id, for aria-labelledby), optionalMarker and errorPrefix |
Registration rules:
aria-describedbyis every description's id (Prose and HelpText alike) in DOM order, then the error id, joined by a space, and only for the parts rendered. The order is the DOM order, whichever order the parts mounted in. With the default order that is the description, the help text, then the error. When none is rendered the attribute is absent, never empty. A screen-reader user hears the description, the help text, then "Error: …" in English, whatever the visual order.- A
Field.HelpTextregisters like aField.Prose, takesdata-invalidanddata-disabledfrom the Field and nothing else from its state (the theme never styles them), is never focusable and is no live region. Outside a Field or Fieldset it gives the dev warninghelp-text-outside-fieldonce and renders a<p class="kv-field-help-text">with no id. A help text is plain text: no link, list or heading in it. There is no dev warning for rich content. - A
Field.Proseinside a Field is the description of its control. Registration is automatic and has no opt-out: a Prose that isn't a description goes outside the Field. - The description is the Prose's text content. A heading, list or link inside it is read as plain text, without its role or structure, and a link in a description can't be followed from there. Keep a description to plain text and a few short paragraphs, and put anything with structure outside the Field. A help text is plain text only.
- Each description and help text has its own id (a generated suffix on the control's id), so no two share one. A Prose or HelpText that unmounts leaves
aria-describedbyat once: it never names a missing id. - A Prose outside a Field or Fieldset has no id and gives no warning, unlike a HelpText.
- A Field with two ErrorMessages gives a dev warning (they share one id): render one, with all the text.
Field.ErrorMessagerenders nothing while the Field isn'tinvalid, so a hidden or stale message is never referenced. A Field that isinvalidwithout a Field.ErrorMessage gives a dev warning (3.3.1 Error Identification (A)).- A Prose, a HelpText and the Field.ErrorMessage attach to the nearest Field or Fieldset. A Field inside a Fieldset (an option, a date box) therefore owns its own help text and error, and the Fieldset's own Prose, HelpText and Field.ErrorMessage stay the group's.
- A Fieldset's
invalidnever passes down to the Fields inside it. useField({ hasDescription: true })oruseField({ descriptions: ['above', 'under'] })setsaria-describedbyfrom the first render, so server-rendered markup is complete. Withdescriptions, spreadgetDescriptionProps(name)on each description or help text: its class iskv-prose(for a help text, setclassName="kv-field-help-text"after the spread), its id is<controlId>-description-<name>, listed in the order of the array, then the error. The Root component learns about its parts when they mount, so for a moment before hydration the server HTML has the parts but not the association. Use the hook for server-critical markup.
It announces nothing.
What you need to do#
- Keep a help text short and plain: one or two short sentences or a format example, text only, with no link, list or heading (see above). Anything the user must read before answering is a description (
Field.Prose). A Prose that isn't a description, such as an article or a list of links, goes outside the Field. A help text is never the only place a format lives: the error repeats it. Its copy in a disabled or read-only field says why. - Give every control a visible label (Field.Label) that describes what to enter (2.4.6 Headings and Labels (AA)). A placeholder is not a label (3.3.2 Labels or Instructions (A)). Put examples in a
Field.HelpText, not in a placeholder. - Set
invalidand render a Field.ErrorMessage together. Write the message so it says what's wrong and how to fix it, in the field's own words, never blaming the user (3.3.1 Error Identification (A), 3.3.3 Error Suggestion (AA)). Plain text only: the icon, the prefix and the text lay out as one line. - Set
requiredon every required field. Required fields carry no visible marker, and optional ones say "(optional)". Usemarker="none"where that text is wrong, such as a lone search field or a single consent checkbox. If you mark required fields yourself with an asterisk, add your own text that explains it, and usemarker="none". - Keep a Field's control a direct child of
Field.Rootwhen it is a checkbox or radio: the default theme finds its layout from.kv-field:has(> .kv-checkbox, > .kv-radio). - Validate on submit, not on every key. Then move focus to the first invalid field, or show an ErrorSummary (3.3.1 Error Identification (A)).
- Render the parts in the default order: label, description, control, help text, then the error, so the visual order is the
aria-describedbyorder (1.3.2 Meaningful Sequence (A)). A help text always goes under the control: text the user must read before answering is a description (Field.Prose) above it. With the error under the control, keepscroll-paddingon the page (the end value leaves room for the message), so the on-screen keyboard or an autocomplete list doesn't hide it when the field gets focus (2.4.11 Focus Not Obscured (Minimum) (AA)). The order is the consumer's: another order keeps working. - Use
autocompleteon controls that ask for the user's own data (1.3.5 Identify Input Purpose (AA)), and never block paste (3.3.8 Accessible Authentication (Minimum) (AA)). - A Field.Label whose text is in another language goes in a nested
KvirnProviderwithuseLocale().localePropson your own element (3.1.2 Language of Parts (AA)). - Give a Field the
controlIdyou need to link to it, for example from an error summary. Don't pass anidto the control inside a Field: the Field's id wins and a dev warning says so.
Warning: Don't forget
Give every control a visible label. A placeholder is not a label: it is gone once people type (3.3.2 Labels or Instructions).
Visual and modes#
- Focus indicator: on the control (see the TextInput contract). Labels and text parts aren't focusable. An invalid text input keeps its error-coloured edge when it has focus, and shows the focus ring on any focus, a click included.
- Target size: the label is the click target for choice controls, taller than the 24 by 24 CSS pixel minimum in both densities, and sits above a text control (2.5.8 Target Size (Minimum) (AA)).
- Colour: the label, description, help text and optional marker use the normal text colour, and a help text keeps it when the field is invalid, disabled or read-only (the error carries the state). The error text has at least 4.5:1 contrast on every background (7:1 in the high-contrast themes), checked by the theme's contrast check. The error has an icon, and a text prefix for screen readers, and the invalid control has a thicker edge, so colour is never the only cue (1.4.1 Use of Color (A)). The invalid edge has at least 3:1 contrast against the page and card backgrounds (1.4.11 Non-text Contrast (AA)).
- forced-colors behaviour: the error text uses the system's text colour, the icon follows it, and the invalid control keeps its thicker border.
- reduced-motion behaviour: no layout animation when an error appears. Not checked by an automated sweep.
- 1.4.12 Text Spacing (AA): no fixed heights. A help text's size and line height are in
rem, so it grows with the browser's text size (1.4.4 Resize Text (AA)). - Help text size: a help text is a step smaller than a description in both densities. The size belongs to the part, not to where it sits.
- RTL: logical properties only. The icon doesn't mirror.
Focus management#
- Initial focus: not moved.
- Trap: no.
- Restore to: not applicable.
- On error: Field never moves focus. On submit, the form moves focus to the first invalid field, or to an ErrorSummary. The consumer does this, and the docs say so.
- Never obscured by: Field renders no overlay. Consumers with a sticky header set
scroll-padding(2.4.11 Focus Not Obscured (Minimum) (AA)).
WCAG success criteria#
- 1.3.1 Info and Relationships (A): native
<label for>, description and error in the accessible description (field.test.tsx › wiring: name and description per state). - 2.4.6 Headings and Labels (AA): the label describes the purpose of the control (consumer's text).
- 1.3.5 Identify Input Purpose (AA): the consumer's
autocompletepasses through (see the TextInput contract). - 1.4.1 Use of Color (A): invalid is a thicker edge, an icon and a message that starts with a text prefix.
- 1.4.3 Contrast (Minimum) (AA), 1.4.11 Non-text Contrast (AA): the pairs in the theme's contrast check (the error colour as text and as a 3:1 edge).
- 2.5.3 Label in Name (A): the visible label text, including "(optional)", is the name.
- 3.3.1 Error Identification (A): the message in text, with a text prefix, linked by
aria-describedby. - 1.3.2 Meaningful Sequence (A): with the default order the visual order is the spoken order: description, help text, then the error.
- 3.3.2 Labels or Instructions (A): a visible label always, and the description and help text linked to the control.
- 3.3.3 Error Suggestion (AA): the consumer's message text (the docs show the patterns).
- 4.1.2 Name, Role, Value (A): the control's name, description,
aria-invalidandaria-required. - 2.4.7 Focus Visible (AA): the control shows the focus ring on any focus, an invalid one included (Visual / modes; the control's own tests are in the TextInput contract).
- 2.5.8 Target Size (Minimum) (AA): the label is taller than 24 by 24 CSS pixels (Visual / modes; reviewed in the stories, no named test).
- 1.4.4 Resize Text (AA): the help text is in
rem(Visual / modes; no named test). - 3.1.2 Language of Parts (AA): a label in another language is marked by the consumer (see Consumer responsibilities).
Keyboard#
- Focus
- native
- Selection follows focus
- n/a
- Arrows wrap
- n/a
- Shortcuts
- none
Field.Root, Field.Label, the description (Field.Prose), the help text (Field.HelpText) and Field.ErrorMessage handle no keys and move no focus. Focus stays on the control, which owns its keys: see the TextInput and NumberInput contracts. Enter, Space, Escape, the arrow keys, Home and End are not handled by Field.
| Key | Where | What happens |
|---|---|---|
| Tab / Shift+Tab | Fields in a form | Moves through the controls in DOM order. Field.Label, description, help text and error text are not Tab stops Test: field.test.tsx › Tab moves through the controls in DOM order, field.test.tsx › Tab moves through the controls in DOM order in right to left |
| Tab | From a Field's label, help text or error | Moves to the control, and never stops on the label, the help text or the error Test: field.test.tsx › Tab goes to the control and never stops on the label, the help text or the error |
| No key | Field.Label | A click on the label focuses the control (native <label for>), also on the optional markerTest: field.test.tsx › clicking the label focuses the input, also on the optional text |
| No key | The description (Field.Prose), the help text (Field.HelpText), Field.ErrorMessage | Not focusable and not interactive: no tabindexTest: field.test.tsx › is never focusable and adds no role, live region or tabindex |
API reference#
import { Field, useField } from '@kvirn-ui/react'Field.Root
Renders <div> with no role. It takes every attribute of a <div> and passes ref to it. It creates the ids and links its label, description, help text, error and control to each other. The default theme is described on Theming.
| Prop | Type | Default | Description |
|---|---|---|---|
invalid | boolean | false | Sets aria-invalid on the control and data-invalid on every part, and shows the Field.ErrorMessage. You decide when: KvirnUI holds no form state. |
required | boolean | false | Sets aria-required on the control and removes the optional text from the label. Never native required: pass that on the control too if you want the browser’s validation. |
disabled | boolean | false | Native disabled on the control and data-disabled on every part. |
controlId | string | generated | The control’s id, for example to link to it from an error summary. The ids of the label, description and error are derived from it. |
messages | Partial<KvirnMessages['field']> | – | Overrides field.optional and field.errorPrefix for this field. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-field | always | The part class. The default theme styles it. |
data-invalid | present or absent | The field is invalid. |
data-required | present or absent | The field is required. |
data-disabled | present or absent | The field is disabled. |
Field.Label
Renders <label for>. It names the control. It ends with the optional text when the field is not required, unless marker="none" or the Field is in a group Fieldset.
| Prop | Type | Default | Description |
|---|---|---|---|
marker | 'optional' | 'none' | 'optional' | Whether the label ends with the optional text when the field is not required. Inside a group Fieldset the Field default is ‘none’. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-field-label | always | The part class. |
kv-field-optional | on the span inside the label | The optional text, for example “(optional)”. It is part of the accessible name. |
data-invalid, data-required, data-disabled | present or absent | The state of the field. |
Field.Prose
Renders <div class="kv-prose">, the description. Anywhere inside a Field it registers itself, gets an id and is listed in the control’s aria-describedby. It is the same Prose as outside a Field.
| Class or attribute | Values | Meaning |
|---|---|---|
kv-prose | always | The class that styles the text for reading. |
data-invalid | present or absent | The field is invalid. |
data-disabled | present or absent | The field is disabled. |
Field.HelpText
Renders <p>, the help text. It takes every attribute of a <p> except id. It registers like a description and is listed in DOM order, then the error. Outside a Field or Fieldset it renders a plain paragraph with no id and warns in development.
| Class or attribute | Values | Meaning |
|---|---|---|
kv-field-help-text | always | The part class. The default theme sets it a step smaller than the description. |
data-invalid | present or absent | The field is invalid. |
data-disabled | present or absent | The field is disabled. |
Field.ErrorMessage
Renders <p>, rendered only while the field is invalid. It takes every attribute of a <p> except id. It starts with a decorative error icon and the field.errorPrefix text, which the default theme hides from sight but not from screen readers. It is not a live region (a part of the page that a screen reader reads aloud when it changes).
| Class or attribute | Values | Meaning |
|---|---|---|
kv-field-error-message | always | The part class. |
kv-field-error-prefix | on a span inside | The prefix text, for example “Error:”. The theme hides it visually, not from screen readers. |
data-invalid | always | The part only renders while invalid. |
data-disabled | present or absent | The field is disabled. |
useField
Options
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | generated | The control’s id. The description and error ids are derived from it. |
invalid | boolean | false | Marks the field as invalid. |
required | boolean | false | aria-required on the control, and no optional text in the label. |
disabled | boolean | false | Native disabled on the control. |
hasDescription | boolean | false | You render one description with descriptionProps, so the control’s aria-describedby lists it from the first render. |
descriptions | readonly string[] | – | The names of the descriptions you render with getDescriptionProps(name), in render order. aria-describedby lists them in this order, then the error. If you also set hasDescription, that description comes first. |
hasErrorMessage | boolean | true | false when you render no error message for an invalid field. |
marker | 'optional' | 'none' | 'optional' | Whether the optional text shows. Inside a group Fieldset the default is ‘none’. |
messages | Partial<KvirnMessages['field']> | – | Per-instance message overrides. |
Result
| Prop | Type | Default | Description |
|---|---|---|---|
rootProps | FieldRootPartProps | – | Spread on the container. |
labelProps | FieldLabelPartProps | – | Spread on the <label>: class, id and htmlFor. |
descriptionProps | FieldDescriptionPartProps | – | For the one description (hasDescription). |
getDescriptionProps | (name: string) => FieldDescriptionPartProps | – | For the description with this name. Its id is listed in descriptions. |
errorMessageProps | FieldErrorMessagePartProps | – | Spread on the error message, which you render only while invalid. |
controlProps | FieldControlPartProps | – | Spread on the control: id, aria-describedby, aria-invalid, aria-required, disabled and data-* state. |
controlId | string | – | The control’s id. |
labelId | string | – | The label’s id, for an aria-labelledby from another part. |
descriptionId | string | – | The base id the description ids are derived from. |
errorMessageId | string | – | The error message’s id. |
isInvalid | boolean | – | Whether the field is invalid. |
isRequired | boolean | – | Whether the field is required. |
isDisabled | boolean | – | Whether the field is disabled. |
marker | 'optional' | 'none' | – | The resolved marker: your option, else ‘none’ in a group Fieldset. |
optionalMarker | string | undefined | – | The text to render after the label and a space, or undefined when the label shows none. |
errorPrefix | string | – | The resolved field.errorPrefix text. Start the error message with it. |
Strings
These are the default texts in @kvirn-ui/i18n.
For your whole app, pass messages to KvirnProvider. For one Field, pass its messages prop.
field.optional
The text that ends the label of a field that is not required.
| Language | Default text |
|---|---|
| Svenska | (valfritt) |
| Suomi | (vapaaehtoinen) |
| Norsk bokmål | (valgfritt) |
| Norsk nynorsk | (valfritt) |
| English | (optional) |
field.errorPrefix
The text that starts the Field.ErrorMessage.
| Language | Default text |
|---|---|
| Svenska | Fel: |
| Suomi | Virhe: |
| Norsk bokmål | Feil: |
| Norsk nynorsk | Feil: |
| English | Error: |
Known issues#
- The description is associated after mount. Server-rendered markup lists a Prose or a HelpText in
aria-describedbyonly after hydration.useFieldwithhasDescriptionordescriptionsdoesn't have this gap. - Error under the control on phones. The on-screen keyboard can cover the message under a focused field. The mitigation is in the docs (focus on submit,
scroll-padding), not in the components, and the AT and usability run checks it. The error is linked from the first render whenever the field is invalid, in server-rendered markup too, and when an app moves focus to the field in an effect after submit. Tests:field.test.tsx › focus on submit. - WebKit is not automated. Keyboard rows run in Vitest browser mode on Chromium. WebKit is not covered by the automated tests, so check Safari with your own users and assistive technology.
Testing#
The automated tests prove the keyboard behaviour, the names and states, that axe finds no violations in every story and theme, and, for the components they cover, that the stories hold up in forced colours, reduced motion, text spacing and a 320 pixel width. An Automated row passes on these tests alone. A Core or Release row passes only when an automated agent check and a person on the real assistive technology have both checked it. "agent-verified" means automated tests in the repository (with a virtual screen reader for the screen reader rows), not the real assistive technology.
| AT + browser + OS | Agent check | Human check | Result | Notes |
|---|---|---|---|---|
| Automated (re-runnable tests) | ||||
| axe, WCAG 2.2 A and AA, every story, 4 themes | pass | n/a | pass | field.stories.tsx, every story, 4 themes |
| Markup and ARIA (roles, names, ids, states) | pass | n/a | pass | field.test.tsx (axe and role, name and state): wiring: name and description per state › label and description: the label names the control, the description describes it |
| Keyboard contract rows (Vitest browser) | pass | n/a | pass | 4 rows, each names a test in field.test.tsx |
| Focus order and management | pass | n/a | pass | field.test.tsx: keyboard › Tab goes to the control and never stops on the label, the help text or the error |
| Display modes (forced colours, 320px reflow, text spacing, reduced motion) | pass | n/a | pass | the four sweep projects (storybook-forced-colors, -reduced-motion, -reflow, -text-spacing), run in CI |
| Core (required for beta) | ||||
| NVDA + Chrome + Windows | pending | pending | pending | |
| VoiceOver + Safari + iOS | pending | pending | pending | |
| Release (before 1.0 and each minor) | ||||
| JAWS + Chrome + Windows | pending | pending | pending | |
| TalkBack + Chrome + Android | pending | pending | pending | |
| VoiceOver + Safari + macOS | pending | pending | pending |
What to check#
With a screen reader and the keyboard, try:
- Tab to the box: the label is read, then the description and the help text.
- A field that is not required reads "(optional)" at the end of its name.
- Submit the form empty: "Error:" and the message are read when focus arrives.
- Click the label: the box takes focus.
- On a phone with the keyboard open, the error under an invalid field stays visible.