Overview
Feedback is a nds-feedback element with a data-status. It holds a status icon (nds-feedback-icon) and an optional short message (nds-feedback-message).
Pick another component when:
Markup
<span class="nds-feedback nds-outline" data-status="error">
<span class="nds-feedback-icon">
<i class="nds-icon" aria-hidden="true"></i>
</span>
<span class="nds-feedback-message">Enter a valid email address</span>
</span>
NDS.Feedback.create({
message: 'Enter a valid email address',
status: 'error',
target: '#email-hint'
});
Variants
#fb-js is the same message as one NDS.Feedback.create() call (data-js on the base canon). A row whose On element is create() sets an option of that call. The call’s defaults match the canon: no size class, so SM, and style: 'outline'.
| Group | Option | Markup | On element | Use |
|---|---|---|---|---|
| Structure | Message (default) | — | — | The icon and a short message |
| Structure | Icon only | canon #fb-icon |
— | The icon alone, where the text around it already says the status |
| Structure | Icon only | message: '' |
create() |
The same, in JavaScript: leave out message |
| Status | Error (default) | [data-status="error"] |
.nds-feedback |
Something failed or is wrong |
| Status | Error (default) | status: 'error' |
create() |
The same, in JavaScript |
| Status | Critical (hint: Error colors with an exclamation mark) | [data-status="critical"] |
.nds-feedback |
A severe error. Error colors with an exclamation mark |
| Status | Critical (hint: Error colors with an exclamation mark) | status: 'critical' |
create() |
The same, in JavaScript |
| Status | Success | [data-status="success"] |
.nds-feedback |
A confirmation |
| Status | Success | status: 'success' |
create() |
The same, in JavaScript |
| Status | Warning | [data-status="warning"] |
.nds-feedback |
A risk the user should know about |
| Status | Warning | status: 'warning' |
create() |
The same, in JavaScript |
| Status | Info | [data-status="info"] |
.nds-feedback |
News or a tip |
| Status | Info | status: 'info' |
create() |
The same, in JavaScript |
| Status | Neutral | [data-status="neutral"] |
.nds-feedback |
A general hint. Gray, with an “i” |
| Status | Neutral | status: 'neutral' |
create() |
The same, in JavaScript |
| Status | Help | [data-status="help"] |
.nds-feedback |
Help text. Gray, with a question mark |
| Status | Help | status: 'help' |
create() |
The same, in JavaScript |
| Size | SM (default) | — | — | A 16px icon, for a message in a form or in text |
| Size | MD | .nds-md |
.nds-feedback |
A 24px icon and larger text, for a status that stands alone |
| Size | MD | size: 'md' |
create() |
The same, in JavaScript |
| Size | LG | .nds-lg |
.nds-feedback |
A 32px icon and large text, for the main status of a page or a panel |
| Size | LG | size: 'lg' |
create() |
The same, in JavaScript |
| Style | Outline (default) | .nds-outline |
.nds-feedback |
The icon drawn as a line in the status color |
| Style | Solid | — | — | A filled disc in the status color, with a white symbol. On color, a light disc with a dark symbol, and in dark mode the neutral one too. It is the look with no style class, and it is stronger than outline |
| Style | Solid | style: '' |
create() |
The same, in JavaScript |
| Style | Ring (hint: A light halo around the disc) | .nds-ring |
.nds-feedback |
A solid disc with a light halo around it, for a status that must stand out |
| Style | Ring (hint: A light halo around the disc) | style: 'ring' |
create() |
The same, in JavaScript |
Behavior
Permanent Message
A permanent message is a hint that stays in place, such as “Use 8 characters or more”. Mark it with data-permanent, or permanent: true in create(). When a newer message arrives in the same place, the hint hides instead of being removed. When that newer message is dismissed, the hint shows again.
Built-in Features
-
Auto Icon by Status
The status picks the icon: a check for success, an exclamation mark for warning and critical, a cross for error, "i" for info and neutral, and a question mark for help. The icon element stays empty in the markup.
-
Parent Status Inheritance
A feedback icon inside any element with a
data-statustakes that status, with no attribute of its own. This is how an alert, a form field and a progress bar color their icons. -
Screen Reader Announcement
create()marks the message so that a screen reader reads it when it appears. An error is read at once, and any other status after the screen reader finishes what it is reading. -
One Message per Place
A new message replaces the one already in the same place, so messages never pile up. A group's message leaves the messages of the fields inside the group. A target with
hiddenshows while a message is in it, and hides again when the last one is dismissed.
Best Practices
- Match the status to the message: error for a failure, success for a confirmation, warning for a risk, info for news, neutral for a general hint and help for help text.
- Keep the message to one short sentence.
- Use an icon alone only where the text around it already says the status. The icon has no text for screen readers.
- Add a message from a script with
NDS.Feedback.create(), not with your own markup, so a screen reader reads it. - Use SM in forms and in text. Use MD for a status that stands alone, and LG for the main status of a page or a panel.
- Keep Solid and Ring for a status that must stand out. Outline suits most messages.
API
Data Attributes
| Attribute | Element | Effect |
|---|---|---|
data-status |
.nds-feedback, or any parent |
error, critical, success, warning, info, neutral or help. Sets the icon and the colors |
data-permanent |
.nds-feedback |
Makes the message permanent. See Behavior |
CSS Custom Properties
Set these on the .nds-feedback-icon, on the .nds-feedback, or on a parent. Each status sets its own colors and shapes.
| Property | Default | Controls |
|---|---|---|
--feedback-size |
16px, 24px with nds-md, 32px with nds-lg |
Size of the icon. It wins over a size class wherever you set it. A message with no size class takes its parent’s size, such as 20px in a tooltip |
--feedback-color |
var(--icon-neutral) |
Color of the outline icon. It changes in dark mode |
--feedback-icon-color |
var(--feedback-icon-fill-neutral) |
Fill of the solid disc. On color it takes the light status shade. In dark mode it stays, except neutral, which turns white |
--feedback-ring |
var(--icon-neutral-ring) |
Color of the ring halo |
--feedback-symbol-color |
The status’s --feedback-icon-symbol-* token: white, black on a light disc |
Color of the symbol on the solid disc |
--feedback-icon-symbol |
the “i” in a .nds-feedback, none elsewhere |
Shape of the symbol, as an icon mask |
--feedback-icon-stroke |
var(--nds-icon-information-circle) |
Shape of the outline icon, as an icon mask |
--feedback-icon-disc |
var(--nds-icon-disc) |
Shape of the solid disc, as an icon mask |
--feedback-ring-inset |
6% of the size | Inner edge of the ring, which closes the gap between the disc and the halo. 0 with nds-outline |
Tokens
Set a token at :root, or on a wrapper to reach every feedback icon inside it. Give a token with a Dark mode value a dark override too: see Tokens.
Source: the feedback group in _sass/tokens/_components.scss.
| Token | Preview | Value |
|---|---|---|
--feedback-icon-fill-success | var(--colors-green-700) | |
--feedback-icon-fill-error | var(--colors-red-700) | |
--feedback-icon-fill-warning | var(--colors-yellow-700) | |
--feedback-icon-fill-info | var(--colors-blue-700) | |
--feedback-icon-fill-neutral | var(--colors-neutral-700)Dark mode var(--colors-neutral-500) | |
--feedback-icon-symbol-success | var(--colors-base-white) | |
--feedback-icon-symbol-error | var(--colors-base-white) | |
--feedback-icon-symbol-warning | var(--colors-base-white) | |
--feedback-icon-symbol-info | var(--colors-base-white) | |
--feedback-icon-symbol-neutral | var(--colors-base-white) |
It also reads these shared tokens. A change to one also changes other components.
Source: the var() reads in _sass/components/_feedback.scss.
| Token | Preview | Value |
|---|---|---|
--text-primary-paragraphRead by color | var(--colors-neutral-700)Dark mode var(--colors-neutral-300) | |
--text-successRead by color | var(--colors-green-700)Dark mode var(--colors-green-400) | |
--text-infoRead by color | var(--colors-blue-700)Dark mode var(--colors-blue-400) | |
--text-warningRead by color | var(--colors-yellow-700)Dark mode var(--colors-yellow-400) | |
--text-errorRead by color | var(--colors-red-700)Dark mode var(--colors-red-400) | |
--icon-neutralRead by --feedback-color | var(--colors-neutral-700)Dark mode var(--colors-neutral-300) | |
--icon-successRead by --feedback-color | var(--colors-green-700)Dark mode var(--colors-green-400) | |
--icon-infoRead by --feedback-color | var(--colors-blue-700)Dark mode var(--colors-blue-400) | |
--icon-warningRead by --feedback-color | var(--colors-yellow-700)Dark mode var(--colors-yellow-400) | |
--icon-errorRead by --feedback-color | var(--colors-red-700)Dark mode var(--colors-red-400) | |
--icon-neutral-ringRead by --feedback-ring | var(--colors-neutral-100)Dark mode var(--colors-alpha-white-20) | |
--icon-success-ringRead by --feedback-ring | var(--colors-green-100)Dark mode var(--colors-green-900) | |
--icon-info-ringRead by --feedback-ring | var(--colors-blue-100)Dark mode var(--colors-blue-900) | |
--icon-warning-ringRead by --feedback-ring | var(--colors-yellow-100)Dark mode var(--colors-yellow-900) | |
--icon-error-ringRead by --feedback-ring | var(--colors-red-100)Dark mode var(--colors-red-900) |
JavaScript
There is no init(): nothing scans the page for feedback. The script only builds messages.
| Method | Effect |
|---|---|
NDS.Feedback.create(options) |
Builds a message, puts it in place and returns the element. It replaces the message already in the same place, but not a message that belongs to a field inside it |
NDS.Feedback.dismiss(elOrSelector) |
Removes one message, and shows again a permanent message it hid. Returns true when it existed |
NDS.Feedback.dismissAll(container, options) |
Removes every message in a container except the permanent ones, which show again. With { own: true }, it leaves the messages of fields nested in the container. A message has a .nds-feedback-message or a role: a bare status icon, such as an Upload row’s check mark, stays |
| Option | Default | Effect |
|---|---|---|
message |
'' |
The message text. Leave it out for an icon alone |
status |
'neutral' |
The status, as in data-status |
target |
null |
The element or selector the message goes to |
position |
'append' |
'append' or 'prepend' puts it inside the target, 'before' or 'after' beside it. This is where the message goes in the page, unlike Alert’s position, which is the toast’s screen corner |
size |
none | 'sm', 'md' or 'lg'. With none, the message takes no class: SM, or its parent’s size |
style |
'outline' |
'outline', '' for solid, or 'ring' |
showIcon |
true |
false leaves out the icon |
permanent |
false |
Makes the message permanent |
ariaLive |
from the status | 'assertive' for error, else 'polite' |
id, className |
none | An id and more classes for the message |
onCreate(el), onDismiss() |
none | Run after the message is built, and when it is dismissed |
| Event | Fired on | Detail |
|---|---|---|
nds:feedback:created |
document |
{ feedback, options }, after the message is in place |
nds:feedback:dismiss |
document |
{ feedback }, before the message is removed |
The full API is in the banner of _js/nds-feedback.js.