Skip to content

Dialog API ​

Methods ​

MethodSignatureDescription
openModal(options: SoDialogModalOptions)Open a modal dialog.
openOffcanvas(options: Omit<SoDialogOffcanvasOptions, 'kind'>)Open an offcanvas panel dialog.
confirmModal(options?: SoDialogConfirmOptions)Open a confirm dialog and return Promise<boolean>.
promptModal(options?: SoDialogPromptOptions)Open a prompt dialog and return `Promise<string
formModal(options: SoDialogFormOptions)Open a dynamic form dialog and return submitted values.
openImagePreview(source, options?)Open a centered, configurable image preview.
bindImagePreview(options?)Delegate image clicks from a document or element.
SoDialog.open(options: SoDialogOptions)Open modal or offcanvas by kind.

bindImagePreview({ root }) enhances dynamic content such as help documents and returns a handle with destroy() for listener cleanup. See the Image Preview API for the complete contract.

Core Options (SoDialogBaseOptions) ​

NameTypeRequiredDefaultDescription
titlestring | HTMLElementYes-Dialog title text, or an HTMLElement rendered inside the title region.
contentstring | NodeYes-Dialog content.
confirmTextstringNo确认Confirm button text.
cancelTextstringNo取消Cancel button text.
confirmAction'hide' | 'destroy'NohideConfirm click close strategy.
closeOnEscbooleanNotrueAllow Esc to close the dialog.
closeOnBackdropbooleanNotrueAllow backdrop click close.
hideHeaderbooleanNofalseHide the built-in header while preserving an accessible dialog name.
hideCloseButtonbooleanNofalseHide the built-in close button.
closeButtonLabelstringNoCloseAccessible label for the close button.
closeButtonTextstringNo×Visible close button text or symbol.
hideFooterbooleanNofalseHide default footer buttons.
footerAlign'start' | 'center' | 'end' | 'between'NoendFooter layout alignment.
footerButtonsSoDialogFooterButton[]Nobuilt-in confirm/cancelCustom footer buttons.
traceIdstringNo-Diagnostic trace identifier.
onLayoutStable(ctx) => voidNo-Triggered when layout is stable.
onAction(ctx) => voidNo-Triggered on footer actions.
onLifecycle/onBeforeOpen/...SoLifecycleHookNo-Dialog lifecycle hooks.
NameTypeDefaultDescription
idstringauto idReuse an existing modal instance by id.
position'center' | 'top' | 'bottom'centerModal position.
animation'slide' | 'fade' | 'zoom'fadeModal animation.
widthnumber | stringautoPanel width. Numbers are interpreted as pixels; strings accept CSS sizes.
heightnumber | stringautoPanel height. Numbers are interpreted as pixels; strings accept CSS sizes.
useModalbooleantrueUse native showModal() behavior.
draggablebooleantrueEnable drag interactions. Set false to disable dragging.
dragHandleSoModalDragHandle | falseheaderDrag handle selector target(s). Supports header, title, body, footer, panel, CSS selectors, arrays, or false.
preset'deploy'-Apply an optional preset style from the standard stylesheet.
autoFitSizebooleantrueAuto fit panel to content changes.
scrollMode'body' | 'viewport' | 'none' | 'hybrid'autoAuto-fit scroll strategy.

Providing width or height disables automatic modal sizing so the explicit dimensions take precedence.

Offcanvas-only Options (SoDialogOffcanvasOptions) ​

NameTypeDefaultDescription
placement'start' | 'end' | 'top' | 'bottom'endPanel placement.
animation'slide' | 'fade' | 'zoom'slideOffcanvas animation.
widthnumber | stringplacement defaultPanel width. Numbers are interpreted as pixels; strings accept CSS sizes.
heightnumber | stringplacement defaultPanel height. Numbers are interpreted as pixels; strings accept CSS sizes.
resizableboolean | SoOffcanvasResizeOptionsfalseEnable pointer and keyboard width resizing for start/end panels.

SoOffcanvasResizeOptions: minWidth defaults to 320 px (minimum accepted value 160); maxWidth defaults to no configured limit and is restricted by the viewport; step defaults to 10 px; largeStep defaults to 50 px with Shift; handleLabel defaults to Resize panel; storageKey is unset by default. Arrow keys, Home, and End adjust width. Pointer and keyboard changes persist when a storage key is set. The handle is hidden on narrow screens. Offcanvas locks page scrolling while its body remains scrollable.

Return Handle (SoDialogHandle) ​

openModal and openOffcanvas return a SoDialogHandle which can be used to close, update, or inspect state.

FieldTypeDescription
dialogHTMLDialogElementNative dialog element.
close() => voidClose dialog.
refit() => voidTrigger layout refit manually.
setWidth(width: number | string) => voidSet panel width; numeric widths on resizable panels use configured limits.
getWidth() => numberRead the current rendered width in pixels.
setFooterButtons(buttons) => voidReplace footer button set.
updateFooterButton(id, updates) => booleanPatch one button by id.
onAction(listener) => () => voidSubscribe footer actions and return unsubscribe.

Usage Example ​

ts
import { openModal } from 'sodialog'

const handle = openModal({
  title: 'Delete item',
  content: '<p>Do you want to continue?</p>',
  confirmText: 'Delete',
  cancelText: 'Cancel',
})

handle.close()

Released under the MIT License.