FieldError
What is wrong with a value and how to fix it, under the control, with the error icon. A Field writes it from error.
import { FieldError } from '@sypnia/ui/react'
From a Field and on its own
This email has no @. Write it like ana@northwind.io.
The limit cannot be below zero. Write 0 to stop spending.
Code
import { Field, FieldError, Input } from '@sypnia/ui/react';
// Say what is wrong and how to fix it. A Field does this with `error`; on its own, tie it with aria-describedby.
export default function Errors() {
return (
<div className="sy-stack">
<Field label="Email" error="This email has no @. Write it like ana@northwind.io."><Input type="email" defaultValue="ana.northwind.io" /></Field>
<div className="sy-field" data-invalid="">
<label className="sy-field__label" htmlFor="limit">Monthly limit</label>
<Input id="limit" defaultValue="-20" aria-invalid aria-describedby="limit-error" />
<FieldError id="limit-error">The limit cannot be below zero. Write 0 to stop spending.</FieldError>
</div>
</div>
);
} When to use it
Use it when
- Say what happened and what to do: «This email has no @. Write it like ana@northwind.io».
Do not use it when
- Blaming words such as «invalid» or «illegal» alone.
- Errors that are not about one field: use an ErrorSummary or an Alert.
For everyone
- Mark the control
aria-invalidand tie the error witharia-describedby. - It is said with words and an icon, never only with red.
Props
| FieldError | Type | Default |
|---|---|---|
id | string |