Skip to main content

rc-dialog

Draggable, resizable wrapper for a native <dialog>, following the WAI-ARIA Dialog Modal pattern.

Package
@rcarls/rc-dialog
Element
<rc-dialog>
Native dependency
Requires a direct child native dialog
State model
Open state follows the native dialog
Main events
rc-dialog-openrc-dialog-togglerc-dialog-request-closerc-dialog-cancelrc-dialog-close

Installation

npm install @rcarls/rc-dialog
import '@rcarls/rc-dialog/define';

Live demo

Theming

The default demo mode shows the component without a package theme. Use the shared preview controls on this page to compare inherited, light, and dark color schemes or to apply the optional Material theme only inside the demo frames.

API

Properties

PropertyMarkupTypeDefaultDescription
movablemovablebooleanfalseAllow the dialog to be moved by dragging. Use `move-handle` to restrict dragging to a specific child element (e.g. a titlebar).
moveHandlemove-handlestring''CSS selector (within the inner `<dialog>`) for the drag handle element.
moveBoundsmove-bounds'viewport' | 'parent''viewport'Bounds constraint for movement.
moveStepmove-stepnumber4Keyboard arrow-key step in px for moving.
resizeresize'none' | 'both' | 'horizontal' | 'vertical''none'Enable resizing, mirroring the CSS `resize` property values.
resizeThresholdresize-thresholdnumber8Edge hit-test thickness in px for resize detection.
resizeStepresize-stepnumber4Keyboard arrow-key step in px for resizing.
closedByclosed-by'any' | 'closerequest' | 'none' | ''''Proxied to the inner `<dialog closedby="...">` attribute. Progressive enhancement, no-op in older browsers. - `'any'` — Escape OR backdrop click closes the dialog. - `'closerequest'` — Escape only (browser default for modal dialogs). - `'none'` — Only programmatic `close()` / `requestClose()`. - `''` — Attribute absent; use `light-dismiss` for JS fallback.
lightDismisslight-dismissbooleanfalseWhen true and the dialog is modal, a click on the backdrop area calls `requestClose()`.
modalJS property onlybooleantrueWhether to open as modal with controlled open. Default: `true`.
openopenbooleanNot specifiedWhether the inner `<dialog>` is currently open. Host writes update silently.
defaultOpendefault-openbooleanNot specifiedInitial uncontrolled open state.
returnValueJS property onlystringNot specifiedThe return value set when the dialog was closed.

Methods

MethodDescription
showModal()Opens the inner `<dialog>` as a modal and fires `rc-dialog-open`.
show()Opens the inner `<dialog>` (non-modal) and fires `rc-dialog-open`.
close(returnValue?: string)Closes the inner `<dialog>`, optionally setting a return value.
requestClose(returnValue?: string)Requests the inner `<dialog>` to close, firing a cancelable `cancel` event first.

Events

EventDetail typeDescription
rc-dialog-openCustomEventFired when the dialog opens via `showModal()` or `show()`.
rc-dialog-toggleCustomEventFired when user/native interaction changes open state.
rc-dialog-request-closeNo detail type documentedFired before the dialog closes (cancellable).
rc-dialog-cancelNo detail type documentedMirrors the inner `<dialog>` cancel event when the close was not prevented. Backward-compatible alias for `rc-dialog-request-close`.
rc-dialog-closeNo detail type documentedMirrors the inner `<dialog>` close event. `detail: { returnValue: string }`

Slots

NameDescription
(default)Place a `<dialog>` element with your content here.

CSS Custom Properties

No CSS custom properties are documented in the custom elements manifest.

CSS Parts

No CSS parts are documented in the custom elements manifest.