Liking cljdoc? Tell your friends :D

x-modal

Centered overlay dialog with backdrop. Traps focus, dismisses on Escape or backdrop click, and animates with opacity + scale.

Tag name

<x-modal>…</x-modal>

Observed Attributes

AttributeTypeDefaultDescription
openbooleanabsentPresence controls visibility. Set to open, remove to close.
sizestring"md"Width variant: sm \| md \| lg \| xl \| full
labelstring"Modal"Accessible label applied as aria-label on the dialog element.

Properties

PropertyTypeDefaultDescription
openbooleanfalseReflects the open attribute. Setting true calls show(), false calls hide().
sizestring"md"Reflects the size attribute.
labelstring"Modal"Reflects the label attribute.

Methods

MethodDescription
show()Opens the modal (sets open attribute). No-op if already open.
hide()Closes the modal (removes open attribute).
toggle()Opens if closed, closes if open.

Events

EventBubblesDetailDescription
x-modal-toggleyes{ open: boolean }Fires once on any open/close transition.
x-modal-dismissyes{ reason: "escape"\|"backdrop" }Fires on user-initiated close before the modal closes.

Slots

SlotDescription
headerHeader content. Rendered in [part=header] with bottom border.
(default)Body content. Rendered in [part=body], scrollable.
footerFooter content. Rendered in [part=footer] with top border.

CSS Parts

PartDescription
backdropFixed overlay behind the dialog.
dialogThe dialog container. Centered with translate(-50%,-50%).
headerHeader wrapper div.
bodyBody wrapper div (scrollable).
footerFooter wrapper div.

CSS Custom Properties

PropertyDefaultDescription
--x-modal-bgCanvasDialog background color.
--x-modal-fgCanvasTextDialog foreground color.
--x-modal-backdroprgb(0 0 0 / 0.45)Backdrop background.
--x-modal-shadow0 20px 60px rgb(0 0 0 / 0.25)Dialog box shadow.
--x-modal-radius0.75remDialog border radius.
--x-modal-width-sm22remWidth for size="sm".
--x-modal-width-md32remWidth for size="md".
--x-modal-width-lg44remWidth for size="lg".
--x-modal-width-xl60remWidth for size="xl".
--x-modal-max-height90vhMaximum height for sm/md/lg/xl variants.
--x-modal-header-padding1rem 1.25remHeader padding.
--x-modal-body-padding1rem 1.25remBody padding.
--x-modal-footer-padding0.75rem 1.25remFooter padding.
--x-modal-bordercolor-mix(in srgb, currentColor 12%, transparent)Header/footer divider color.
--x-modal-duration180msTransition duration.
--x-modal-easingeaseTransition easing.
--x-modal-z1000Backdrop z-index (dialog is z+1).

Accessibility

  • [part=dialog] has role="dialog" and aria-modal="true".
  • aria-label is set from the label attribute (default: "Modal").
  • Focus is trapped inside the open dialog. Tab and Shift+Tab cycle through tabbable elements.
  • Focus is restored to the previously focused element on close.
  • Escape key closes the modal and fires x-modal-dismiss with reason: "escape".
  • Respects prefers-reduced-motion: reduce — disables all transitions.

Size Variants

SizeWidthNotes
sm22rem
md32remDefault
lg44rem
xl60rem
full100vw × 100dvhFills the viewport, border-radius removed.

Usage

<!-- Import -->
<script>
  import { init } from '@vanelsas/baredom/x-modal';
  init();
</script>

<!-- Basic usage -->
<button onclick="document.getElementById('my-modal').show()">Open Modal</button>

<x-modal id="my-modal" label="Confirm Action">
  <div slot="header">Confirm</div>
  <p>Are you sure you want to proceed?</p>
  <div slot="footer">
    <button onclick="document.getElementById('my-modal').hide()">Cancel</button>
    <button onclick="handleConfirm()">Confirm</button>
  </div>
</x-modal>

<!-- Large variant -->
<x-modal id="settings-modal" size="lg" label="Settings">
  <div slot="header">Settings</div>
  <p>Settings content here…</p>
  <div slot="footer">
    <button onclick="document.getElementById('settings-modal').hide()">Close</button>
  </div>
</x-modal>

<!-- Full-screen -->
<x-modal id="fullscreen-modal" size="full" label="Full Screen View">
  <div slot="header">Full Screen</div>
  <p>Content fills the entire viewport.</p>
</x-modal>

<!-- Listen to events -->
<script>
  const modal = document.getElementById('my-modal');
  modal.addEventListener('x-modal-toggle', (e) => {
    console.log('open:', e.detail.open);
  });
  modal.addEventListener('x-modal-dismiss', (e) => {
    console.log('dismissed via:', e.detail.reason);
  });
</script>

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close