rebase: port hyperhive#2874's composedPath() click-retarget fix into hive-dialog.js

#2875 (merged) fixed this on main's flat modal.js before #2793's
component-dir split landed. Porting the same one-line fix here now
instead of leaving it as a rebase landmine for whichever PR merges
second.
This commit is contained in:
iris 2026-07-31 21:37:39 +02:00
commit 94390da54c

View file

@ -80,7 +80,19 @@ class HiveDialog extends HTMLElement {
root.append(box);
this.addEventListener('click', (e) => {
if (dismissable && e.target === this) done(null);
// `e.target` is retargeted to `this` (the host) for ANY click that
// originated inside the shadow tree, once it bubbles out to a
// listener attached on the host itself — per spec, retargeting
// applies to every ancestor outside the shadow tree, and the host
// element's own light-DOM-side listeners count as outside. So
// `e.target === this` was true for every click inside `.box` too
// (title, message, a bare checkbox row with no button to consume
// it first), not just genuine backdrop clicks — dismissing the
// whole dialog on, say, a checkbox click.
// `composedPath()[0]` is the true original target, unaffected by
// retargeting: it's `this` only when nothing inside the shadow
// tree was actually under the cursor, i.e. a real backdrop click.
if (dismissable && e.composedPath()[0] === this) done(null);
});
document.addEventListener('keydown', onKey, true);