Error state
newEmpty's anatomy for a failure, with an error icon, a title, a description and a place for Retry, announced as an alert.
Open Props in the corner of the example to try size.
Installation
Usage
<script setup lang="ts">
import { RotateCw } from '@lucide/vue'
import { Button } from '@/components/ui/button'
import {
ErrorState,
ErrorStateActions,
ErrorStateDescription,
ErrorStateHeader,
ErrorStateMedia,
ErrorStateTitle,
} from '@/components/ui/error-state'
</script>
<template>
<ErrorState>
<ErrorStateHeader>
<ErrorStateMedia />
<ErrorStateTitle>Couldn't load projects</ErrorStateTitle>
<ErrorStateDescription>Try again in a moment.</ErrorStateDescription>
</ErrorStateHeader>
<ErrorStateActions>
<Button variant="outline" color="neutral" @click="refetch">
<RotateCw data-icon="inline-start" />
Retry
</Button>
</ErrorStateActions>
</ErrorState>
</template>
The parts are Empty's, so the layout, the surface (none) and size work the same. Three things differ: the root is an alert, ErrorStateMedia shows a circled exclamation mark in the destructive colour when you give it nothing, and the actions part is named for what goes there. Put your own icon or image in ErrorStateMedia to replace the default.
There is no Retry part and no retry event: the button is yours, so it can show a spinner, disable itself or do something else entirely.
Examples
In a data table
A DataTable draws its error slot where the empty message goes.
In a data tree
A DataTree draws its error slot inside its frame, next to the tree.
API Reference
Every part accepts class, merged over its base classes.
ErrorState
| Prop | Default | Type and description |
|---|---|---|
| size | "md" | EmptySizeSets the padding and the gaps, and through them the icon, title and description sizes of the parts inside, from |
| Slot | Scope and description |
|---|---|
| default | {}The header, the actions and anything else, stacked and centred. |
ErrorStateHeader
| Slot | Scope and description |
|---|---|
| default | {}The media, title and description. |
ErrorStateMedia
| Slot | Scope and description |
|---|---|
| default | {}An icon or an image, a circled exclamation mark by default. A bare |
ErrorStateTitle
| Prop | Default | Type and description |
|---|---|---|
| asChild | — | booleanRender the single child instead of a wrapper, merging the title's attributes and classes onto it. |
| as | "h3" | AsTag | ComponentThe element to render. An |
| Slot | Scope and description |
|---|---|
| default | {}The title. |
ErrorStateDescription
| Slot | Scope and description |
|---|---|
| default | {}What went wrong and what to do about it. |
ErrorStateActions
| Slot | Scope and description |
|---|---|
| default | {}The actions, such as a Retry button. |
Props
- size
"md" EmptySizeSets the padding and the gaps, and through them the icon, title and description sizes of the parts inside, fromxstoxl, as on Empty.mdby default.
Slots
- default
{}The header, the actions and anything else, stacked and centred.
Slots
- default
{}The media, title and description.
Slots
- default
{}An icon or an image, a circled exclamation mark by default. A baresvgtakes its size from the root'ssize, from 24px atxsto 56px atxl.
Props
- asChild
booleanRender the single child instead of a wrapper, merging the title's attributes and classes onto it.- as
"h3" AsTag | ComponentThe element to render. Anh3by default; pick the level that fits the page.
Slots
- default
{}The title.
Slots
- default
{}What went wrong and what to do about it.
Slots
- default
{}The actions, such as a Retry button.
Data attributes
| data-slot | Attributes | Description |
|---|---|---|
| error-state | data-size | The root, with role="alert". The parts read data-size through the group/empty class. |
| error-state-header | — | The media, title and description. |
| error-state-media | — | The icon or image. |
| error-state-title | — | The heading, an h3 unless as says otherwise. |
| error-state-description | — | The muted paragraph. |
| error-state-actions | — | The actions. |
Accessibility
- The root is
role="alert", so a screen reader reads it out as soon as it appears. - An error that is on the page from the start, or one the user went looking for, needn't interrupt: pass
role="status"orrole="none".