Skip to content

CdsToastQueue

New in v4.0

A queue of pop-up notifications built on CdsToast. Put the messages into the v-model array — the queue will show them one by one or as a stack, respect the limit of simultaneously visible toasts and close the ones that are done.

Storybook GitLab
Test coverage: 99% — good coverage
API in specs
58 / 58 props, events, slots and exposed members with a test
Test cases
34 unit · 2 browser
Known bugs
2 pinned by an it.fails test
Code coverage
99.2% lines · 87.2% branches measured in v4.0.0-alpha.13
A11y (axe)
6 recommendations in 6 stories measured in v4.0.0-alpha.11

For a single notification — a save confirmation, for example — CdsToast is enough.

Variations ​

The message queue ​

A message is a string or an object with toast props. Add messages to the v-model array: the queue shows them one by one, and the rest wait for their place. The closable prop adds a close button with the close-text label to every toast. Props shared by the toasts — location, timer, status and others — are set right on the queue: they apply to every message. While the browser tab is hidden, auto-closing is paused.

Limit and overflow ​

The total-visible prop caps the number of simultaneously visible toasts: a new one takes the place at the edge of the screen and pushes the previous ones aside. The display-strategy prop decides what to do with the extra ones: hold (the default) keeps them in the queue until a place frees up, overflow closes the oldest ones.

The stack ​

The collapsed prop folds all the toasts except the last one into a compact stack. Hover the cursor — the stack unfolds, and the timers pause while the cursor is inside.

Slots ​

The slots customize every toast of the queue; each of them receives the item object of the current message.

SlotDescription
headerHeader of the toast
textText of the toast. Replaces the text of the message
actionsActions of the toast. props carries an onClick handler that closes the toast
itemFull replacement of the toast. The message props are passed through CdsDefaultsProvider

Scenarios ​

Background operations ​

Pass a promise in the message — the toast gets a loading indicator and does not close until the operation is done. The success and error callbacks return the toast props for the result: the status, the text and the auto-close delay.

Notification center ​

The events of the application pile up into a single queue in the corner of the screen: location="bottom right" moves the toasts out of the working area, collapsed hides the older ones in a stack, and closable lets the user close every notification.

Controlling the queue ​

The onDismiss callback of a message receives the reason it was closed — auto, dismissed, overflow or cleared — and the exposed clear() method closes all the toasts and empties the queue.

API ​

Props

NameTypeDefaultDescription
absoluteboolean | undefined—Positions the element absolutely instead of fixed. This is useful for overlays that must stay inside a certain area, for example inside a container with position: relative.
activator(string & {}) | Element | "parent" | ComponentPublicInstance | undefined—The element that activates the component
activatorPropsRecord<string, any> | undefined{}Props for the activator element
attachstring | boolean | Element | undefined—Sets the DOM element the overlay content is moved to. It accepts a direct element reference, a querySelector string, or true to disable moving. By default the body element is used. Changing this prop is usually not recommended except for edge cases: the default positioning algorithm handles most scenarios better than it can without moving, and unexpected behavior may appear if the menu ends up being a child of its activator.
bgColorstring | undefined—Background color of the component
closablestring | boolean | undefined—Adds a close button to every toast. A string value sets the color of the button.
closeDelaystring | number | undefined—Delay in milliseconds before the component closes. Works only together with open-on-hover.
closeOnBackboolean | undefinedfalseCloses the overlay content when the browser Back button is pressed or $router.back() is called, cancelling the original navigation. persistent overlays cancel the navigation and animate as if they were clicked outside instead of closing.
closeOnContentClickboolean | undefined—Hide the component on a click on the content
closeTextstring | undefined'$cds.dismiss'Text of the close button.
collapsedboolean | undefined—Folds the inactive toasts into a stack under the last visible one.
containedboolean | undefined—Limits the size of the component and of its grid to the offset parent. Implies the absolute and attach props. (Note: the parent element must have position: relative.)
contentstring | number | undefined—Content displayed in the component.
contentClassany—Applies a custom class to the content element. This is handy because the content is moved to the beginning of the cds-app component (unless attach is set) and cannot be selected with classes passed to the component directly.
contentPropsany—Applies custom props to the moved content
disabledboolean | null | undefinednullDisabled state
displayStrategy"overflow" | "hold" | undefined'hold'Strategy when totalVisible is exceeded: hold — wait until a toast closes, overflow — push the oldest ones out.
eagerboolean | undefined—Renders the content of the component right away. Useful when you have content that is not in the DOM but has to be indexed for SEO.
gapstring | number | undefined8Gap between the toasts, in pixels.
heightstring | number | undefined—Component height
iconfalse | IconValue | undefinednullIcon before the content. Taken from status by default; false hides the icon.
loadingboolean | undefined—Shows a loading indicator instead of the icon.
locationAnchor | null | undefined'top center'Position of the element relative to its container, for example "top left", "center", "bottom right".
locationStrategy"static" | "connected" | LocationStrategyFunction | undefined'static'Sets the way the overlay content is positioned. By default static is used, which centers the content in its container. Use connected to attach the content to the activator element.
maxHeightstring | number | undefined—Maximum component height
maxWidthstring | number | undefined—Maximum component width
minHeightstring | number | undefined—Minimum component height
minWidthstring | number | undefined—Minimum component width
modelValuereadonly ToastMessage[] | undefined[]The queue of messages (v-model). A string or an object with toast props.
opacitystring | number | undefined—Opacity of the scrim element. Applies only when scrim=true.
openDelaystring | number | undefined—Delay in milliseconds before the component opens. Works only together with open-on-hover.
openOnClickboolean | undefined—Show the component on a click on the activator
openOnFocusboolean | undefined—Show the component when the activator gets focus
openOnHoverboolean | undefined—Show the component on hover over the activator
originAnchor | "auto" | "overlap" | undefined'auto'Sets the anchor point of the overlay content that is aligned with the location anchor of the target. With "auto" the opposite side of the location point is used. With "overlap" the same anchor point is used, so the overlay overlaps the target. It also sets the CSS transform-origin property for the enter/leave transitions.
position"absolute" | "static" | "fixed" | "relative" | "sticky" | undefined—CSS positioning of the component — the value of the position property
prependAvatarstring | undefined—Source of the avatar image before the content. Takes priority over the icon.
reverseTimerboolean | undefined—Reverses the timer bar: it fills up instead of draining.
status"progress" | "danger" | "success" | "warning" | "info" | undefined'info'Semantic status — drives the color and the default icon.
target(string & {}) | Element | "parent" | ComponentPublicInstance | "cursor" | [x: number, y: number] | undefined—When locationStrategy is set to "connected", specify the element or the array of x, y coordinates the overlay is positioned against. By default the activator element is used.
textstring | number | undefined—Text displayed in the component.
textColorstring | undefined—Text color of the component
themestring | undefined—Component theme
timeoutstring | number | undefined5000Delay in milliseconds before the toast hides automatically. The value -1 turns auto-closing off.
timerboolean | "top" | "bottom" | undefinedfalseShows the timer bar until auto-closing: true/top — on top, bottom — at the bottom.
timerColorstring | undefined—Color of the timer bar.
titlestring | undefined—Heading of the toast.
totalVisiblestring | number | undefined1Maximum number of simultaneously visible toasts.
transitionstring | boolean | (TransitionProps & { component?: Component | undefined; }) | null | undefined'cds-toast-transition'Transition animation
verticalboolean | undefined—Vertical layout: the actions move below the content.
widthstring | number | undefined—Component width
zIndexstring | number | undefined2000The z-index value of the component.

Events

NameTypeDescription
update:modelValue[value: ToastMessage[]]The queue of messages changed.

Slots

NameTypeDescription
actions{ item: ToastMessage; props: { onClick: () => void; }; }Slot for the actions of the toast.
header{ item: ToastMessage; }Slot for the header of the toast.
item{ item: ToastMessage; }Slot that fully replaces the toast. The toast props are passed through CdsDefaultsProvider.
text{ item: ToastMessage; }Slot for the text of the toast.

Exposed

NameTypeDescription
clear() => voidEmpties the queue and closes all the visible toasts.