Message
Short messages: types, display time, queue, update and Promise lifecycle.
When to use
message gives a short temporary response to an action: saving, error or waiting. It doesn't stop working and usually disappears on its own. For a permanent message next to the fields, use Alert; for a detailed notification with actions, use Notification.
CSS prefixes message show global ConfigProvider.prefixCls and local prefixCls without resetting state. The prefix is set by MessageHolder; queue, handles and message timing do not depend on it. For App, the same parameter is set via message.prefixCls. The example is closed manually; holder is released when leaving the page.
Instance and message surface
Create a queue with createMessage() and mount one MessageHolder under the provider you want to use. Create the instance inside a component so each user and each independent area has its own queue.
| Problem | Opportunity | Example |
|---|---|---|
| Show result | message.info/success/error |
Main scenario |
| Change show time | duration, pauseOnHover |
Time and pause |
| Replace expectation with result | identical key |
Update |
| Wait for completion | callable thenable handle | Subsequence |
| Limit messages | maxCount |
Queue |
| Collapse a long list | stack, threshold |
Message stack |
| Connect theme design | theme.components.Message |
Message Subject |
Pass an object with content to open(). Typed methods such as message.success() also accept text, a number or a snippet. The number 0 is visible. With null or a boolean, the text is empty. Set type: null for a message without a built-in status icon. A duration and a close callback passed as positional arguments take precedence over the corresponding object fields.
Update, Timer and Termination
duration is measured in seconds, the default instance value is 3. Zero disables automatic closing. loading also uses the instance duration by default: to wait without a timer, set duration:0 explicitly.
Calling the API again with the same key updates the content and display time. This lets you replace a loading message with the result. When the queue reaches maxCount, each new message replaces the oldest one.
The returned handle can be called as a closure function and awaited via await. The result true means the message is completed, false means the holder is disconnected. onClose is not called when detached. For consistency after await, check the result and the owner's relevance; resetting or leaving the page should not trigger a later continuation.
destroy(key) closes the desired entry, destroy() — the queue. onClose is called when closing begins, and await waits for completion. These events do not confirm that data has been saved on the server.
Stack and placement
Enable stack to make a long list take up less space. By default, the fourth message collapses the list to the newest card. The earlier messages stay in the queue. Hover over the stack to expand it. While the pointer is over the stack, timers pause for messages with pauseOnHover enabled. In the example, you can change the threshold or turn stacking off.
To mount the list in a different DOM element, pass getContainer to MessageHolder. The list is still positioned relative to the viewport. If the getter returns no element, the library tries ConfigProvider.getPopupContainer. If that also yields no element, it uses document.body. With neither getter set, the list stays with its holder. Container example.
Context, availability and limitations of
Holder receives the ConfigProvider context where it is located. top specifies the position of the surface. message design tokens change the background, padding, and layer; local style holder and entries take precedence. Changing the theme does not require re-open and should not restart the closing time.
role selects status or alert. For normal results, avoid urgent announcements unless necessary. Leave the important error also available next to the action, so that a short message is not the only explanation.
In the styling example, ConfigProvider.message sets classes and styles for messages under the provider. Use classNames and styles to target the list, text or icon. Classes are combined. Styles are applied in order from the provider to the holder and then to the individual message. Its own style takes precedence.
An alternative to manual createMessage/MessageHolder is App. Child App.useApp() returns message with the same methods and already connected holder. App Defaults apply to new calls; existing timers are not restarted.
Examples
Normal message
Independent instance and one MessageHolder.
<script lang="ts">
import { Button, MessageHolder, createMessage } from '@woodger/antd';
const message = createMessage();
</script>
<MessageHolder message={(message)} top={240} id="message-basic-notices" />
<Button onclick={() => message.info(("Welcome to the documentation."))}>
{("Show regular message")}
</Button>
Message types
Success, warning and error.
<script lang="ts">
import { Button, MessageHolder, createMessage } from '@woodger/antd';
const message = createMessage();
</script>
<style>
.actions {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
</style>
<MessageHolder message={(message)} top={240} id="message-types-notices" />
<div class="actions">
<Button onclick={() => message.success(("Changes have been published."))}>
{("Show success")}
</Button>
<Button
onclick={() => message.warning(("Check your publishing settings."))}
>{("Show warning")}</Button>
<Button onclick={() => message.error(("Publishing failed."))}>
{("Show error")}
</Button>
<Button onclick={() => message.destroy()}>{("Remove type messages")}</Button>
</div>
Display time and pause
duration, pauseOnHover, onClose and callable handle.
<script lang="ts">
import {
Button,
Checkbox,
InputNumber,
MessageHolder,
createMessage,
type MessageHandle
} from '@woodger/antd';
const message = createMessage();
let duration = $state(3);
let pauseOnHover = $state(true);
let closed = $state(0);
let handle = $state.raw<MessageHandle>();
</script>
<style>
.settings {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 16px;
}
output {
display: block;
margin-top: 16px;
}
</style>
<MessageHolder message={(message)} top={240} id="message-duration-notices" />
<div class="settings">
<InputNumber
aria-label={("Message Duration")}
min={0}
max={10}
value={duration}
onValueChange={next => { duration = next ?? 0; }}
/>
<Checkbox bind:checked={pauseOnHover}>{("Pause message on hover")}</Checkbox>
<Button onclick={() => {
handle = message.info(({
key: 'duration',
content: "Message with the selected time.",
duration,
pauseOnHover,
onClose: () => { closed++; handle = undefined; }
}));
}}>{("Show with selected time")}</Button>
<Button
disabled={!handle}
onclick={() => handle?.()}
>{("Close via handle")}</Button>
</div>
<output aria-label={("Closing Message")}>{("Closed: ")}{closed}</output>
loading and update
One key for anticipation, success and error.
<script lang="ts">
import { Button, MessageHolder, createMessage } from '@woodger/antd';
const message = createMessage();
</script>
<style>
.actions {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
</style>
<MessageHolder message={(message)} top={240} id="message-update-notices" />
<div class="actions">
<Button onclick={() => message.loading(({
key: 'publish',
content: "We are publishing changes...",
duration: 0
}))}>{("Start publication")}</Button>
<Button onclick={() => message.success(({
key: 'publish',
content: "Changes have been published.",
duration: 3
}))}>{("Complete publication")}</Button>
<Button onclick={() => message.error(({
key: 'publish',
content: "Publish error.",
duration: 3
}))}>{("Exit with error")}</Button>
<Button onclick={() => message.destroy('publish')}>{("Remove post")}</Button>
</div>
Sequence via await
Completion, cancellation and protection against late continuation.
<script lang="ts">
import { onDestroy } from 'svelte';
import { Button, MessageHolder, createMessage } from '@woodger/antd';
const message = createMessage();
let result = $state(("Sequence not started."));
let running = $state(false);
let generation = 0;
let active = true;
async function start() {
if (running) {
return;
}
running = true;
const current = ++generation;
result = ("Checking the data.");
const closed = await message.loading(({
content: "Check before publication...",
duration: 1,
pauseOnHover: false
}));
if (!closed || !active || current !== generation) {
return;
}
result = ("Check completed.");
await message.success(({
content: "Check completed successfully.",
duration: 1,
pauseOnHover: false
}));
if (active && current === generation) {
result = ("Sequence completed.");
running = false;
}
}
function reset() {
generation++;
message.destroy();
running = false;
result = ("Sequence cancelled.");
}
onDestroy(() => { active = false; generation++; });
</script>
<style>
.actions {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
output {
display: block;
margin-top: 16px;
}
</style>
<MessageHolder message={(message)} top={240} id="message-promise-notices" />
<div class="actions">
<Button disabled={running} onclick={() => { void start(); }}>
{("Start Message thread")}
</Button>
<Button onclick={reset}>{("Cancel Message thread")}</Button>
</div>
<output aria-label={("Message chain")}>{result}</output>
Queue limit
Once there are three messages, each new one replaces the oldest.
<script lang="ts">
import { Button, MessageHolder, createMessage } from '@woodger/antd';
const message = createMessage({ maxCount: 3, duration: 0 });
let sequence = $state(0);
</script>
<style>
.actions {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
</style>
<MessageHolder message={(message)} top={240} id="message-queue-notices" />
<div class="actions"><Button onclick={() => message.info((`Queue message no.${++sequence}`))}>{("Add to Message queue")}</Button>
<Button
onclick={() => message.destroy()}
>{("Clear queue Message")}</Button></div>
Message stack
Add a few import messages. Hover over the stack to see them all.
<script lang="ts">
import { Button, Checkbox, Flex, InputNumber, MessageHolder, createMessage } from '@woodger/antd';
const thresholdId = $props.id();
const message = createMessage({ duration: 0 });
let enabled = $state(true);
let threshold = $state(3);
let sequence = 0;
function reportImport() {
sequence += 1;
const filename = `report-${sequence}.csv`;
const content = ("Imported file " + String((filename)) + "");
message.success(content);
}
</script>
<MessageHolder {message} top={160} stack={enabled ? { threshold } : false} />
<Flex vertical align="start" gap="medium">
<Flex align="center" wrap gap="small">
<Checkbox bind:checked={enabled}>{("Collapse the list")}</Checkbox>
<label for={thresholdId}>{("Stack threshold")}</label>
<InputNumber id={thresholdId} value={threshold} min={1} max={10} step={1} precision={0}
disabled={!enabled} onValueChange={value => { threshold = value ?? 1; }} />
</Flex>
<Flex wrap gap="small">
<Button type="primary" onclick={reportImport}>
{("Show import result")}
</Button>
<Button onclick={() => message.destroy()}>{("Clear messages")}</Button>
</Flex>
</Flex>
Content and design
The tip and the error share a text style. The border changes with the message type.
<script lang="ts">
import { Button, ConfigProvider, Flex, MessageHolder, createMessage } from '@woodger/antd';
import type { MessageSemanticProps } from '@woodger/antd';
const message = createMessage({ duration: 5 });
const appearance = {
classNames: { title: 'settings-message-title' },
styles: { root: 'border-radius: 12px' }
};
function statusStyles({ props }: { props: MessageSemanticProps }) {
if (props.type === 'error') {
return { root: 'border-inline-start: 3px solid var(--ant-color-error)' };
}
return { root: 'border: 1px dashed var(--ant-color-info)' };
}
function showTip() {
message.info({ content, icon, class: 'message-custom', styles: statusStyles });
}
function showError() {
message.error({
key: 'settings-error',
content: ("Could not save settings."),
styles: statusStyles,
onClick: () => message.destroy('settings-error')
});
}
</script>
<style>
:global(.settings-message-title) { font-weight: 600; }
</style>
{#snippet icon()}<span aria-hidden="true">★</span>{/snippet}
{#snippet content()}
<span><strong>{("Tip:")}</strong>{(" theme settings are saved after reboot.")}</span>
{/snippet}
<ConfigProvider message={appearance}>
<MessageHolder {message} top={240} id="message-custom-notices" />
<Flex wrap gap="small">
<Button onclick={showTip}>{("Show your content Message")}</Button>
<Button onclick={showError}>{("Show save error")}</Button>
<Button onclick={() => message.destroy()}>{("Clear messages")}</Button>
</Flex>
</ConfigProvider>
Component message Theme
Background, padding and layer; changing the topic preserves the queue, text and closing date of the message.
<script lang="ts">
import {
Button,
Checkbox,
ConfigProvider,
Input,
MessageHolder,
createMessage
} from '@woodger/antd';
import type { MessageHandle } from '@woodger/antd';
const message = createMessage({ pauseOnHover: false });
let enabled = $state(true);
let content = $state(("Checking the Message topic."));
let handle = $state.raw<MessageHandle>();
const tokens = { contentBg: '#fffbe6', contentPadding: '18px 24px', zIndexPopup: 2300 };
</script>
<style>
.settings {
display: grid;
gap: 24px;
}
.actions {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
label {
display: grid;
gap: 8px;
}
</style>
<ConfigProvider direction="rtl" theme={{ components: { Message: enabled ? tokens : {} } }}>
<MessageHolder message={(message)} top={240} id="message-theme-notices" />
<div class="settings">
<Checkbox bind:checked={enabled}>{("Apply Message tokens")}</Checkbox>
<label>{("Message text\n ")}<Input
bind:value={content}
aria-label={("Subject text Message")}
/>
</label>
<div class="actions">
<Button onclick={() => {
handle = message.info(({ key: 'theme', content, duration: 0 }));
}}>{("Check Message thread")}</Button>
<Button onclick={() => message.info(({
key: 'timed-theme', content: "Message for two seconds.", duration: 2,
class: 'message-theme-timed'
}))}>{("Show for 2 seconds")}</Button>
<Button disabled={!handle} onclick={() => { handle?.(); handle = undefined; }}>
{("\n Close via topic handle\n ")}
</Button>
</div>
</div>
</ConfigProvider>
Messages appear on top without moving focus. There are no more than three active messages left in the queue.
Saving settings
Asynchronous success, error, retry and reset.
<script lang="ts">
import { onDestroy } from 'svelte';
import { Button, Checkbox, MessageHolder, createMessage } from '@woodger/antd';
const message = createMessage({ maxCount: 3 });
let failSave = $state(false);
let pending = $state(false);
let result = $state(("Save settings or show a separate message."));
let generation = 0;
let timer: ReturnType<typeof setTimeout> | undefined;
function save() {
if (pending) {
return;
}
const failed = failSave;
failSave = false;
pending = true;
message.loading(({ key: 'save', content: "Saving settings...", duration: 0 }));
timer = setTimeout(() => {
timer = undefined;
pending = false;
if (failed) {
message.error(
({
key: 'save',
content: "Failed to save settings. Please try again."
})
);
result = ("Saving error. Can be repeated.");
}
else {
message.success(({ key: 'save', content: "Settings saved." }));
result = ("Settings saved.");
}
}, 700);
}
async function sequence() {
const current = generation;
const closed = await message.info(({ content: "Checking the data...", duration: 1 }));
if (closed && current === generation) message.success(("Data verified."));
}
function reset() {
generation++;
clearTimeout(timer);
timer = undefined;
pending = false;
message.destroy();
result = ("Example reset.");
}
onDestroy(() => {
generation++;
clearTimeout(timer);
});
</script>
<style>
.actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 12px;
}
.actions :global(.ant-btn) {
max-width: 100%;
height: auto;
min-height: var(--ant-control-height);
white-space: normal;
}
.actions :global(.ant-btn-sm) { min-height: var(--ant-control-height-sm); }
.actions :global(.ant-btn-lg) { min-height: var(--ant-control-height-lg); }
.note {
margin: 16px 0;
color: var(--ant-color-text-secondary);
}
output {
display: block;
margin-top: 20px;
color: var(--ant-color-text-secondary);
}
</style>
<MessageHolder message={(message)} id="showcase-messages" />
<div class="actions"><Button type="primary" loading={pending} onclick={save}>
{("Save settings with message")}
</Button><Checkbox
bind:checked={failSave}
>{("Next save error Message")}</Checkbox><Button
onclick={() => { void sequence(); }}
>{("Serial messages")}</Button><Button
onclick={reset}
>{("Reset example Message")}</Button></div>
<p class="note">
{("Messages appear on top without moving focus. There are no more than three active messages left in the queue.")}
</p>
<div
class="actions"
><Button
onclick={() => message.success(("Operation completed."))}
>{("Message: success")}</Button><Button
onclick={() => message.info(("A new version of the document is available."))}
>{("Message: information")}</Button><Button
onclick={() => message.warning(("Check the entered data."))}
>{("Message: warning")}</Button><Button
onclick={() => message.error(("The operation failed."))}
>{("Message: error")}</Button></div>
<output aria-label={("Example result Message")}>{result}</output>
The prefix is set by MessageHolder; queue, handles and message timing do not depend on it. For App, the same parameter is set via message.prefixCls. The example is closed manually; holder is released when leaving the page.
CSS prefixes message
Common namespace ConfigProvider and local prefixCls; the state of the component is preserved when the name is changed.
<script lang="ts">
import { Checkbox, ConfigProvider, MessageHolder, createMessage, Button } from '@woodger/antd';
let custom = $state(true);
let local = $state(true);
const prefix = $derived(custom ? 'suite' : 'ant');
const localPrefix = $derived(local ? 'project-message' : '');
const message = createMessage({ duration: 0 });
</script>
<style>
.example,
.prefix-stage {
display: grid;
grid-template-columns: minmax(0, 1fr);
gap: 16px;
min-width: 0;
}
.controls {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
p { margin: 0; }
output { overflow-wrap: anywhere; }
</style>
<div class="example">
<div class="controls">
<Checkbox bind:checked={custom}>{("Common prefix Message suite")}</Checkbox>
<Checkbox bind:checked={local}>{("Local prefix Message")}</Checkbox>
</div>
<ConfigProvider prefixCls={prefix} theme={{ cssVar: { prefix: 'message-theme' } }}>
<div class="prefix-stage">
<MessageHolder message={(message)} prefixCls={localPrefix} top={240} />
<Button onclick={() => message.success(({
key: 'prefix',
content: "Message with prefix"
}))}>{("Show Message with prefix")}</Button>
<Button
onclick={() => message.destroy()}
>{("Close Message with prefix")}</Button>
</div>
</ConfigProvider>
<output
aria-label={("CSS prefix Message")}
>{("General: ")}{prefix}{("; local: ")}{(localPrefix
|| ("from the provider"))}</output>
<p>
{("The prefix is set by MessageHolder; queue, handles and message timing do not depend on it. For App, the same parameter is set via message.prefixCls. The example is closed manually; holder is released when leaving the page.")}
</p>
</div>
API
| Theme | Example or limitation |
|---|---|
| Hooks usage (recommended) | Svelte: createMessage and one MessageHolder in the required context. |
| Other types of message | success, warning and error. |
| Customize duration | Seconds, constant message, hover pause and handle. |
| Stack | The list collapses above the threshold. Hover to expand it. |
| Message with loading indicator | Update one record by key. |
| Promise interface | Await completion with boolean result of Svelte API. |
| Custom semantic styles | Shared text styling with different borders for tips and errors. |
| Update Message Content | The text and type are changed without duplicating the entry. |
MessageInstance
| Property | Description | Type | Default |
|---|---|---|---|
open | Create or update by key. | (config: MessageConfig) => MessageHandle | — |
info | Information message. | (content | config, duration?, onClose?) => MessageHandle | info |
success | Successful operation. | (content | config, duration?, onClose?) => MessageHandle | success |
warning | Warning. | (content | config, duration?, onClose?) => MessageHandle | warning |
error | Error. | (content | config, duration?, onClose?) => MessageHandle | error |
loading | Waiting. For a persistent message, explicitly set duration=0. | (content | config, duration?, onClose?) => MessageHandle | loading |
destroy | Close one entry or the entire queue. | (key?: string | number) => void | — |
MessageConfig
| Property | Description | Type | Default |
|---|---|---|---|
content | Strings and numbers appear as text. null and booleans leave the text empty. | string | number | boolean | null | Snippet | is required |
type | Pass null to omit the built-in status icon. | info | success | warning | error | loading | null | info |
key | Stable update ID. | string | number | is generated |
duration | Seconds; 0 disables the timer. | number | 3 |
pauseOnHover | Pause the timer under the pointer. | boolean | true |
icon | Own decorative icon. | MessageContent | by type |
role | Urgency of the announcement. | status | alert | status |
onClick | On click, currentTarget is the root element of the message. | (event: MouseEvent) => void | — |
classNames | CSS classes for message parts, as an object or a function of props. | MessageSemantic | — |
styles | Inline CSS for individual parts, as an object or a function of props. | MessageSemantic | — |
onClose | Start of closing. The holder callback does not cause detachment. | () => void | — |
class | Record root class. | string | — |
style | CSS of the entry root. | string | — |
createMessage options
| Property | Description | Type | Default |
|---|---|---|---|
duration | Total display time of the instance. | number | 3 |
maxCount | Suppresses the oldest messages when exceeded. | number | no limit |
pauseOnHover | General timer settings. | boolean | true |
MessageHolder
| Property | Description | Type | Default |
|---|---|---|---|
message | Queue instance; one connected holder is supported. | MessageInstance | is required |
id | Visual surface identifier. | string | — |
class | Surface class. | string | — |
style | CSS surfaces. | string | — |
createMessage / MessageHolder / App.message
| Property | Description | Type | Default |
|---|---|---|---|
prefixCls | Full prefix of MessageHolder and its cards. The empty string/undefined inherit ConfigProvider. Does not change the queue or timers. | string | ConfigProvider.prefixCls + "-message" |
top | Offset from the top of the viewport. Numbers are in pixels. | number | string | 8 |
rtl | Sets the text direction for this list. | boolean | ConfigProvider.direction |
getContainer | Returns the DOM element for the list. Its position is relative to the viewport. | () => HTMLElement | null | undefined | — |
stack | Collapses the list above the threshold. The default threshold is three messages. | boolean | { threshold?: number } | false |
transitionName | CSS transition name. An empty string disables animation. | string | — |
classNames | CSS classes for message parts, as an object or a function of props. | MessageSemantic | — |
styles | Inline CSS for individual parts, as an object or a function of props. | MessageSemantic | — |
MessageHolder props override the corresponding createMessage options.
Semantic DOM
Use these names in classNames and styles to target the list and individual messages.
| Element | Purpose |
|---|---|
list | Surface that displays the messages. |
listContent | List of entries. |
root | Root element of a single message. |
wrapper | Icon and text. |
icon | Decorative badge. |
title | Message content. |
Registration tokens
theme.components.Message specifies contentBg, contentPadding and zIndexPopup. The settings apply to the holder surface and messages, including nested topics and custom cssVar prefix. Local style holder and entries retain priority. Updating the theme saves the queue, surface position, and remaining display time.
| Token | Purpose |
|---|---|
zIndexPopup | CSS surface layer holder; native popover remains in the top layer. |
contentBg | Recording background. |
contentPadding | Record indents; number in px or CSS string. |
| Token | Meaning |
|---|---|
colorText | rgba(0,0,0,0.88) |
colorSuccess | #52c41a |
colorError | #ff4d4f |
colorInfo | #1677ff |
colorWarning | #faad14 |
colorBgElevated | #ffffff |
borderRadiusLG | 8 |
FAQ
Where is the contextHolder from the React example?
In Svelte use createMessage and one MessageHolder inside the desired ConfigProvider.
What does await handle return?
true after message completion, false when holder is disconnected. handle itself is called to close.
How to replace loading with the result?
Pass the same key for loading and success/error.
What does duration:0 mean?
The message remains until handle(), destroy(key) or destroy(). For loading, zero is also set explicitly.
How do I turn off message animations?
Pass transitionName="" to the holder. Supply a CSS transition name for a custom animation. Omit the option to use the built-in animation.
Do I need to reopen a message after changing the subject?
No. Tokens are applied reactively without replacing the queue and closing time.
How does a long word behave?
Transported inside the card. This is the preserved behavior of the Svelte implementation.