@nectary/components 5.45.2 → 5.45.3
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/bundle.js +106 -17
- package/package.json +1 -1
- package/pop/index.js +106 -15
- package/utils/dom.js +1 -3
package/bundle.js
CHANGED
|
@@ -211,9 +211,7 @@ const isTransformedElement = (element) => {
|
|
|
211
211
|
}
|
|
212
212
|
const style = getComputedStyle(element);
|
|
213
213
|
const backdropFilter = style.getPropertyValue("backdrop-filter");
|
|
214
|
-
|
|
215
|
-
const hasWillChange = style.willChange.split(",").map((value) => value.trim().toLowerCase()).some((value) => value === "transform" || value === "perspective" || value === "filter" || value === "backdrop-filter");
|
|
216
|
-
return hasTransform || hasWillChange;
|
|
214
|
+
return style.transform !== "none" || style.perspective !== "none" || style.filter !== "none" || backdropFilter !== "" && backdropFilter !== "none";
|
|
217
215
|
};
|
|
218
216
|
const getTransformedAncestor = (node) => {
|
|
219
217
|
let current = node;
|
|
@@ -3582,13 +3580,14 @@ const enableOverscroll = () => {
|
|
|
3582
3580
|
document.documentElement.style.removeProperty("overscroll-behavior");
|
|
3583
3581
|
}
|
|
3584
3582
|
};
|
|
3585
|
-
const templateHTML$Z = '<style>:host{display:contents;position:relative}dialog{position:fixed;left:0;top:0;transform:translate(var(--sinch-pop-offset-x),var(--sinch-pop-offset-y));margin:0;outline:0;padding:0;border:none;box-sizing:border-box;max-width:unset;max-height:unset;z-index:var(--sinch-comp-pop-z-index,1);background:0 0;overflow:visible}dialog:not([open]){display:none}dialog::backdrop{background-color:transparent}#content{position:relative;z-index:var(--sinch-comp-pop-z-index,1)}#target-open{display:flex;flex-direction:column;position:absolute;left:0;top:0}#focus{display:none;position:absolute;width:0;height:0}</style><slot id="target" name="target" aria-haspopup="dialog" aria-expanded="false"></slot><div id="focus"></div><dialog id="dialog"><div id="target-open"><slot name="target-open"></slot></div><div id="content"><slot name="content"></slot></div></dialog>';
|
|
3583
|
+
const templateHTML$Z = '<style>:host{display:contents;position:relative}dialog{position:fixed;left:0;top:0;transform:translate(var(--sinch-pop-offset-x),var(--sinch-pop-offset-y));margin:0;outline:0;padding:0;border:none;box-sizing:border-box;max-width:unset;max-height:unset;z-index:var(--sinch-comp-pop-z-index,1);background:0 0;overflow:visible}dialog:not([open]){display:none}dialog::backdrop{background-color:transparent}#backdrop{display:none;position:fixed;inset:0;margin:0;border:none;padding:0;background:0 0;pointer-events:auto;z-index:0}dialog[data-modal-backdrop] #backdrop{display:block}#content{position:relative;z-index:var(--sinch-comp-pop-z-index,1)}#target-open{display:flex;flex-direction:column;position:absolute;left:0;top:0;z-index:var(--sinch-comp-pop-z-index,1)}#focus{display:none;position:absolute;width:0;height:0}</style><slot id="target" name="target" aria-haspopup="dialog" aria-expanded="false"></slot><div id="focus"></div><dialog id="dialog"><div id="backdrop"></div><div id="target-open"><slot name="target-open"></slot></div><div id="content"><slot name="content"></slot></div></dialog>';
|
|
3586
3584
|
const template$Z = document.createElement("template");
|
|
3587
3585
|
template$Z.innerHTML = templateHTML$Z;
|
|
3588
3586
|
class Pop extends NectaryElement {
|
|
3589
3587
|
#$targetWrapper;
|
|
3590
3588
|
#$focus;
|
|
3591
3589
|
#$dialog;
|
|
3590
|
+
#$backdrop;
|
|
3592
3591
|
#resizeThrottle;
|
|
3593
3592
|
#scrollPositionThrottle;
|
|
3594
3593
|
#resizeObserver;
|
|
@@ -3603,9 +3602,11 @@ class Pop extends NectaryElement {
|
|
|
3603
3602
|
#modalWidth = 0;
|
|
3604
3603
|
#modalHeight = 0;
|
|
3605
3604
|
#scrollableParents = [];
|
|
3605
|
+
#documentDismissController = null;
|
|
3606
3606
|
#openSession = {
|
|
3607
3607
|
effectiveAllowScroll: false,
|
|
3608
3608
|
modalSemantics: false,
|
|
3609
|
+
openAsModal: true,
|
|
3609
3610
|
targetStyleValue: null,
|
|
3610
3611
|
transformedAncestor: null
|
|
3611
3612
|
};
|
|
@@ -3623,6 +3624,7 @@ class Pop extends NectaryElement {
|
|
|
3623
3624
|
this.#$targetWrapper = shadowRoot.querySelector("#target");
|
|
3624
3625
|
this.#$focus = shadowRoot.querySelector("#focus");
|
|
3625
3626
|
this.#$dialog = shadowRoot.querySelector("#dialog");
|
|
3627
|
+
this.#$backdrop = shadowRoot.querySelector("#backdrop");
|
|
3626
3628
|
this.#$targetSlot = shadowRoot.querySelector('slot[name="target"]');
|
|
3627
3629
|
this.#$targetOpenSlot = shadowRoot.querySelector('slot[name="target-open"]');
|
|
3628
3630
|
this.#$contentSlot = shadowRoot.querySelector('slot[name="content"]');
|
|
@@ -3649,6 +3651,7 @@ class Pop extends NectaryElement {
|
|
|
3649
3651
|
this.#syncDialogA11yAttrs();
|
|
3650
3652
|
this.#$dialog.addEventListener("cancel", this.#onCancel, { signal });
|
|
3651
3653
|
this.#$dialog.addEventListener("mousedown", this.#onBackdropMouseDown, { signal });
|
|
3654
|
+
this.#$backdrop.addEventListener("pointerdown", this.#onModalBackdropPointerDown, { signal });
|
|
3652
3655
|
this.addEventListener("-close", this.#onCloseReactHandler, { signal });
|
|
3653
3656
|
subscribeContext(this, "visibility", this.#onContextVisibility, signal);
|
|
3654
3657
|
if (getBooleanAttribute(this, "open")) {
|
|
@@ -3744,7 +3747,9 @@ class Pop extends NectaryElement {
|
|
|
3744
3747
|
}
|
|
3745
3748
|
case "modal": {
|
|
3746
3749
|
if (this.#$dialog.open) {
|
|
3747
|
-
this.#
|
|
3750
|
+
this.#openSession.modalSemantics = this.modal;
|
|
3751
|
+
this.#syncDialogSemantics(this.modal);
|
|
3752
|
+
this.#syncModalBackdrop(this.#needsModalBackdrop());
|
|
3748
3753
|
}
|
|
3749
3754
|
break;
|
|
3750
3755
|
}
|
|
@@ -3783,8 +3788,19 @@ class Pop extends NectaryElement {
|
|
|
3783
3788
|
this.#hasManagedHostRole = false;
|
|
3784
3789
|
this.#$dialog.removeAttribute("aria-modal");
|
|
3785
3790
|
}
|
|
3786
|
-
#
|
|
3787
|
-
return
|
|
3791
|
+
#needsModalBackdrop(openSession = this.#openSession) {
|
|
3792
|
+
return openSession.modalSemantics && !openSession.openAsModal;
|
|
3793
|
+
}
|
|
3794
|
+
#syncModalBackdrop(shouldShow) {
|
|
3795
|
+
if (shouldShow) {
|
|
3796
|
+
this.#$dialog.setAttribute("data-modal-backdrop", "");
|
|
3797
|
+
} else {
|
|
3798
|
+
this.#$dialog.removeAttribute("data-modal-backdrop");
|
|
3799
|
+
}
|
|
3800
|
+
}
|
|
3801
|
+
#usesShowModal(transformedAncestor) {
|
|
3802
|
+
const effectiveAllowScroll = this.allowScroll || transformedAncestor != null;
|
|
3803
|
+
return !effectiveAllowScroll || this.modal && transformedAncestor === null;
|
|
3788
3804
|
}
|
|
3789
3805
|
#getTargetRect() {
|
|
3790
3806
|
let item = getFirstSlotElement(this.#$targetSlot, true);
|
|
@@ -3854,22 +3870,56 @@ class Pop extends NectaryElement {
|
|
|
3854
3870
|
el.removeEventListener("scroll", this.#onScrollableParentScroll, { capture: true });
|
|
3855
3871
|
});
|
|
3856
3872
|
}
|
|
3873
|
+
#subscribeDocumentDismiss() {
|
|
3874
|
+
this.#documentDismissController = new AbortController();
|
|
3875
|
+
const { signal } = this.#documentDismissController;
|
|
3876
|
+
requestAnimationFrame(() => {
|
|
3877
|
+
requestAnimationFrame(() => {
|
|
3878
|
+
if (!signal.aborted && this.isDomConnected && this.#$dialog.open) {
|
|
3879
|
+
document.addEventListener("pointerdown", this.#onDocumentPointerDown, { capture: true, signal });
|
|
3880
|
+
}
|
|
3881
|
+
});
|
|
3882
|
+
});
|
|
3883
|
+
}
|
|
3884
|
+
#unsubscribeDocumentDismiss() {
|
|
3885
|
+
this.#documentDismissController?.abort();
|
|
3886
|
+
this.#documentDismissController = null;
|
|
3887
|
+
}
|
|
3888
|
+
#isPointerEventInsidePop(e) {
|
|
3889
|
+
for (const node of e.composedPath()) {
|
|
3890
|
+
if (node === this || node === this.#$dialog) {
|
|
3891
|
+
return true;
|
|
3892
|
+
}
|
|
3893
|
+
if (node instanceof Node && composedContains(this.#$dialog, node)) {
|
|
3894
|
+
return true;
|
|
3895
|
+
}
|
|
3896
|
+
for (const targetEl of [
|
|
3897
|
+
...this.#$targetSlot.assignedElements({ flatten: true }),
|
|
3898
|
+
...this.#$targetOpenSlot.assignedElements({ flatten: true })
|
|
3899
|
+
]) {
|
|
3900
|
+
if (node === targetEl || node instanceof Node && composedContains(targetEl, node)) {
|
|
3901
|
+
return true;
|
|
3902
|
+
}
|
|
3903
|
+
}
|
|
3904
|
+
}
|
|
3905
|
+
return false;
|
|
3906
|
+
}
|
|
3857
3907
|
#onExpand() {
|
|
3858
3908
|
if (!this.isDomConnected || this.#$dialog.open) {
|
|
3859
3909
|
return;
|
|
3860
3910
|
}
|
|
3861
3911
|
const transformedAncestor = getTransformedAncestor(this);
|
|
3862
3912
|
const effectiveAllowScroll = this.allowScroll || transformedAncestor != null;
|
|
3863
|
-
const
|
|
3864
|
-
const openAsModal = shouldUseModal || !effectiveAllowScroll;
|
|
3913
|
+
const openAsModal = this.#usesShowModal(transformedAncestor);
|
|
3865
3914
|
this.#openSession = {
|
|
3866
3915
|
effectiveAllowScroll,
|
|
3867
|
-
modalSemantics:
|
|
3916
|
+
modalSemantics: this.modal,
|
|
3917
|
+
openAsModal,
|
|
3868
3918
|
targetStyleValue: null,
|
|
3869
3919
|
transformedAncestor
|
|
3870
3920
|
};
|
|
3871
3921
|
this.#syncDialogA11yAttrs();
|
|
3872
|
-
this.#syncDialogSemantics(
|
|
3922
|
+
this.#syncDialogSemantics(this.modal);
|
|
3873
3923
|
this.#$targetSlot.addEventListener("blur", this.#stopEventPropagation, true);
|
|
3874
3924
|
this.#$focus.setAttribute("tabindex", "-1");
|
|
3875
3925
|
this.#$focus.style.display = "block";
|
|
@@ -3884,10 +3934,11 @@ class Pop extends NectaryElement {
|
|
|
3884
3934
|
} else {
|
|
3885
3935
|
this.#$dialog.show();
|
|
3886
3936
|
}
|
|
3937
|
+
this.#syncModalBackdrop(this.#needsModalBackdrop());
|
|
3887
3938
|
this.#$targetWrapper.setAttribute("aria-expanded", "true");
|
|
3888
3939
|
this.#updateOrientation();
|
|
3889
3940
|
this.#resizeObserver.observe(this.#$dialog);
|
|
3890
|
-
if (
|
|
3941
|
+
if (this.modal) {
|
|
3891
3942
|
getFirstFocusableElement(this.#$contentSlot)?.focus();
|
|
3892
3943
|
} else {
|
|
3893
3944
|
if (!effectiveAllowScroll) {
|
|
@@ -3915,6 +3966,9 @@ class Pop extends NectaryElement {
|
|
|
3915
3966
|
} else {
|
|
3916
3967
|
this.#subscribeScrollTracking();
|
|
3917
3968
|
}
|
|
3969
|
+
if (!openAsModal) {
|
|
3970
|
+
this.#subscribeDocumentDismiss();
|
|
3971
|
+
}
|
|
3918
3972
|
window.addEventListener("resize", this.#onResize);
|
|
3919
3973
|
requestAnimationFrame(() => {
|
|
3920
3974
|
if (this.isDomConnected && this.#$dialog.open) {
|
|
@@ -3931,19 +3985,21 @@ class Pop extends NectaryElement {
|
|
|
3931
3985
|
const openSession = this.#openSession;
|
|
3932
3986
|
const effectiveAllowScroll = openSession.effectiveAllowScroll;
|
|
3933
3987
|
this.#resizeObserver.disconnect();
|
|
3934
|
-
const
|
|
3988
|
+
const usesShowClosePath = !openSession.openAsModal;
|
|
3989
|
+
const hasTransferredTarget = !openSession.modalSemantics && !effectiveAllowScroll;
|
|
3935
3990
|
const activeSlot = effectiveAllowScroll ? this.#$targetSlot : this.#$targetOpenSlot;
|
|
3936
3991
|
this.#dispatchContentVisibility(false);
|
|
3937
3992
|
activeSlot.removeEventListener("keydown", this.#onTargetKeydown);
|
|
3938
|
-
if (
|
|
3993
|
+
if (usesShowClosePath) {
|
|
3939
3994
|
activeSlot.addEventListener("blur", this.#captureActiveElement, true);
|
|
3940
3995
|
}
|
|
3996
|
+
this.#syncModalBackdrop(false);
|
|
3941
3997
|
this.#$dialog.close();
|
|
3942
3998
|
this.#$targetWrapper.setAttribute("aria-expanded", "false");
|
|
3943
|
-
if (
|
|
3999
|
+
if (usesShowClosePath) {
|
|
3944
4000
|
activeSlot.removeEventListener("blur", this.#captureActiveElement, true);
|
|
3945
4001
|
}
|
|
3946
|
-
if (
|
|
4002
|
+
if (hasTransferredTarget) {
|
|
3947
4003
|
this.#restoreTransferredTarget();
|
|
3948
4004
|
}
|
|
3949
4005
|
if (this.shouldRestoreFocusOnClose && this.#targetActiveElement !== null) {
|
|
@@ -3964,6 +4020,7 @@ class Pop extends NectaryElement {
|
|
|
3964
4020
|
}
|
|
3965
4021
|
}
|
|
3966
4022
|
this.#targetActiveElement = null;
|
|
4023
|
+
this.#unsubscribeDocumentDismiss();
|
|
3967
4024
|
if (!effectiveAllowScroll) {
|
|
3968
4025
|
enableOverscroll();
|
|
3969
4026
|
} else {
|
|
@@ -3977,6 +4034,7 @@ class Pop extends NectaryElement {
|
|
|
3977
4034
|
this.#openSession = {
|
|
3978
4035
|
effectiveAllowScroll: false,
|
|
3979
4036
|
modalSemantics: false,
|
|
4037
|
+
openAsModal: true,
|
|
3980
4038
|
targetStyleValue: null,
|
|
3981
4039
|
transformedAncestor: null
|
|
3982
4040
|
};
|
|
@@ -3985,7 +4043,17 @@ class Pop extends NectaryElement {
|
|
|
3985
4043
|
#onResize = () => {
|
|
3986
4044
|
this.#resizeThrottle.fn();
|
|
3987
4045
|
};
|
|
3988
|
-
#
|
|
4046
|
+
#shouldRepositionForScroll(scrollingElement) {
|
|
4047
|
+
const { transformedAncestor } = this.#openSession;
|
|
4048
|
+
if (transformedAncestor == null || !(scrollingElement instanceof HTMLElement)) {
|
|
4049
|
+
return true;
|
|
4050
|
+
}
|
|
4051
|
+
return scrollingElement !== transformedAncestor;
|
|
4052
|
+
}
|
|
4053
|
+
#onScrollableParentScroll = (e) => {
|
|
4054
|
+
if (!this.#shouldRepositionForScroll(e.target)) {
|
|
4055
|
+
return;
|
|
4056
|
+
}
|
|
3989
4057
|
this.#scrollPositionThrottle.fn();
|
|
3990
4058
|
};
|
|
3991
4059
|
#updatePosition = (updateWidth) => {
|
|
@@ -4051,6 +4119,27 @@ class Pop extends NectaryElement {
|
|
|
4051
4119
|
}
|
|
4052
4120
|
}
|
|
4053
4121
|
};
|
|
4122
|
+
#onModalBackdropPointerDown = (e) => {
|
|
4123
|
+
if (!this.shouldCloseOnBackdropClick || e.button !== 0) {
|
|
4124
|
+
return;
|
|
4125
|
+
}
|
|
4126
|
+
e.preventDefault();
|
|
4127
|
+
e.stopPropagation();
|
|
4128
|
+
this.#dispatchCloseEvent();
|
|
4129
|
+
};
|
|
4130
|
+
#onDocumentPointerDown = (e) => {
|
|
4131
|
+
if (!this.shouldCloseOnBackdropClick || this.#$dialog.open === false) {
|
|
4132
|
+
return;
|
|
4133
|
+
}
|
|
4134
|
+
if (e.button !== 0) {
|
|
4135
|
+
return;
|
|
4136
|
+
}
|
|
4137
|
+
if (this.#isPointerEventInsidePop(e)) {
|
|
4138
|
+
return;
|
|
4139
|
+
}
|
|
4140
|
+
e.preventDefault();
|
|
4141
|
+
this.#dispatchCloseEvent();
|
|
4142
|
+
};
|
|
4054
4143
|
#onCancel = (e) => {
|
|
4055
4144
|
e.preventDefault();
|
|
4056
4145
|
e.stopPropagation();
|
package/package.json
CHANGED
package/pop/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Context, subscribeContext } from "../utils/context.js";
|
|
2
|
-
import { getBooleanAttribute, updateBooleanAttribute, getLiteralAttribute, updateLiteralAttribute, updateIntegerAttribute, getIntegerAttribute, isAttrEqual, getScrollableParents, getTransformedAncestor, isAttrTrue } from "../utils/dom.js";
|
|
2
|
+
import { getBooleanAttribute, updateBooleanAttribute, getLiteralAttribute, updateLiteralAttribute, updateIntegerAttribute, getIntegerAttribute, isAttrEqual, getScrollableParents, composedContains, getTransformedAncestor, isAttrTrue } from "../utils/dom.js";
|
|
3
3
|
import { defineCustomElement, NectaryElement } from "../utils/element.js";
|
|
4
4
|
import { getRect } from "../utils/rect.js";
|
|
5
5
|
import { getFirstSlotElement, getFirstFocusableElement, isElementFocused } from "../utils/slot.js";
|
|
@@ -8,13 +8,14 @@ import { getReactEventHandler } from "../utils/get-react-event-handler.js";
|
|
|
8
8
|
import { isTargetEqual } from "../utils/event-target.js";
|
|
9
9
|
import { getPlacementContext, toLocalRect } from "../utils/placement.js";
|
|
10
10
|
import { orientationValues, disableOverscroll, enableOverscroll, getAnchorPosition, clampPosition } from "./utils.js";
|
|
11
|
-
const templateHTML = '<style>:host{display:contents;position:relative}dialog{position:fixed;left:0;top:0;transform:translate(var(--sinch-pop-offset-x),var(--sinch-pop-offset-y));margin:0;outline:0;padding:0;border:none;box-sizing:border-box;max-width:unset;max-height:unset;z-index:var(--sinch-comp-pop-z-index,1);background:0 0;overflow:visible}dialog:not([open]){display:none}dialog::backdrop{background-color:transparent}#content{position:relative;z-index:var(--sinch-comp-pop-z-index,1)}#target-open{display:flex;flex-direction:column;position:absolute;left:0;top:0}#focus{display:none;position:absolute;width:0;height:0}</style><slot id="target" name="target" aria-haspopup="dialog" aria-expanded="false"></slot><div id="focus"></div><dialog id="dialog"><div id="target-open"><slot name="target-open"></slot></div><div id="content"><slot name="content"></slot></div></dialog>';
|
|
11
|
+
const templateHTML = '<style>:host{display:contents;position:relative}dialog{position:fixed;left:0;top:0;transform:translate(var(--sinch-pop-offset-x),var(--sinch-pop-offset-y));margin:0;outline:0;padding:0;border:none;box-sizing:border-box;max-width:unset;max-height:unset;z-index:var(--sinch-comp-pop-z-index,1);background:0 0;overflow:visible}dialog:not([open]){display:none}dialog::backdrop{background-color:transparent}#backdrop{display:none;position:fixed;inset:0;margin:0;border:none;padding:0;background:0 0;pointer-events:auto;z-index:0}dialog[data-modal-backdrop] #backdrop{display:block}#content{position:relative;z-index:var(--sinch-comp-pop-z-index,1)}#target-open{display:flex;flex-direction:column;position:absolute;left:0;top:0;z-index:var(--sinch-comp-pop-z-index,1)}#focus{display:none;position:absolute;width:0;height:0}</style><slot id="target" name="target" aria-haspopup="dialog" aria-expanded="false"></slot><div id="focus"></div><dialog id="dialog"><div id="backdrop"></div><div id="target-open"><slot name="target-open"></slot></div><div id="content"><slot name="content"></slot></div></dialog>';
|
|
12
12
|
const template = document.createElement("template");
|
|
13
13
|
template.innerHTML = templateHTML;
|
|
14
14
|
class Pop extends NectaryElement {
|
|
15
15
|
#$targetWrapper;
|
|
16
16
|
#$focus;
|
|
17
17
|
#$dialog;
|
|
18
|
+
#$backdrop;
|
|
18
19
|
#resizeThrottle;
|
|
19
20
|
#scrollPositionThrottle;
|
|
20
21
|
#resizeObserver;
|
|
@@ -29,9 +30,11 @@ class Pop extends NectaryElement {
|
|
|
29
30
|
#modalWidth = 0;
|
|
30
31
|
#modalHeight = 0;
|
|
31
32
|
#scrollableParents = [];
|
|
33
|
+
#documentDismissController = null;
|
|
32
34
|
#openSession = {
|
|
33
35
|
effectiveAllowScroll: false,
|
|
34
36
|
modalSemantics: false,
|
|
37
|
+
openAsModal: true,
|
|
35
38
|
targetStyleValue: null,
|
|
36
39
|
transformedAncestor: null
|
|
37
40
|
};
|
|
@@ -49,6 +52,7 @@ class Pop extends NectaryElement {
|
|
|
49
52
|
this.#$targetWrapper = shadowRoot.querySelector("#target");
|
|
50
53
|
this.#$focus = shadowRoot.querySelector("#focus");
|
|
51
54
|
this.#$dialog = shadowRoot.querySelector("#dialog");
|
|
55
|
+
this.#$backdrop = shadowRoot.querySelector("#backdrop");
|
|
52
56
|
this.#$targetSlot = shadowRoot.querySelector('slot[name="target"]');
|
|
53
57
|
this.#$targetOpenSlot = shadowRoot.querySelector('slot[name="target-open"]');
|
|
54
58
|
this.#$contentSlot = shadowRoot.querySelector('slot[name="content"]');
|
|
@@ -75,6 +79,7 @@ class Pop extends NectaryElement {
|
|
|
75
79
|
this.#syncDialogA11yAttrs();
|
|
76
80
|
this.#$dialog.addEventListener("cancel", this.#onCancel, { signal });
|
|
77
81
|
this.#$dialog.addEventListener("mousedown", this.#onBackdropMouseDown, { signal });
|
|
82
|
+
this.#$backdrop.addEventListener("pointerdown", this.#onModalBackdropPointerDown, { signal });
|
|
78
83
|
this.addEventListener("-close", this.#onCloseReactHandler, { signal });
|
|
79
84
|
subscribeContext(this, "visibility", this.#onContextVisibility, signal);
|
|
80
85
|
if (getBooleanAttribute(this, "open")) {
|
|
@@ -170,7 +175,9 @@ class Pop extends NectaryElement {
|
|
|
170
175
|
}
|
|
171
176
|
case "modal": {
|
|
172
177
|
if (this.#$dialog.open) {
|
|
173
|
-
this.#
|
|
178
|
+
this.#openSession.modalSemantics = this.modal;
|
|
179
|
+
this.#syncDialogSemantics(this.modal);
|
|
180
|
+
this.#syncModalBackdrop(this.#needsModalBackdrop());
|
|
174
181
|
}
|
|
175
182
|
break;
|
|
176
183
|
}
|
|
@@ -209,8 +216,19 @@ class Pop extends NectaryElement {
|
|
|
209
216
|
this.#hasManagedHostRole = false;
|
|
210
217
|
this.#$dialog.removeAttribute("aria-modal");
|
|
211
218
|
}
|
|
212
|
-
#
|
|
213
|
-
return
|
|
219
|
+
#needsModalBackdrop(openSession = this.#openSession) {
|
|
220
|
+
return openSession.modalSemantics && !openSession.openAsModal;
|
|
221
|
+
}
|
|
222
|
+
#syncModalBackdrop(shouldShow) {
|
|
223
|
+
if (shouldShow) {
|
|
224
|
+
this.#$dialog.setAttribute("data-modal-backdrop", "");
|
|
225
|
+
} else {
|
|
226
|
+
this.#$dialog.removeAttribute("data-modal-backdrop");
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
#usesShowModal(transformedAncestor) {
|
|
230
|
+
const effectiveAllowScroll = this.allowScroll || transformedAncestor != null;
|
|
231
|
+
return !effectiveAllowScroll || this.modal && transformedAncestor === null;
|
|
214
232
|
}
|
|
215
233
|
#getTargetRect() {
|
|
216
234
|
let item = getFirstSlotElement(this.#$targetSlot, true);
|
|
@@ -280,22 +298,56 @@ class Pop extends NectaryElement {
|
|
|
280
298
|
el.removeEventListener("scroll", this.#onScrollableParentScroll, { capture: true });
|
|
281
299
|
});
|
|
282
300
|
}
|
|
301
|
+
#subscribeDocumentDismiss() {
|
|
302
|
+
this.#documentDismissController = new AbortController();
|
|
303
|
+
const { signal } = this.#documentDismissController;
|
|
304
|
+
requestAnimationFrame(() => {
|
|
305
|
+
requestAnimationFrame(() => {
|
|
306
|
+
if (!signal.aborted && this.isDomConnected && this.#$dialog.open) {
|
|
307
|
+
document.addEventListener("pointerdown", this.#onDocumentPointerDown, { capture: true, signal });
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
#unsubscribeDocumentDismiss() {
|
|
313
|
+
this.#documentDismissController?.abort();
|
|
314
|
+
this.#documentDismissController = null;
|
|
315
|
+
}
|
|
316
|
+
#isPointerEventInsidePop(e) {
|
|
317
|
+
for (const node of e.composedPath()) {
|
|
318
|
+
if (node === this || node === this.#$dialog) {
|
|
319
|
+
return true;
|
|
320
|
+
}
|
|
321
|
+
if (node instanceof Node && composedContains(this.#$dialog, node)) {
|
|
322
|
+
return true;
|
|
323
|
+
}
|
|
324
|
+
for (const targetEl of [
|
|
325
|
+
...this.#$targetSlot.assignedElements({ flatten: true }),
|
|
326
|
+
...this.#$targetOpenSlot.assignedElements({ flatten: true })
|
|
327
|
+
]) {
|
|
328
|
+
if (node === targetEl || node instanceof Node && composedContains(targetEl, node)) {
|
|
329
|
+
return true;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
283
335
|
#onExpand() {
|
|
284
336
|
if (!this.isDomConnected || this.#$dialog.open) {
|
|
285
337
|
return;
|
|
286
338
|
}
|
|
287
339
|
const transformedAncestor = getTransformedAncestor(this);
|
|
288
340
|
const effectiveAllowScroll = this.allowScroll || transformedAncestor != null;
|
|
289
|
-
const
|
|
290
|
-
const openAsModal = shouldUseModal || !effectiveAllowScroll;
|
|
341
|
+
const openAsModal = this.#usesShowModal(transformedAncestor);
|
|
291
342
|
this.#openSession = {
|
|
292
343
|
effectiveAllowScroll,
|
|
293
|
-
modalSemantics:
|
|
344
|
+
modalSemantics: this.modal,
|
|
345
|
+
openAsModal,
|
|
294
346
|
targetStyleValue: null,
|
|
295
347
|
transformedAncestor
|
|
296
348
|
};
|
|
297
349
|
this.#syncDialogA11yAttrs();
|
|
298
|
-
this.#syncDialogSemantics(
|
|
350
|
+
this.#syncDialogSemantics(this.modal);
|
|
299
351
|
this.#$targetSlot.addEventListener("blur", this.#stopEventPropagation, true);
|
|
300
352
|
this.#$focus.setAttribute("tabindex", "-1");
|
|
301
353
|
this.#$focus.style.display = "block";
|
|
@@ -310,10 +362,11 @@ class Pop extends NectaryElement {
|
|
|
310
362
|
} else {
|
|
311
363
|
this.#$dialog.show();
|
|
312
364
|
}
|
|
365
|
+
this.#syncModalBackdrop(this.#needsModalBackdrop());
|
|
313
366
|
this.#$targetWrapper.setAttribute("aria-expanded", "true");
|
|
314
367
|
this.#updateOrientation();
|
|
315
368
|
this.#resizeObserver.observe(this.#$dialog);
|
|
316
|
-
if (
|
|
369
|
+
if (this.modal) {
|
|
317
370
|
getFirstFocusableElement(this.#$contentSlot)?.focus();
|
|
318
371
|
} else {
|
|
319
372
|
if (!effectiveAllowScroll) {
|
|
@@ -341,6 +394,9 @@ class Pop extends NectaryElement {
|
|
|
341
394
|
} else {
|
|
342
395
|
this.#subscribeScrollTracking();
|
|
343
396
|
}
|
|
397
|
+
if (!openAsModal) {
|
|
398
|
+
this.#subscribeDocumentDismiss();
|
|
399
|
+
}
|
|
344
400
|
window.addEventListener("resize", this.#onResize);
|
|
345
401
|
requestAnimationFrame(() => {
|
|
346
402
|
if (this.isDomConnected && this.#$dialog.open) {
|
|
@@ -357,19 +413,21 @@ class Pop extends NectaryElement {
|
|
|
357
413
|
const openSession = this.#openSession;
|
|
358
414
|
const effectiveAllowScroll = openSession.effectiveAllowScroll;
|
|
359
415
|
this.#resizeObserver.disconnect();
|
|
360
|
-
const
|
|
416
|
+
const usesShowClosePath = !openSession.openAsModal;
|
|
417
|
+
const hasTransferredTarget = !openSession.modalSemantics && !effectiveAllowScroll;
|
|
361
418
|
const activeSlot = effectiveAllowScroll ? this.#$targetSlot : this.#$targetOpenSlot;
|
|
362
419
|
this.#dispatchContentVisibility(false);
|
|
363
420
|
activeSlot.removeEventListener("keydown", this.#onTargetKeydown);
|
|
364
|
-
if (
|
|
421
|
+
if (usesShowClosePath) {
|
|
365
422
|
activeSlot.addEventListener("blur", this.#captureActiveElement, true);
|
|
366
423
|
}
|
|
424
|
+
this.#syncModalBackdrop(false);
|
|
367
425
|
this.#$dialog.close();
|
|
368
426
|
this.#$targetWrapper.setAttribute("aria-expanded", "false");
|
|
369
|
-
if (
|
|
427
|
+
if (usesShowClosePath) {
|
|
370
428
|
activeSlot.removeEventListener("blur", this.#captureActiveElement, true);
|
|
371
429
|
}
|
|
372
|
-
if (
|
|
430
|
+
if (hasTransferredTarget) {
|
|
373
431
|
this.#restoreTransferredTarget();
|
|
374
432
|
}
|
|
375
433
|
if (this.shouldRestoreFocusOnClose && this.#targetActiveElement !== null) {
|
|
@@ -390,6 +448,7 @@ class Pop extends NectaryElement {
|
|
|
390
448
|
}
|
|
391
449
|
}
|
|
392
450
|
this.#targetActiveElement = null;
|
|
451
|
+
this.#unsubscribeDocumentDismiss();
|
|
393
452
|
if (!effectiveAllowScroll) {
|
|
394
453
|
enableOverscroll();
|
|
395
454
|
} else {
|
|
@@ -403,6 +462,7 @@ class Pop extends NectaryElement {
|
|
|
403
462
|
this.#openSession = {
|
|
404
463
|
effectiveAllowScroll: false,
|
|
405
464
|
modalSemantics: false,
|
|
465
|
+
openAsModal: true,
|
|
406
466
|
targetStyleValue: null,
|
|
407
467
|
transformedAncestor: null
|
|
408
468
|
};
|
|
@@ -411,7 +471,17 @@ class Pop extends NectaryElement {
|
|
|
411
471
|
#onResize = () => {
|
|
412
472
|
this.#resizeThrottle.fn();
|
|
413
473
|
};
|
|
414
|
-
#
|
|
474
|
+
#shouldRepositionForScroll(scrollingElement) {
|
|
475
|
+
const { transformedAncestor } = this.#openSession;
|
|
476
|
+
if (transformedAncestor == null || !(scrollingElement instanceof HTMLElement)) {
|
|
477
|
+
return true;
|
|
478
|
+
}
|
|
479
|
+
return scrollingElement !== transformedAncestor;
|
|
480
|
+
}
|
|
481
|
+
#onScrollableParentScroll = (e) => {
|
|
482
|
+
if (!this.#shouldRepositionForScroll(e.target)) {
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
415
485
|
this.#scrollPositionThrottle.fn();
|
|
416
486
|
};
|
|
417
487
|
#updatePosition = (updateWidth) => {
|
|
@@ -477,6 +547,27 @@ class Pop extends NectaryElement {
|
|
|
477
547
|
}
|
|
478
548
|
}
|
|
479
549
|
};
|
|
550
|
+
#onModalBackdropPointerDown = (e) => {
|
|
551
|
+
if (!this.shouldCloseOnBackdropClick || e.button !== 0) {
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
e.preventDefault();
|
|
555
|
+
e.stopPropagation();
|
|
556
|
+
this.#dispatchCloseEvent();
|
|
557
|
+
};
|
|
558
|
+
#onDocumentPointerDown = (e) => {
|
|
559
|
+
if (!this.shouldCloseOnBackdropClick || this.#$dialog.open === false) {
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
if (e.button !== 0) {
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
if (this.#isPointerEventInsidePop(e)) {
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
e.preventDefault();
|
|
569
|
+
this.#dispatchCloseEvent();
|
|
570
|
+
};
|
|
480
571
|
#onCancel = (e) => {
|
|
481
572
|
e.preventDefault();
|
|
482
573
|
e.stopPropagation();
|
package/utils/dom.js
CHANGED
|
@@ -221,9 +221,7 @@ const isTransformedElement = (element) => {
|
|
|
221
221
|
}
|
|
222
222
|
const style = getComputedStyle(element);
|
|
223
223
|
const backdropFilter = style.getPropertyValue("backdrop-filter");
|
|
224
|
-
|
|
225
|
-
const hasWillChange = style.willChange.split(",").map((value) => value.trim().toLowerCase()).some((value) => value === "transform" || value === "perspective" || value === "filter" || value === "backdrop-filter");
|
|
226
|
-
return hasTransform || hasWillChange;
|
|
224
|
+
return style.transform !== "none" || style.perspective !== "none" || style.filter !== "none" || backdropFilter !== "" && backdropFilter !== "none";
|
|
227
225
|
};
|
|
228
226
|
const getTransformedAncestor = (node) => {
|
|
229
227
|
let current = node;
|