Skip to content

Commit 7a203e4

Browse files
committed
Fix web components as openers/closers not working properly
1 parent 34f762b commit 7a203e4

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/a11y-dialog.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -192,20 +192,19 @@ export default class A11yDialog {
192192
// target
193193
// See: https://github.com/KittyGiraudel/a11y-dialog/issues/582
194194
const target = event.composedPath()[0] as HTMLElement
195-
196-
// We use `.closest(..)` and not `.matches(..)` here so that clicking
197-
// an element nested within a dialog opener does cause the dialog to open
198-
if (target.closest(`[${SCOPE}-show="${this.id}"]`)) {
199-
this.show(event)
200-
}
201-
202-
if (
203-
target.closest(`[${SCOPE}-hide="${this.id}"]`) ||
204-
(target.closest(`[${SCOPE}-hide]`) &&
205-
target.closest('[aria-modal="true"]') === this.$el)
206-
) {
207-
this.hide(event)
208-
}
195+
const opener = closest(`[${SCOPE}-show="${this.id}"]`, target)
196+
const explicitCloser = closest(`[${SCOPE}-hide="${this.id}"]`, target)
197+
const implicitCloser =
198+
closest(`[${SCOPE}-hide]`, target) &&
199+
closest('[aria-modal="true"]', target) === this.$el
200+
201+
// We use `closest(..)` (instead of `matches(..)`) so that clicking an
202+
// element nested within a dialog opener does cause the dialog to open, and
203+
// we use our custom `closest(..)` function so that it can cross shadow
204+
// boundaries
205+
// See: https://github.com/KittyGiraudel/a11y-dialog/issues/712
206+
if (opener) this.show(event)
207+
if (explicitCloser || implicitCloser) this.hide(event)
209208
}
210209

211210
/**

0 commit comments

Comments
 (0)