Modal
Modal windows: confirmation, asynchronous action, footer and localization.
When to use
Modal asks for a solution or displays a limited problem on top of the current page. It is suitable for confirmation and short form. For a side subtask with large content, use Drawer; for a simple confirmation next to the action, use Popconfirm.
Modal CSS prefixes show global ConfigProvider.prefixCls and local prefixCls without resetting state. ModalConfirmConfig.prefixCls modifies a separate context confirmation; a missing or empty string uses the holder provider prefix. The open dialog and draft are not recreated; namespace Button is independent.
Opening and confirmation
bind:open binds the state to the application. title is optional and accepts a scalar or Snippet, children is an optional Snippet of the body. An empty/null/boolean title removes the header, the number 0 remains visible. Without a title, specify aria-label or aria-labelledby. By default, the footer contains confirm and cancel buttons.
| Problem | Opportunity | Example |
|---|---|---|
| Open window | bind:open, title |
Main window |
| Wait for the operation | onOk, confirmLoading |
Asynchronous action |
| Replace bottom actions | footer snippet or null |
Your footer |
| Set up closing | closable, keyboard, mask.closable |
Closing rules |
| Translate buttons | ConfigProvider.locale | Locale |
| Connect design | theme.components.Modal |
Window theme |
Without onOk, the standard button closes the window. When onOk is passed, the Promise result is not automatically processed: the callback contract is () => void. The application sets confirmLoading, executes the request, shows an error and closes open only after success.
confirmLoading blocks repeated confirmation and regular cancellation. Don't leave it enabled after an error occurs. Asynchronous example shows replay and protection of the operation result.
Contextual confirmations
Place ModalHolder under the provider you want to use and pass it the controller from createModal(). Its dialogs inherit the theme, locale, text direction and container from that part of the application.
Five types return ModalConfirmHandle. Await handle gives true after OK, false after canceling, destroy or deleting the holder. confirm shows OK/Cancel; info/success/error/warning - only OK. By default, the width is 416px, the cross is hidden, Escape is enabled, and canceling by background is disabled. title/content and button captions accept scalar/Snippet.
When a confirmation has both buttons, use focusable.autoFocusButton to focus Cancel on open. okButtonProps and cancelButtonProps customize the built-in buttons. These settings also work with handle.update().
onOk/onCancel without an argument closes the window after a synchronous result. A callback with a declared argument close controls manual closure. The returned Promise includes loading of the corresponding button; fulfillment closes, rejection leaves a window for repetition. Confirmation check shows this difference with declarative Modal. While waiting for OK, cancellation via Escape/close/mask remains possible and closes immediately with onCancel.
update and destroy belongs to the handle of a specific window. update takes an object of either previous → patch. destroy doesn't call onCancel and awaits with false. afterClose is called after the native dialog is actually closed. Removing the holder clears the queue and frees the modal without onCancel/afterClose; late Promise does not open the window again. In SSR, the controller does not access the DOM, the holder does not open the modality.
Keep the controller and its holder in the same component instance. When using App.useApp(), the holder is already mounted.
Static confirmations
Call Modal.confirm() from an event handler to open a separate confirmation dialog. For a message, use Modal.info(), Modal.success(), Modal.warning() or Modal.error(). In the clear draft example, canceling keeps the text. Confirming clears the field and shows the result in the same dialog.
The call returns a ModalStaticHandle. Pass an object to update() to change individual settings. An updater function receives the current settings and returns the entire next configuration, so keep any fields you need with ...previous. Use update({ open: false }) to hide the dialog and reopen it later. Call destroy() to close it permanently.
In the dialog management example, Modal.destroyAll() closes both the static warning and the context dialog behind it. This also closes dialogs from createModal() and App.useApp().modal, resolving their pending results to false. During server rendering, static methods return a handle without creating a dialog. Set the theme and language of static dialogs.
Cancellation, Focus and Lifecycle
closable controls the close button, keyboard handles Escape and mask.closable handles a backdrop click. Use focusable to control focus trapping and restoration, and scrollLock to control page scrolling.
By default the content is mounted before the first open. forceRender={false} defers mounting until the dialog opens. With destroyOnHidden, closing discards the content and its local draft. An explicit forceRender={true} keeps the content mounted even in that mode. Try it with an input.
Title and content show Snippet, the number 0, and an empty window with an explicit accessible name. aria-labelledby takes precedence over aria-label, then the generated title id is used. afterClose notifies that it has actually closed; changing the title does not recreate the dialog and its fields.
getContainer={false} keeps the dialog in the current DOM branch. afterClose followed by afterOpenChange(false) signals that closing is complete. Reopening during the exit transition cancels these close callbacks.
footer, loading and appearance
In the custom footer example, the footer snippet reorders the built-in OkBtn and CancelBtn. They retain their labels, handlers and settings from okButtonProps and cancelButtonProps. Pass null to remove the footer. With loading, declarative Modal shows a skeleton in the body and hides the footer. Loading example.
The size example shows how to set width in pixels, CSS units or by screen size. centered chooses the alignment. Context confirmations accept a number or CSS string for their width. Modal design tokens control the appearance of the dialog.
In the note example, the editor and the preview share a modalRender snippet. It receives the built-in panel, so a custom wrapper can keep the heading, field and action buttons. ConfigProvider.modal.styles sets the spacing in both dialogs. The editor uses styles.body to reduce that spacing while you type.
transitionName and maskTransitionName set separate CSS transitions for the dialog and backdrop. An empty string disables the corresponding animation. mousePosition sets the zoom origin in page coordinates.
In container example, an open dialog is transferred between two DOM nodes. The new getter with the old node retains the contents; changing a node recreates it and resets the local draft.
Examples
Regular window
Confirm, Tab and return focus.
<script lang="ts">
import { Button, Modal } from '@woodger/antd';
let open = $state(false);
let confirmed = $state(0);
</script>
<style>
output {
display: block;
margin-top: 16px;
}
</style>
<Button onclick={() => { open = true; }}>{("Open normal window")}</Button>
<Modal title={("Regular window")} bind:open onOk={() => { confirmed++; open = false; }}>
<p>{("Tab remains inside the window. Escape or cancel returns focus to the open button.")}</p>
</Modal>
<output
aria-label={("Modal Confirmations")}
>{("Confirmed: ")}{confirmed}</output>
Asynchronous confirmation
Controlled wait, error and retry.
<script lang="ts">
import { onDestroy } from 'svelte';
import { Alert, Button, Checkbox, Modal } from '@woodger/antd';
let open = $state(false);
let loading = $state(false);
let fail = $state(false);
let error = $state(false);
let saved = $state(0);
let timer: ReturnType<typeof setTimeout> | undefined;
function save() {
if (loading) {
return;
}
loading = true;
error = false;
timer = setTimeout(() => {
loading = false;
if (fail) {
error = true;
}
else {
saved++;
open = false;
}
}, 700);
}
onDestroy(() => clearTimeout(timer));
</script>
<style>
.content {
display: grid;
gap: 20px;
}
output {
display: block;
margin-top: 16px;
}
</style>
<Button onclick={() => { open = true; }}>{("Open asynchronous window")}</Button>
<Modal
title={("Saving settings")}
bind:open
confirmLoading={loading}
onOk={save}
okText={("Save")}
>
<div class="content">
<Checkbox bind:checked={fail} disabled={loading}>
{("Check saving error")}
</Checkbox>
{#if error}<Alert
type="error"
title={("Failed to save")}
description={("Clear the error flag and try again.")}
showIcon
/>{/if}
<p>{("The example itself controls loading and open; the returned Promise does not automatically close the Modal.")}</p>
</div>
</Modal>
<output
aria-label={("Modal Saves")}
>{("Saved: ")}{saved}</output>
Closing rules
Escape, standard cross, mask.closable to close by background and cancel button.
<script lang="ts">
import { Button, Checkbox, Modal } from '@woodger/antd';
let open = $state(false);
let keyboard = $state(false);
let closable = $state(true);
let closeOnBackdrop = $state(true);
</script>
<style>
.settings {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 16px;
}
</style>
<div class="settings"><Checkbox bind:checked={keyboard}>{("Escape in Modal")}</Checkbox>
<Checkbox bind:checked={closable}>{("Cross Modal")}</Checkbox>
<Checkbox bind:checked={closeOnBackdrop}>{("Close Modal by background")}</Checkbox>
<Button
onclick={() => { open = true; }}
>{("Open with closing rules")}</Button></div>
<Modal title={("Closing rules")} bind:open {keyboard} {closable} mask={{
closable: closeOnBackdrop
}}>
<p>{("The “Cancel” button remains available regardless of Escape, cross and background close.")}</p>
</Modal>
Localization
Labels of standard buttons from ConfigProvider.locale.
<script lang="ts">
import { Button, Checkbox, ConfigProvider, Modal, enUS, ruRU } from '@woodger/antd';
let open = $state(false);
let english = $state(false);
</script>
<style>
.settings {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 16px;
}
</style>
<ConfigProvider locale={english ? enUS : ruRU}>
<div class="settings"><Checkbox bind:checked={english}>English buttons</Checkbox>
<Button
onclick={() => { open = true; }}
>{("Open localized window")}</Button></div>
<Modal title={("Localization Modal")} bind:open><p>{("Button and cross labels are taken from ConfigProvider.locale.")}</p></Modal>
</ConfigProvider>
Width and position
Fixed or responsive width, aligned near the top or centered.
<script lang="ts">
import { Button, Flex, Modal, RadioGroup, type ModalWidth } from '@woodger/antd';
let position = $state('center');
let preset = $state('520px');
let open = $state(false);
const widths: Record<string, ModalWidth> = {
'520px': 520,
'800px': 800,
responsive: { xs: '92vw', md: 640 }
};
</script>
<Flex vertical align="start" gap="medium">
<RadioGroup
aria-label={("Modal position")}
bind:value={position}
options={['center', 'top']}
/>
<RadioGroup
aria-label={("Modal width")}
bind:value={preset}
options={[
'520px', '800px', { value: 'responsive', label: ("Match screen size") }
]}
/>
<Button onclick={() => { open = true; }}>
{("Open with selected geometry")}
</Button>
</Flex>
<Modal
title={("Geometry Modal")}
bind:open
width={widths[preset]}
centered={position === 'center'}
>
<p>{("In responsive mode, the dialog width adjusts to the screen.")}</p>
</Modal>
Loading content
loading replaces the body with a Skeleton and hides the footer. Child components are recreated after loading.
<script lang="ts">
import { onDestroy } from 'svelte';
import { Button, Input, Modal } from '@woodger/antd';
let open = $state(false);
let loading = $state(false);
let timer: ReturnType<typeof setTimeout> | undefined;
function load() {
clearTimeout(timer);
loading = true;
timer = setTimeout(() => { loading = false; }, 1500);
}
function show() {
open = true;
load();
}
onDestroy(() => clearTimeout(timer));
</script>
<style>
.content {
display: grid;
gap: 16px;
}
</style>
<Button onclick={show}>{("Open with loading")}</Button>
<Modal
title={("Contents pending")}
bind:open
{loading}
afterClose={() => clearTimeout(timer)}
>
<div class="content">
<p>{("Data received.")}</p>
<Input
aria-label={("Loaded dialog draft")}
placeholder={("The draft resets when reloading")}
/>
<Button onclick={load}>{("Upload again")}</Button>
</div>
</Modal>
Saving content
Try keeping or discarding a draft on close.
<script lang="ts">
import { Button, Checkbox, Flex, Input, Modal } from '@woodger/antd';
let open = $state(false);
let destroyOnHidden = $state(false);
</script>
<Flex align="center" gap="medium" wrap>
<Checkbox bind:checked={destroyOnHidden}>
{("Delete draft when closing")}
</Checkbox>
<Button onclick={() => { open = true; }}>{("Check saving Modal")}</Button>
</Flex>
<Modal title={("Content status")} bind:open {destroyOnHidden}>
<Input
aria-label={("Draft Modal")}
defaultValue={("The draft is saved")}
/>
</Modal>
Changing the target container recreates the content and resets the local draft.
DOM branch and container change
getContainer=false saves the DOM branch. Changing the target container recreates the content; dialog remains modal.
<script lang="ts">
import { Button, Input, Modal } from '@woodger/antd';
let open = $state(false);
let transferredOpen = $state(false);
let alternate = $state(false);
let first = $state<HTMLDivElement>();
let second = $state<HTMLDivElement>();
let getContainer = $derived(() => (alternate ? second : first) ?? document.body);
</script>
<div data-modal-inline-example>
<Button onclick={() => { open = true; }}>
{("Open Modal in current DOM")}
</Button>
<Modal title={("Modal in the current DOM")} bind:open getContainer={false}>
<p>
{("DOM remains inside the example, and showModal uses the top layer of the browser.")}
</p>
</Modal>
</div>
<div data-modal-transfer-example>
<p>{("Changing the target container recreates the content and resets the local draft.")}</p>
<Button
onclick={() => { transferredOpen = true; }}
>{("Open Modal with transfer")}</Button>
<div data-container="first" bind:this={first}></div>
<div data-container="second" bind:this={second}></div>
<Modal
title={("Transfer Modal")}
bind:open={transferredOpen}
{getContainer}
prefixCls="example-modal"
footer={null}
>
<p>{("Container: ")}{(alternate ? "second" : "first")}</p>
<Input aria-label={("Transfer draft")} defaultValue="Начальный текст" />
<Button
onclick={() => { alternate = !alternate; }}
>{("Change container")}</Button>
</Modal>
</div>
Component Modal Theme
Background, header and padding; changing the theme saves the window, draft and RTL.
<script lang="ts">
import { Button, Checkbox, ConfigProvider, Input, Modal } from '@woodger/antd';
let open = $state(false);
let enabled = $state(true);
let draft = $state(("Draft Modal"));
const tokens = {
contentBg: '#fffbe6',
headerBg: '#fff1b8',
footerBg: '#fff1b8',
titleColor: '#874d00',
titleFontSize: 24,
titleLineHeight: 2,
contentPadding: '16px 20px'
};
</script>
<style>
.settings {
display: grid;
gap: 24px;
}
label {
display: grid;
gap: 8px;
}
</style>
<ConfigProvider direction="rtl" theme={{ components: { Modal: enabled ? tokens : {} } }}>
<Button
onclick={() => { open = true; }}
>{("Check component Modal theme")}</Button>
<Modal title={("Modal Theme")} bind:open>
<div class="settings">
<Checkbox bind:checked={enabled}>{("Apply Modal tokens")}</Checkbox>
<label>{("Draft\n ")}<Input bind:value={draft} aria-label={("Modal theme draft")} />
</label>
<p>
{("Background, title and padding are updated without closing the window and resetting the text.")}
</p>
</div>
</Modal>
</ConfigProvider>
Title and content
Snippet, numeric 0, window without title/children, ARIA name and afterClose.
<script lang="ts">
import { Button, Checkbox, Input, Modal } from '@woodger/antd';
let rich = $state(false);
let untitled = $state(false);
let empty = $state(false);
let zero = $state(false);
let draft = $state('');
let closed = $state(0);
</script>
<style>
.controls {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.body {
display: grid;
gap: 16px;
}
output {
display: block;
margin-top: 12px;
}
</style>
{#snippet heading()}
<span>{("Card ")}<em>
{("project")}
</em></span>
{/snippet}
<div class="controls">
<Button onclick={() => { rich = true; }}>{("Heading snippet")}</Button>
<Button onclick={() => { untitled = true; }}>{("Without title")}</Button>
<Button onclick={() => { empty = true; }}>{("Without content")}</Button>
</div>
<Modal bind:open={rich} title={(zero ? 0 : heading)} afterClose={() => { closed++; }}>
<div class="body">
<Input
bind:value={draft}
aria-label={("Modal header draft")}
placeholder={("Draft")}
/>
<Checkbox bind:checked={zero}>{("Numeric header 0")}</Checkbox>
</div>
</Modal>
<Modal bind:open={untitled} aria-label={("Window without title")}>
<p>{("The accessible name is specified explicitly, header is missing.")}</p>
</Modal>
<Modal bind:open={empty} aria-label={("Empty window")} />
<output
aria-label={("Closing window with snippet")}
>{("Closed: ")}{closed}</output>
Style individual dialog elements
The editor and preview share a wrapper. Adjust the spacing inside the editor.
<script lang="ts">
import { Button, Checkbox, ConfigProvider, Flex, Modal, ModalHolder, TextArea, createModal }
from '@woodger/antd';
import type { Snippet } from 'svelte';
const modal = createModal();
const noteId = $props.id();
let open = $state(false);
let compact = $state(false);
let note = $state('');
let draft = $state('');
function edit() {
draft = note;
open = true;
}
function save() {
note = draft;
open = false;
}
function preview() {
modal.info({
title: ("Note preview"),
content: note || ("The note is empty."),
modalRender: notePanel
});
}
</script>
{#snippet notePanel(content: Snippet)}
<div class="note-panel">{@render content()}</div>
{/snippet}
<ConfigProvider modal={{ styles: { body: 'padding-block: 16px' } }}>
<Flex gap="small" wrap>
<Button onclick={edit}>{("Edit note")}</Button>
<Button onclick={preview}>{("Preview note")}</Button>
</Flex>
<Modal
bind:open
title={("Edit note")}
okText={("Save")}
onOk={save}
modalRender={notePanel}
classNames={{ title: 'note-title' }}
styles={compact ? { body: 'padding-block: 4px' } : undefined}
>
<Flex vertical gap="small">
<label for={noteId}>{("Note text")}</label>
<TextArea id={noteId} bind:value={draft} rows={3} />
<Checkbox bind:checked={compact}>{("Reduce spacing")}</Checkbox>
</Flex>
</Modal>
<ModalHolder {modal} />
</ConfigProvider>
<style>
.note-panel {
border-inline-start: 4px solid var(--ant-color-primary);
border-radius: var(--ant-border-radius-lg);
}
.note-panel :global(.note-title) {
color: var(--ant-color-primary);
}
</style>
Contextual confirmations
createModal and one ModalHolder: five types and await result.
<script lang="ts">
import { Button, ModalHolder, createModal, type ModalConfirmType } from '@woodger/antd';
const modal = createModal();
const kinds = [
{ type: 'info', label: "Information" },
{ type: 'success', label: "Success" },
{ type: 'error', label: "Error" },
{ type: 'warning', label: "Warning" },
{ type: 'confirm', label: "Confirmation" }
] as const;
let result = $state(("Not opened yet"));
async function show(type: ModalConfirmType, title: string) {
const accepted = await modal[type](({
title,
content: "The context is set by the nearest ConfigProvider."
}));
result = ("" + String((type)) + ": " + String((accepted)) + "");
}
</script>
<style>
.controls {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
output {
display: block;
margin-top: 12px;
}
</style>
<div class="controls">
{#each kinds as kind (kind.type)}
<Button onclick={() => show(kind.type, kind.label)}>{(kind.label)}</Button>
{/each}
</div>
<ModalHolder {modal} />
<output aria-label={("Result of contextual Modal")}>{result}</output>
Static confirmation dialog
Modal.confirm opens a dialog. Clearing the draft shows the result in the same dialog.
<script lang="ts">
import { Button, Flex, Input, Modal, type ModalStaticHandle } from '@woodger/antd';
import { onDestroy } from 'svelte';
const draftId = $props.id();
let draft = $state(("Review the layout."));
let active: ModalStaticHandle | undefined;
onDestroy(() => active?.destroy());
function confirmClear() {
if (active) {
return;
}
const dialog = Modal.confirm({
title: ("Clear the draft?"),
content: draft,
okText: ("Clear"),
okType: 'danger',
onOk(close) {
draft = '';
dialog.update({
type: 'success',
title: ("Draft cleared"),
content: undefined,
okType: 'primary',
okText: ("Close"),
onOk: close
});
},
afterClose() { active = undefined; }
});
active = dialog;
}
</script>
<Flex vertical gap="small" align="start">
<label for={draftId}>{("Draft")}</label>
<Input id={draftId} bind:value={draft} />
<Button danger disabled={!draft} onclick={confirmClear}>
{("Clear draft")}
</Button>
</Flex>
Promise confirmation
The controller processes Promise: rejection and leaves a retry window.
<script lang="ts">
import { Button, Checkbox, ModalHolder, createModal } from '@woodger/antd';
const modal = createModal();
let fail = $state(true);
let error = $state('');
let result = $state(("Not selected yet"));
async function confirm() {
error = '';
const accepted = await modal.confirm(({
title: "Confirmation check",
content: body,
okText: "Apply",
cancelText: "Set aside",
onOk: async () => {
if (fail) {
fail = false;
error = ("Test failed. Confirm again.");
throw new Error((error));
}
}
}));
result = accepted ? ("Applied") : ("Postponed");
}
</script>
<style>
.example {
display: grid;
gap: 12px;
}
</style>
{#snippet body()}
<p>{("A rejected Promise leaves the window open for retry.")}</p>
{#if error}<p role="alert">{error}</p>{/if}
{/snippet}
<div class="example">
<Checkbox bind:checked={fail}>{("First attempt failed")}</Checkbox>
<Button onclick={confirm}>{("Confirm with verification")}</Button>
<output aria-label={("Modal test result")}>{result}</output>
</div>
<ModalHolder {modal} />
Update and destruction
Handle.update with previous settings, destroy and await completion with false.
<script lang="ts">
import { onDestroy } from 'svelte';
import {
Button, Modal, ModalHolder, createModal, type ModalConfirmHandle, type ModalStaticHandle
} from '@woodger/antd';
const modal = createModal();
let handle = $state.raw<ModalConfirmHandle>();
let warning: ModalStaticHandle | undefined;
let result = $state(("Not selected yet"));
onDestroy(() => warning?.destroy());
async function show() {
handle = modal.info(({
title: "Task status",
content: controls,
okText: "Ready"
}));
result = ("Result: " + String((await handle)) + "");
}
function update() {
handle?.update(previous => ({
title: "Updated task",
okText: previous.okText === ("Ready")
? "Close"
: "Ready"
}));
}
function confirmCloseAll() {
if (warning) {
return;
}
warning = Modal.warning({
title: ("Close all confirmations?"),
content: ("Both this warning and the task dialog will close."),
okCancel: true,
okText: ("Close all"),
onOk: Modal.destroyAll,
afterClose() { warning = undefined; }
});
}
</script>
<style>
.controls {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
output {
display: block;
margin-top: 12px;
}
</style>
{#snippet controls()}
<p>
{("Update changes the settings of the open window; destroy ends the wait with false.")}
</p>
<div class="controls">
<Button onclick={update}>{("Update confirmation")}</Button>
<Button
onclick={() => { handle?.destroy(); }}
>{("Destroy confirmation")}</Button>
<Button onclick={confirmCloseAll}>{("Close all confirmations")}</Button>
</div>
{/snippet}
<Button onclick={show}>{("Manage confirmation")}</Button>
<ModalHolder {modal} />
<output aria-label={("Modal control result")}>{result}</output>
ModalConfirmConfig.prefixCls modifies a separate context confirmation; a missing or empty string uses the holder provider prefix. The open dialog and draft are not recreated; namespace Button is independent.
Modal CSS prefixes
Common namespace ConfigProvider and local prefixCls; the state of the component is preserved when the name is changed.
<script lang="ts">
import {
Checkbox,
ConfigProvider,
Modal,
ModalHolder,
createModal,
Input,
Button
} from '@woodger/antd';
let custom = $state(true);
let local = $state(true);
const prefix = $derived(custom ? 'suite' : 'ant');
const localPrefix = $derived(local ? 'project-modal' : '');
let open = $state(false);
let draft = $state(("Window draft"));
const modal = createModal();
</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 Modal suite")}</Checkbox>
<Checkbox bind:checked={local}>{("Modal local prefix")}</Checkbox>
</div>
<ConfigProvider prefixCls={prefix} theme={{ cssVar: { prefix: 'modal-theme' } }}>
<div class="prefix-stage">
<Button onclick={() => open = true}>{("Open Modal with prefix")}</Button>
<Modal prefixCls={localPrefix} bind:open title={("Modal with prefix")}>
<Input bind:value={draft} aria-label={("Draft Modal with prefix")} />
</Modal>
<Button onclick={() => modal.confirm(({
prefixCls: localPrefix,
title: "Acknowledgment with prefix",
content: "The context method saves the common namespace Button."
}))}>{("\n Open confirmation with prefix\n ")}</Button>
<ModalHolder {modal} />
</div>
</ConfigProvider>
<output
aria-label={("Modal CSS prefix")}
>{("General: ")}{prefix}{("; local: ")}{(localPrefix
|| ("from the provider"))}</output>
<p>
{("ModalConfirmConfig.prefixCls modifies a separate context confirmation; a missing or empty string uses the holder provider prefix. The open dialog and draft are not recreated; namespace Button is independent.")}
</p>
</div>
API
The examples cover declarative Modal and confirmations opened with createModal.
| Theme | Example or limitation |
|---|---|
| Basic | Open, confirm and return focus. |
| Asynchronously close | The application controls confirmLoading/open, error and retry. |
| Customized Footer | footer Snippet or null. |
| mask | Controls the backdrop, its blur and whether clicking it closes the panel. |
| Loading | loading shows the body Skeleton and hides the footer, preserving the title and closing controls. |
| Customized Footer render function | Arrange the standard OK and Cancel buttons in a custom order. |
| Use hooks to get context | Svelte analogue: createModal and one ModalHolder under the desired ConfigProvider. React Modal.useModal is not exported. |
| Internationalization | ConfigProvider.locale, okText and cancelText. |
| Manual to update destroy | update and destroy belong to the returned handle. |
| To customize the position of modal | Choose the alignment with centered. |
| Customize footer buttons props | Props for the standard OK button. |
| Custom modal content render | One wrapper for the editor and the preview. |
| To customize the width of modal | A pixel width, CSS length or widths for different screen sizes. |
| Static Method | Modal.confirm opens a standalone dialog. |
| Static confirmation | After confirmation, update replaces the question with a success message. |
| destroy confirmation modal dialog | Modal.destroyAll closes both the static warning and the context dialog. |
| Custom semantic dom styling | Style the title color and body padding independently. |
Modal
| Property | Description | Type | Default |
|---|---|---|---|
panelRef | Use bind:panelRef to access the native dialog while the panel is mounted. | HTMLDialogElement | undefined | — |
closeIcon | The close icon. With closable omitted, null hides the close button. | ModalContent | — |
focusable | Traps focus and optionally restores it to the trigger after closing. | ModalFocusableConfig | — |
height | Height in pixels or a CSS length. | number | string | — |
centered | Centers the dialog. Set to false to align it near the top. | boolean | ConfigProvider.modal |
scrollLock | Locks page scrolling while the dialog is open. | boolean | true |
forceRender | Mounts the content in advance. false defers mounting until the first open. | boolean | — |
destroyOnHidden | Unmounts the content after closing unless forceRender is enabled. | boolean | false |
transitionName | CSS transition name for the dialog. An empty string disables its animation. | string | — |
maskTransitionName | CSS transition name for the backdrop. | string | — |
mousePosition | Page coordinates used as the dialog animation origin. | { x: number, y: number } | null | — |
okType | Appearance of the OK button. | ModalOkType | primary |
okButtonProps | Props for the standard OK button. | ModalButtonProps | — |
cancelButtonProps | Props for the standard Cancel button. | ModalButtonProps | — |
zIndex | Sets the panel layer used by nested popups. | number | — |
afterOpenChange | Reports opening or closing when the transition completes. | (open: boolean) => void | — |
prefixCls | Full CSS prefix of the component and its parts. A non-empty local prop takes precedence; empty string and undefined inherit ConfigProvider. The namespace of the topic is set separately. | string | ConfigProvider.prefixCls + "-modal" |
open | Supports bind:open. | boolean | false |
title | Scalar or Snippet. Empty/null/boolean title removes header; 0 remains visible. | ModalContent | — |
children | Content survives closing but is removed during loading and recreated afterward. | Snippet | — |
aria-label | Explicit accessible name instead of generated association with title. | string | — |
aria-labelledby | id of available header; takes precedence over aria-label and generated title id. | string | — |
footer | Receives the default footer and individual OkBtn and CancelBtn snippets. | ModalFooter | null | Cancel / OK |
width | A pixel width, CSS length or widths for different screen sizes. | ModalWidth | 520 |
closable | Standard cross. | ModalClosable | true |
keyboard | Cancel by Escape. | boolean | true |
mask | Closing by background regardless of keyboard and closable. The click should start and end outside the content. | ModalMask | { closable: true } |
loading | Skeleton instead of the body and a hidden footer. Does not block cancellation by itself; applies to declarative Modal. | boolean | false |
confirmLoading | Waiting for OK button; blocks standard cancel and cross. | boolean | false |
okText | Label of the confirmation button. | ModalContent | locale.okText |
cancelText | Cancel button label. | ModalContent | locale.cancelText |
onOk | When a callback is passed, the application itself changes open. | () => void | close |
onCancel | Notification after request for cancellation and change open. | () => void | — |
afterClose | After actually closing the native dialog. | () => void | — |
getContainer | Container, getter, selector or false. | GetContainer | body / ConfigProvider |
class | Root dialog class; The example CSS can clarify the position. | string | — |
Modal / ModalConfirmConfig
| Property | Description | Type | Default |
|---|---|---|---|
classNames | Classes for individual parts. Accepts an object or a function of the current props. | ModalSemantic | — |
styles | CSS declaration strings for individual parts. Local styles follow shared styles. | ModalSemantic | — |
style | Inline CSS for the inner panel. | string | — |
rootStyle | Inline CSS for the native dialog, applied before styles.root and styles.wrapper. | string | — |
rootClassName | Class on the native dialog. | string | — |
wrapClassName | Wrapper class on the same dialog element. | string | — |
wrapProps | Native dialog attributes and event handlers. | ModalWrapProps | — |
maskProps | Attributes and event handlers for the backdrop element. | ModalPartProps | — |
bodyProps | Attributes and event handlers for the body container. | ModalPartProps | — |
modalRender | Receives the built-in panel so you can wrap or replace it. | Snippet<[content: Snippet]> | — |
Context methods
| Property | Description | Type | Default |
|---|---|---|---|
info | Information window; only OK by default. | (config) => ModalConfirmHandle | — |
success | Success message. | (config) => ModalConfirmHandle | — |
error | Error message. | (config) => ModalConfirmHandle | — |
warning | Warning. | (config) => ModalConfirmHandle | — |
confirm | Confirmation with OK/Cancel. Await handle returns boolean. | (config) => ModalConfirmHandle | — |
ModalConfirmConfig
| Property | Description | Type | Default |
|---|---|---|---|
direction | Text and button direction for this confirmation. | ltr | rtl | ConfigProvider |
type | The method determines the initial dialog type. Call update to change it. | ModalConfirmType | — |
panelRef | Receives the dialog element on mount and undefined when the reference is released. | (node: HTMLDialogElement | undefined) => void | — |
closeIcon | The close icon. With closable omitted, null hides the close button. | ModalContent | — |
focusable | Also selects OK or Cancel as the initial focus target. | ModalConfirmFocusableConfig | — |
prefixCls | Full prefix of one confirmation. Empty string/undefined use the modal prefix of the holder provider; Button namespace is independent. | string | ConfigProvider.prefixCls + "-modal" |
title | Optional header scalar/Snippet. | ModalContent | — |
content | Scalar/Snippet confirmation body. | ModalContent | — |
icon | Your own icon; null/false hide it. | Snippet | null | false | By window type |
width | Confirmation width in pixels or CSS units. | number | string | 416 |
okCancel | Show cancel button. | boolean | true to confirm |
okText | Label OK, including Snippet. | ModalContent | From locale |
cancelText | Cancellation label, including Snippet. | ModalContent | From locale |
closable | Closing cross. | ModalClosable | false |
keyboard | Cancel by Escape. | boolean | true |
mask | Background cancellation is disabled by default. | ModalMask | { closable: false } |
getContainer | Container native dialog. | GetContainer | From context |
class | Class dialog. | string | — |
footer | Receives the default footer and individual OkBtn and CancelBtn snippets. | ModalFooter | null | Controller actions |
onOk | Without argument closes automatically; the close argument gives manual control. Promise includes loading. | (close) => unknown | Close |
onCancel | Cancel button supports Promise; Escape/close/mask closes immediately. | (close) => unknown | Close |
afterClose | After actual closing; deleting holder does not call callback. | () => void | — |
ModalStaticConfig
| Property | Description | Type | Default |
|---|---|---|---|
open | Use update to hide and reopen the dialog. | boolean | true |
ModalStaticHandle
| Property | Description | Type | Default |
|---|---|---|---|
update | An object patches individual fields. A function returns the entire next configuration. | (config | updater) => void | — |
destroy | Closes the dialog and releases its root. | () => void | — |
Static Modal methods take a ModalStaticConfig and return a ModalStaticHandle.
With declarative Modal, the application manages open and handles the outcome of onOk.
ModalConfirmHandle
Await handle returns true after confirmation, false after canceling, destroy or deleting the holder. update accepts patch or the function previous → patch. destroy closes without onCancel. One instance of createModal is connected to one ModalHolder; create it in the scope of the component.
Semantic DOM
Use these names in classNames and styles.
| Element | Purpose |
|---|---|
root | Native dialog element. |
wrapper | Wrapper on the same dialog element. |
mask | Backdrop behind the dialog. |
container | Inner panel with the heading, content and actions. |
close | Close button with localized name. |
header | Header of a declarative dialog. |
title | Title of a declarative dialog. |
body | Dialog content or the visible text of a context confirmation. |
footer | Action area. |
Registration tokens
theme.components.Modal configures the background, header and padding. The first six tokens correspond to the main ant.design table; The following lists the settings of the installed package. The theme, including the wireframe, is updated without losing the draft or modality. confirm tokens apply to contextual confirmations.
| Token | Purpose |
|---|---|
contentBg | Content background. |
headerBg | Header background. |
footerBg | footer background. |
titleColor | Title color. |
titleFontSize | Header size. |
titleLineHeight | Header line spacing. |
contentPadding | Container padding. |
headerPadding | Header indents. |
headerBorderBottom | Header border. |
headerMarginBottom | Indentation after the header. |
bodyPadding | Body indents. |
footerPadding | footer indents. |
footerBorderTop | footer border. |
footerBorderRadius | footer radius. |
footerMarginTop | Indentation before footer. |
confirmBodyPadding | Indentation of the body of the contextual confirmation. |
confirmIconMarginInlineEnd | Confirmation icon indentation. |
confirmBtnsMarginTop | Indentation of confirmation actions. |
| Token | Meaning |
|---|---|
colorBgMask | rgba(0,0,0,0.45) |
colorText | rgba(0,0,0,0.88) |
colorTextHeading | rgba(0,0,0,0.88) |
colorIcon | rgba(0,0,0,0.45) |
colorIconHover | rgba(0,0,0,0.88) |
borderRadiusLG | 8 |
padding | 16 |
FAQ
Will the returned Promise close the window?
For a declarative Modal, the owner controls open and confirmLoading. For createModal, the returned Promise enables loading and closes the window upon success; rejection leaves it open.
Are fields saved after closing?
By default they are preserved. To start with a fresh form each time, enable destroyOnHidden and keep the values inside the form.
How can I wait for the user’s decision?
With Modal.confirm(), handle the choice in onOk and onCancel. To read the result with await, use createModal() with ModalHolder or use App.useApp().modal.
How to show loading or your footer?
Set loading on a declarative Modal to load its body. It shows a Skeleton and hides the footer until loading finishes. footer accepts a snippet or null. confirmLoading handles pending confirmation and does not replace the body.
Do Modal tokens work?
Yes, the areas background, header and padding are applied via theme.components.Modal. Nested controls have their own tokens.
How can I style individual parts of the dialog?
Pass classes in classNames and CSS declaration strings in styles for the parts you want to customize. Both accept an object or a function ({ props }) => …. The names root and wrapper refer to the same native dialog. Pass native attributes through wrapProps, maskProps and bodyProps. If they specify class or style, that value replaces the corresponding styling for that part.