Skip to content
Nizivo UI

InlineError

One error look for fields and data widgets: icon + text, never colour alone. Not a live region.

Server component, no client JS

Import

import { InlineError } from '@nizivo/react/inline-error';

// Once per app (Getting started), after
// @nizivo/tokens/tokens.css and @nizivo/react/css/base.css
import '@nizivo/react/css/inline-error.css';

Static or interactive

Server. It ships no client JavaScript when a Server Component renders it, in every Next.js build mode; its code is bundled only when a client component (a 'use client' file) imports it. How to choose.

In a client app (a Vite or React Router single-page app, or a 'use client' file) it is an ordinary React component: event handlers, refs and state work as usual. In a client app.

Examples

Basic

Enter a price above zero.
Couldn’t load revenue.
import type { JSX } from 'react';
import { Button } from '@nizivo/react/button';
import { InlineError } from '@nizivo/react/inline-error';

/** Stands in for an `@nizivo/icons` glyph (Lucide circle-x). */
function ErrorMark(): JSX.Element {
  return (
    <svg viewBox="0 0 24 24" width="1em" height="1em" fill="none" stroke="currentColor">
      <circle cx="12" cy="12" r="10" />
    </svg>
  );
}

export function InlineErrorExample(): JSX.Element {
  return (
    <div>
      <InlineError icon={<ErrorMark />}>Enter a price above zero.</InlineError>
      <InlineError
        icon={<ErrorMark />}
        action={
          <Button size="sm" variant="tertiary">
            Retry
          </Button>
        }
      >
        Couldn’t load revenue.
      </InlineError>
    </div>
  );
}

Props

One error look for fields and data widgets: icon + text, never colour alone. Not a live region.

Server component Renders data-slot="inline-error" with the class nz-inline-error. Props: InlineErrorProps. Source: src/inline-error/inline-error.tsx.

NameTypeDefaultDescription
actionReactNode–

A recovery control after the message, for example <Button size="sm">Retry</Button> (§16.5).

iconReactNode–

The error mark, decorative: the message carries the meaning, and the mark keeps the error from being colour-only (§15.1). Defaults to the internal circle-x glyph; pass your icon set's glyph to replace it.

renderRenderProp<Record<string, never>>–
  • Also takes every attribute of <div>. (ComponentPropsWithRef<"div">)

render takes an element, or, in client code, a function of the props and no state.

Other exports

InlineErrorProps type

import type { InlineErrorProps } from '@nizivo/react/inline-error'

The props of InlineError, listed above.

Data attributes and slots

Style parts by class (.nz-<slot>) and state by data attribute. Attribute meanings come from contracts/vocabulary.json.

SlotRendered byData attributes
inline-error
.nz-inline-error
InlineError
root (takes render)
none
inline-error-action
.nz-inline-error-action
InlineError
inner element (CSS only)
none
inline-error-icon
.nz-inline-error-icon
InlineError
inner element (CSS only)
none
inline-error-message
.nz-inline-error-message
InlineError
inner element (CSS only)
none

CSS hooks

Set a hook on the component's class or any ancestor to restyle it without specificity games; leave it unset for the default shown.

HookDefaultRead as
--nz-inline-error-fg--nz-text-critical
  • color on .nz-inline-error
--nz-inline-error-font--nz-font-body-m
  • font on .nz-inline-error
--nz-inline-error-gap--nz-space-1-5
  • gap on .nz-inline-error
--nz-inline-error-icon-fg--nz-icon-critical
  • color on .nz-inline-error-icon

Layers: nz.components. Classes: .nz-inline-error, .nz-inline-error-action, .nz-inline-error-icon.

Tokens this stylesheet reads (5)

--nz-font-body-m, --nz-icon-critical, --nz-size-icon-sm, --nz-space-1-5, --nz-text-critical

Accessibility

Nothing in this component takes focus or keyboard input.

Keyboard

None.

Figma

Node ids from design/component-map.json, which nz gen writes from component.json. The links open the Nizivo Figma library, which may ask you to sign in.

  • Canonical: none
  • Ghost masters: none

On this page