dialog-anchor
Open and close a native <dialog> — no JavaScript required.
Features
- Click to toggle Opens / closes a
<dialog>on click - Target or fallback Point at any
<dialog>viatarget-ref, or let it find the nearest ancestor automatically (great for close buttons) - Modal or non-modal
is-modalblocks the rest of the page; omit it for a lightweight, dismissible popover - Any trigger event Inherits
listen-forto open/close on custom events instead ofclick
Installation
This package is available in the
<script src="https://unpkg.com/@excom/kit-utils@0.3.0/dist/index.umd.min.js"></script>
<script src="https://unpkg.com/@excom/neutron@0.2.0/dist/index.umd.min.js"></script>
<script src="https://unpkg.com/@excom/dialog-anchor@0.1.4/dist/index.umd.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/@excom/dialog-anchor@0.1.4/dist/index.css">npm install @excom/dialog-anchor<!-- import path to `node_modules` will depend on your build setup -->
<script type="module" src="/node_modules/@excom/dialog-anchor"></script>
<link rel="stylesheet" href="/node_modules/@excom/dialog-anchor">import "@excom/dialog-anchor";@import "@excom/dialog-anchor/index.css";Peer dependencies (0)
Packages a consumer must install alongside this one. Workspace deps are bundled.
| Package | Version |
|---|---|
|
Usage
Wrap a trigger in <dialog-anchor> and point it at a <dialog>. A
<dialog-anchor> with no target-ref, placed inside the <dialog> it
should close, needs no configuration at all.
<dialog-anchor target-ref="#confirm" role="button">Delete</dialog-anchor>
<dialog id="confirm">
<p>Are you sure?</p>
<dialog-anchor role="button">Cancel</dialog-anchor>
</dialog><dialog-anchor target-ref="#confirm" role="button">Delete</dialog-anchor>
<dialog id="confirm">
<p>Are you sure?</p>
<dialog-anchor role="button">Cancel</dialog-anchor>
</dialog>API Reference
Attributes
Role —option is configurable, state
is managed by the element (read-only), or hybrid which is both.
Provision
Thisprovision property lives on the DOM node.
Read / watch it with Quark’s prop("provision"), or listen
for the neutron-provision event from app JS.
Events
Type
command event (HTML Command API): from a
<button command commandfor>, an <event-handler
command-name>, or a CommandEvent.
Recognized Elements
Child or descendant elements are recognized by and relevant to its functionality.Styles
@custom-selector synonyms so custom elements can share
semantic styles. Element aliases match the host tag / .tag-* class; state
aliases match attributes (nested under the element alias).
dialog-anchor
Attributes (15)
Role —option is configurable, state
is managed by the element (read-only), or hybrid which is both.
delay-ms
delayMs
number
nullhost-ref
window / document — e.g. Escape to dismiss a dialog from a global keydown. Defaults to :scope. Used with listen-for. Not compatible with listen-for-lifecycle. The selector MUST resolve when host-ref is set — it will not wait for a match to appear.
hostRef
string
<CSS Selector> | "window" | "document" | "html" | "body" | "head"nullis-debounced
delay-ms, coalesce bursts into one trailing call (debounce).
isDebounced
boolean
falseis-modal
isModal
boolean
falsekeycode-filter
+ (AND, any order): shift+k tab → Shift+K or Tab. Modifiers: shift, alt, ctrl/control, meta/cmd. Name the space bar space / spacebar and the plus key plus (shift+space). Case-insensitive.
keycodeFilter
tokenlist
<key | mod+key>…nulllisten-for
click when unset (and no lifecycle list is set).
listenFor
tokenlist
<EventName>…nulllisten-for-lifecycle
listenForLifecycle
tokenlist
"connected" | "disconnected" | "adopted"nulllisten-once
listenOnce
boolean
falsepathname-filter
location.pathname is one of these values — route-aware behaviors without a separate router element.
pathnameFilter
tokenlist
<pathname>…nullprevent-default
preventDefault() on matched events (ignored for lifecycles).
preventDefault
boolean
falseselector-filter
event.target matches this CSS selector. Does not support :scope in the selector.
selectorFilter
string
<CSS Selector>nullstop-immediate-propagation
stopImmediatePropagation() on matched events (ignored for lifecycles).
stopImmediatePropagation
boolean
falsestop-propagation
stopPropagation() on matched events (ignored for lifecycles).
stopPropagation
boolean
falsetarget-ref
<dialog> to toggle. If omitted, the element toggles the nearest ancestor <dialog>.
targetRef
string
<CSS Selector>nullvibrate-ms
navigator.vibrate). Empty / 0 uses a 20ms pulse.
vibrateMs
number
"20 (when attribute is present with no value)"Provision (0)
Thisprovision property lives on the DOM node.
Read / watch it with Quark’s prop("provision"), or listen
for the neutron-provision event from app JS.
Events (0)
e.preventDefault() is not
synchronously called on the event.
Type
command event (HTML Command API): from a
<button command commandfor>, an <event-handler
command-name>, or a CommandEvent.
Recognized Elements (0)
Child or descendant elements are recognized by dialog-anchor and relevant to its functionality.Styles (2)
.unstyledall: revert-layer.
Valence.css ships this as .unstyled and .unstyled-all for the entire tree.
@custom-selector synonyms so custom elements can share
semantic styles. Element aliases match the host tag / .tag-* class; state
aliases match attributes (nested under the element alias).
:--dialog-anchordialog-anchor, .tag-dialog-anchorRelease notes (1)
0.1.1
- Ship only dist (and declared extras) in the npm tarball; drop build logs, tests and sources
Release notes
e.preventDefault() is not
synchronously called on the event.
all: revert-layer.
Valence.css ships this as .unstyled and .unstyled-all for the entire tree.
Examples
Modal dialog
is-modal opens the dialog as a modal, blocking interaction with the rest
of the page until it's closed (using native ::backdrop). Without that attribute,
the dialog is opened without a backdrop.
If using Valence.css, setting .absolute on the dialog element will display it absolute
in the surrounding content (as opposed to fixed).
Close on a custom event
listen-for swaps the default click for any event. Pair it with a real
<super-form>'s super-form-success event to auto-close a dialog
once a form inside it succeeds — simulated here with <event-handler>.