drab 7.0.0 → 7.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dialog/index.js +6 -3
- package/package.json +1 -1
package/dist/dialog/index.js
CHANGED
@@ -32,6 +32,9 @@ export class Dialog extends Lifecycle(Trigger(Content())) {
|
|
32
32
|
get #clickOutsideClose() {
|
33
33
|
return this.hasAttribute("click-outside-close");
|
34
34
|
}
|
35
|
+
get #scrollbarWidth() {
|
36
|
+
return window.innerWidth - document.documentElement.clientWidth;
|
37
|
+
}
|
35
38
|
/** Remove scroll from the body when open with the `remove-body-scroll` attribute. */
|
36
39
|
#toggleBodyScroll(show) {
|
37
40
|
if (this.#removeBodyScroll) {
|
@@ -68,10 +71,10 @@ export class Dialog extends Lifecycle(Trigger(Content())) {
|
|
68
71
|
// https://blog.webdevsimplified.com/2023-04/html-dialog/#close-on-outside-click
|
69
72
|
this.#dialog.addEventListener("click", (e) => {
|
70
73
|
let rect = this.#dialog.getBoundingClientRect();
|
71
|
-
// If dialog covers full viewport
|
74
|
+
// If dialog covers full viewport, use first child element for hit testing
|
72
75
|
// Example: https://picocss.com/docs/modal
|
73
|
-
if (rect.width - window.innerWidth <=
|
74
|
-
rect.height - window.innerHeight <=
|
76
|
+
if (Math.abs(rect.width - window.innerWidth) <= this.#scrollbarWidth && // 5px tolerance for rounding issues
|
77
|
+
Math.abs(rect.height - window.innerHeight) <= 0 &&
|
75
78
|
this.#dialog.firstElementChild) {
|
76
79
|
rect = this.#dialog.firstElementChild.getBoundingClientRect();
|
77
80
|
}
|