Ant Design Svelte

Notification

Global notifications: positions, display times, actions, updates and queues.

When to use

notification shows the event with title, details and next steps. It is suitable for background export, completion of long-running operation or application message. For a short response, Message is enough; Place an important permanent warning in the main content as well.

notification CSS prefixes show global ConfigProvider.prefixCls and local prefixCls without resetting state. NotificationHolder changes the classes of all placements and parts of the card. App uses notification.prefixCls. The queue, timers, focus and native surface are preserved.

Instance, contents and position

Create a createNotification and place one NotificationHolder inside the desired ConfigProvider. The instance has an independent queue for all positions; certain areas need separate instances.

Problem Opportunity Example
Show detailed event open, title, description Basic Notice
Select semantic status success/info/warning/error Types
Show the time until dismissal duration, showProgress, pauseOnHover Display time
Collapse notices in one placement stack Notification stack
Choose a position and mount node placement, getContainer Placement
Replace expectation with result identical key, actions Update
Run background task application model Export report

Pass text, a number or a snippet to title and description. Put buttons and links in actions. The placement option selects one of six positions along the edges of the viewport. Setting rtl changes the text direction and keeps the selected edge.

Update and show time

Repeated open with the same key updates the entry, including text, actions, type and placement. To preserve the DOM description when changing status, set the type already when opening, for example info: the appearance or removal of an icon can recreate the content wrapper.

Notices close after 4.5 seconds by default. Set duration: 0 or duration: false to keep one open. For a positive duration, showProgress displays the remaining time. The bar and timer pause together while the pointer hovers with pauseOnHover enabled or focus is inside the card. The export example uses Progress to show how much of the report is ready.

Use closable to change the close icon, set its accessible label or disable the button. If you hide the button on a persistent notice, provide another way to dismiss it. onClose runs when a card starts closing. onAllRemoved runs after the last card leaves the DOM.

By default, the fourth card in the same placement collapses the list. Hover over the stack or move focus inside it to reveal every card. Adjust stack.threshold to change the threshold, or use stack: false to keep the list expanded. To dismiss the oldest notices, set maxCount. This limit applies across all placements of the instance.

Context, design and limitations of

Holder gets local topic and direction from ConfigProvider. theme.components.Notification changes width, zIndexPopup and status backgrounds without reopening. Local CSS holder and post variables take precedence.

Without component override, status backgrounds use colorBgElevated rather than the common colorInfoBg/colorSuccessBg. An empty configuration returns the default width of 384px. Explicit width:undefined is a special case; for a given size, use a number or CSS length, without assuming max-content mode.

Use actions for keyboard-accessible buttons and links. Pass HTML attributes such as data-* or ARIA attributes to the card via props. The card’s onClick receives clicks on the card. The close button handles its own clicks.

Set a shared close icon, classes and styles with ConfigProvider.notification. Both classNames and styles accept an object or a function of { props }. Styles apply in order from provider to instance to individual card. Custom styling example.

getContainer runs in the browser. If it returns no node, the library tries ConfigProvider.getPopupContainer and then document.body. With neither function specified, the list stays next to its holder.

Instead of a manual createNotification/NotificationHolder pair, you can use App: App.useApp() returns a notification from the nearest area. Its defaults are inherited by fields, and parent and nested queues are independent. The App.notification.placement change applies to new notifications.

Examples

Regular notification

createNotification and one holder.

Standard icons

success, info, warning and error.

Closed: 0

Show time

The bar shows the time left before the notice closes.

Its closing

Text, accessible name, disabled and hidden button.

Your own icon and design

Share the title and border styles and change the icon color for one card.

Provisions

Choose a mount node, one of six screen positions and the text direction.

Accepted: 0

Update and actions

One key, new result and accept button.

Queue limit

Adding a fourth notice dismisses the oldest one.

Notification stack

Add four reports, then hover over the stack or move keyboard focus into it.

Notification status

Component notification Theme

Width, status backgrounds and layer. Changing the topic saves the comment in actions, the queue and the closing date.

Prepare a report and download it from the notification.

Export report

Operation progress, success, error, retry, cancel and real CSV.

General: suite; local: project-notification

NotificationHolder changes the classes of all placements and parts of the card. App uses notification.prefixCls. The queue, timers, focus and native surface are preserved.

CSS prefixes notification

Common namespace ConfigProvider and local prefixCls; the state of the component is preserved when the name is changed.

API

Example themes
ThemeExample or limitation
Hooks usage (recommended)Svelte: createNotification and one NotificationHolder in the required context.
Duration after which the notification box is closedSeconds, false/0 and pause on hover.
Notification with iconFour standard statuses.
Custom close buttonCustom label, accessible name, disabled and hide button.
Customized IconSnippet icon and description.
PlacementAll six physical areas of the screen.
Update Message ContentUpdate by key and action inside the notification.
StackSet the collapse threshold and expand the stack with the keyboard or pointer.
Show with progressThe bar tracks the notice’s remaining display time.
Customize progress bar colorThe notification theme’s progressBg sets the bar color.
Custom semantic stylesExtend the provider’s shared classes and styles for one card.

NotificationInstance

PropertyDescriptionTypeDefault
openCreate or update a record by key.(config: NotificationConfig) => void—
infoInformation status.(config) => voidinfo
successSuccessful operation.(config) => voidsuccess
warningWarning.(config) => voidwarning
errorError.(config) => voiderror
destroyClose one entry or the entire queue.(key?: string | number) => void—

NotificationConfig

PropertyDescriptionTypeDefault
titleTitle and available name.NotificationContent—
descriptionNotification details.NotificationContent—
actionsButtons and links for further actions.NotificationContent—
typeStandard status icon.success | info | warning | error—
iconOwn icon.NotificationContentby type
keyNon-duplicate update ID.string | numberis generated
placementtop/bottom, topLeft/topRight, bottomLeft/bottomRight.NotificationPlacementtopRight
durationSeconds; false and 0 disable the timer.number | false4.5
pauseOnHoverPause the timer under the pointer.booleantrue
closableStandard close button settings.boolean | NotificationClosabletrue
closeIconOwn label; false/null hide the button.NotificationContentcross
roleUrgency of the announcement.alert | statusalert
onCloseStart of closing. Unmount holder callback is not called.() => void—
classRecord root class.string—
styleCSS of the entry root.string—
classNamesCSS classes for individual parts of the card.NotificationSemantic—
stylesStyles for individual parts of the card.NotificationSemantic—
showProgressShows the time remaining before dismissal.booleanfalse
propsNative card attributes, including data-* and ARIA.NotificationRootAttributes—
onClickHandles clicks on the card. The close button handles its own clicks.(event: MouseEvent) => void—

NotificationClosable

PropertyDescriptionTypeDefault
disabledDisable standard button.booleanfalse
closeIconTakes precedence over closeIcon configuration.NotificationContentcross
aria-labelAvailable button name.stringlocale.closeText
onCloseRuns before the card’s onClose when the close button is pressed or the timer expires.() => void—

createNotification options

PropertyDescriptionTypeDefault
placementGeneral position of the instance.NotificationPlacementtopRight
durationTotal duration.number | false4.5
pauseOnHoverGeneral timer pause.booleantrue
maxCountGeneral limit for all placements.numberno limit
showProgressShows the time remaining before dismissal.booleanfalse
prefixClsFull CSS prefix for the list and its cards.stringConfigProvider.prefixCls + "-notification"
topTop surface offset.number24
bottomBottom surface offset.number24
stackCollapse threshold for each placement. Use false to keep the list expanded.boolean | { threshold?: number }{ threshold: 3 }
rtlText direction. The placement option selects the side of the screen.booleanConfigProvider.direction
getContainerSelects the DOM node where the notification list appears.() => HTMLElement | ShadowRoot | null | undefined—
closeIconCustom close icon for all cards.NotificationContentConfigProvider.notification.closeIcon
classNamesCSS classes for this instance’s list and cards.NotificationSemantic—
stylesStyles for this instance’s list and cards.NotificationSemantic—
onAllRemovedRuns after the last card leaves the DOM.() => void—

NotificationHolder

PropertyDescriptionTypeDefault
prefixClsFull CSS prefix for the list and its cards.stringConfigProvider.prefixCls + "-notification"
topTop surface offset.number24
bottomBottom surface offset.number24
stackCollapse threshold for each placement. Use false to keep the list expanded.boolean | { threshold?: number }{ threshold: 3 }
rtlText direction. The placement option selects the side of the screen.booleanConfigProvider.direction
getContainerSelects the DOM node where the notification list appears.() => HTMLElement | ShadowRoot | null | undefined—
closeIconCustom close icon for all cards.NotificationContentConfigProvider.notification.closeIcon
classNamesCSS classes for this instance’s list and cards.NotificationSemantic—
stylesStyles for this instance’s list and cards.NotificationSemantic—
onAllRemovedRuns after the last card leaves the DOM.() => void—
notificationQueue instance; one connected holder.NotificationInstanceis required
idSurface identifier with all placements.string—
classSurface class.string—
styleCSS surfaces.string—

Instead of React hook/static methods, an independent createNotification and NotificationHolder are used. Open methods return void; closing is done by destroy(key) or a standard button.

Semantic DOM

The list and listContent slots apply to the list. The remaining slots apply to a card.

SlotCSS classPurpose
list.ant-notification-listIndividual placement group.
listContent.ant-notification-list-contentList of entries.
root.ant-notification-noticeRecord with role, available name, class/style.
wrapper.ant-notification-notice-wrapperIcon and text; is created only if there is an icon.
section.ant-notification-notice-sectiontitle/description pair; is created only if both blocks are present.
icon.ant-notification-notice-iconDecorative badge.
title.ant-notification-notice-titleHeading.
description.ant-notification-notice-descriptionDescription.
actions.ant-notification-notice-actionsActions directly at the root of the post, next to the wrapper or text.
close.ant-notification-notice-closeClose button.
progress.ant-notification-notice-progressBar showing the remaining display time.

Registration tokens

In the theme example, progressBg sets the bar color. Choose “Show for 2 seconds” to see it.

TokenPurpose
widthCard width: number in px or CSS length; limited to viewport.
zIndexPopupCSS group placements layer; native popover remains in the top layer.
progressBgColor of the countdown bar.
colorInfoBgExplicit background of the info record.
colorSuccessBgExplicit background of success record.
colorWarningBgExplicit background of warning record.
colorErrorBgExplicit background of error record.
Common tokens of the current topic
TokenMeaning
colorBgElevated#ffffff
colorTextrgba(0,0,0,0.88)
colorTextHeadingrgba(0,0,0,0.88)
colorSuccess#52c41a
colorError#ff4d4f
colorInfo#1677ff
colorWarning#faad14
borderRadiusLG8

FAQ

How to get the ConfigProvider context?

Place the NotificationHolder of your createNotification inside the provider. An instance requires one holder.

What is the difference between notification and Message?

notification is designed for title, details and actions. Message gives a short temporary response.

How to update an existing entry?

Repeat open with the same key and new settings.

How to save DOM descriptions when changing status?

Set the type already upon opening. Adding or removing an icon can recreate the text wrapper.

When does the timer pause?

With hover with pauseOnHover and with focus inside actions. false/0 disables auto-close.

How do I change the countdown color?

Set theme.components.Notification.progressBg and enable showProgress. In the theme example, choose the two-second notification.

Where did the previous notices go?

Move focus into the stack to reveal its cards. If you set a queue limit, adding a notice can dismiss the oldest one.

Do I need to recreate the notification after changing the theme?

No. Design tokens are refreshed reactively, maintaining the queue and closing dates.

Why are the status backgrounds the same?

The default is colorBgElevated. Different backgrounds can be set with notification component tokens.

How to return the standard width?

Remove override or pass an empty component configuration. An explicit width:undefined is different from a missing field.