Error Card
Error card web component: a headline, what to try next, actions, and the raw error under a collapsible Details block with a copy button.
- 4.0 KB gzipped
- @lit-material/error-card 1.8.0
- Renders on the server
Example
Error card
A failure explained: a short headline, what to try next, actions, and the raw error under a collapsible Details block
with a copy button. Add alert when the card appears in answer to what someone just did.
Error: Connection refused
error sending request for url (https://api.example.test/v1/orders): client error (Connect): tcp connect error: Connection refused (os error 111)
Markup
<lit-material-error-card headline="Connection refused" details="error sending request for url (https://api.example.test/v1/orders): client error (Connect): tcp connect error: Connection refused (os error 111)"> Nothing answered on that port: is the server running, and is the port right? <lit-material-button slot="actions" variant="tonal">Try again</lit-material-button> </lit-material-error-card>
Warning, open details
Warning: Saved, but 2 of 14 tests were skipped
skipped: tests/payments.yaml › refund over limit (needs STRIPE_KEY) skipped: tests/payments.yaml › refund twice (needs STRIPE_KEY)
STRIPE_KEY in the environment to run them.
Install
npm install @lit-material/error-card @lit-material/tokens
import "@lit-material/error-card";
Link @lit-material/tokens/css/index.css once per page for the colour, type and shape tokens. Install guide
API
<lit-material-error-card>
A failure explained: a short headline ("Connection refused"), what to try next, optional actions (Retry, Open settings), and the raw error text — an engine message, a stack, a response body — under a collapsible Details block with a copy button, so people can report it.
Properties
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
headline | headline | string | "" | What went wrong, in a few words ("Host not found"). |
details | details | string | "" | The raw text (an engine message, a stack trace). Shown under Details with a copy button; none, no Details. |
variant | variant | ErrorCardVariant | "error" | error or warning. |
alert | alert | boolean | false | Announce the card as it appears (role="alert"). |
open | open | boolean | false | Whether the Details block is open. |
Events
| Event | Description |
|---|---|
toggle | The Details block opened or closed; detail: { open }. |
Slots
| Slot | Description |
|---|---|
| default | What to try next. |
actions | Buttons or links (Retry, Open settings…). |
CSS parts
| Part | Description |
|---|---|
card | The container. |
icon | The error or warning icon. |
headline | The headline. |
toggle | The Details button. |
details | The raw text. |
copy | The Copy details button. |
CSS custom properties
| Property | Description |
|---|---|
--lit-material-error-card-warning-color | Warning icon and border colour. |
--lit-material-error-card-warning-container | Warning background. |
--lit-material-error-card-details-max-height | The Details block scrolls past this height (default 16rem). |