Skip to content

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'

On this page
  1. From a Field and on its own
  2. When to use it
  3. For everyone
  4. Props

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-invalid and tie the error with aria-describedby.
  • It is said with words and an icon, never only with red.

Props

FieldErrorTypeDefault
id string
  1. From a Field and on its own
  2. When to use it
  3. For everyone
  4. Props

    Search pages, sections and terms