@zag-js/popover 0.0.0-dev-20220603082742 → 0.0.0-dev-20220604091934
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/index.js +38 -35
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +39 -36
- package/dist/index.mjs.map +2 -2
- package/dist/popover.connect.d.ts.map +1 -1
- package/dist/popover.dom.d.ts.map +1 -1
- package/dist/popover.machine.d.ts.map +1 -1
- package/dist/popover.types.d.ts +6 -13
- package/dist/popover.types.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -512,7 +512,8 @@ var getFocusables = (el, includeContainer = false) => {
|
|
|
512
512
|
if (!el)
|
|
513
513
|
return [];
|
|
514
514
|
let els = Array.from(el.querySelectorAll(focusableSelector));
|
|
515
|
-
|
|
515
|
+
const shouldAddContainer = includeContainer == true || includeContainer == "if-empty" && els.length === 0;
|
|
516
|
+
if (shouldAddContainer && isHTMLElement(el)) {
|
|
516
517
|
els.unshift(el);
|
|
517
518
|
}
|
|
518
519
|
return els.filter((el2) => isFocusable(el2) && !isHidden(el2));
|
|
@@ -523,6 +524,8 @@ var isFocusable = (el) => {
|
|
|
523
524
|
return el == null ? void 0 : el.matches(focusableSelector);
|
|
524
525
|
};
|
|
525
526
|
var getTabbables = (el, includeContainer = false) => {
|
|
527
|
+
if (!el)
|
|
528
|
+
return [];
|
|
526
529
|
return getFocusables(el, includeContainer).filter(isTabbable);
|
|
527
530
|
};
|
|
528
531
|
var isTabbable = (el) => {
|
|
@@ -675,15 +678,16 @@ var dom = {
|
|
|
675
678
|
getFocusableEls: (ctx) => getFocusables(dom.getContentEl(ctx)),
|
|
676
679
|
getFirstFocusableEl: (ctx) => dom.getFocusableEls(ctx)[0],
|
|
677
680
|
getDocTabbableEls: (ctx) => getTabbables(cast(dom.getDoc(ctx))),
|
|
678
|
-
getTabbableEls: (ctx) =>
|
|
679
|
-
const el = dom.getContentEl(ctx);
|
|
680
|
-
return el ? getTabbables(el) : [];
|
|
681
|
-
},
|
|
681
|
+
getTabbableEls: (ctx) => getTabbables(dom.getContentEl(ctx), "if-empty"),
|
|
682
682
|
getFirstTabbableEl: (ctx) => first(dom.getTabbableEls(ctx)),
|
|
683
683
|
getLastTabbableEl: (ctx) => last(dom.getTabbableEls(ctx)),
|
|
684
684
|
getInitialFocusEl: (ctx) => {
|
|
685
|
-
|
|
686
|
-
|
|
685
|
+
let el = runIfFn2(ctx.initialFocusEl);
|
|
686
|
+
if (!el && ctx.autoFocus)
|
|
687
|
+
el = dom.getFirstFocusableEl(ctx);
|
|
688
|
+
if (!el)
|
|
689
|
+
el = dom.getContentEl(ctx);
|
|
690
|
+
return el;
|
|
687
691
|
}
|
|
688
692
|
};
|
|
689
693
|
|
|
@@ -691,9 +695,10 @@ var dom = {
|
|
|
691
695
|
function connect(state, send, normalize = normalizeProp) {
|
|
692
696
|
const isOpen = state.matches("open");
|
|
693
697
|
const pointerdownNode = state.context.pointerdownNode;
|
|
698
|
+
const currentPlacement = state.context.currentPlacement;
|
|
694
699
|
const popperStyles = (0, import_popper.getPlacementStyles)({
|
|
695
700
|
measured: !!state.context.isPlacementComplete,
|
|
696
|
-
placement:
|
|
701
|
+
placement: currentPlacement
|
|
697
702
|
});
|
|
698
703
|
return {
|
|
699
704
|
portalled: state.context.currentPortalled,
|
|
@@ -720,7 +725,7 @@ function connect(state, send, normalize = normalizeProp) {
|
|
|
720
725
|
triggerProps: normalize.button({
|
|
721
726
|
"data-part": "trigger",
|
|
722
727
|
type: "button",
|
|
723
|
-
"data-placement":
|
|
728
|
+
"data-placement": currentPlacement,
|
|
724
729
|
id: dom.getTriggerId(state.context),
|
|
725
730
|
"aria-haspopup": "dialog",
|
|
726
731
|
"aria-expanded": isOpen,
|
|
@@ -728,6 +733,11 @@ function connect(state, send, normalize = normalizeProp) {
|
|
|
728
733
|
"aria-controls": dom.getContentId(state.context),
|
|
729
734
|
onClick() {
|
|
730
735
|
send("TRIGGER_CLICK");
|
|
736
|
+
},
|
|
737
|
+
onKeyDown(event) {
|
|
738
|
+
if (event.key === "Escape") {
|
|
739
|
+
send("ESCAPE");
|
|
740
|
+
}
|
|
731
741
|
}
|
|
732
742
|
}),
|
|
733
743
|
positionerProps: normalize.element({
|
|
@@ -742,9 +752,9 @@ function connect(state, send, normalize = normalizeProp) {
|
|
|
742
752
|
role: "dialog",
|
|
743
753
|
hidden: !isOpen,
|
|
744
754
|
"data-expanded": dataAttr(isOpen),
|
|
745
|
-
"aria-labelledby": state.context.
|
|
746
|
-
"aria-describedby": state.context.
|
|
747
|
-
"data-placement":
|
|
755
|
+
"aria-labelledby": state.context.renderedElements.title ? dom.getTitleId(state.context) : void 0,
|
|
756
|
+
"aria-describedby": state.context.renderedElements.description ? dom.getDescriptionId(state.context) : void 0,
|
|
757
|
+
"data-placement": currentPlacement,
|
|
748
758
|
onKeyDown(event) {
|
|
749
759
|
const keyMap = {
|
|
750
760
|
Escape(event2) {
|
|
@@ -792,19 +802,16 @@ function connect(state, send, normalize = normalizeProp) {
|
|
|
792
802
|
}
|
|
793
803
|
|
|
794
804
|
// src/popover.machine.ts
|
|
805
|
+
var import_aria_hidden = require("@zag-js/aria-hidden");
|
|
795
806
|
var import_core = require("@zag-js/core");
|
|
796
807
|
var import_popper2 = require("@zag-js/popper");
|
|
797
|
-
var import_aria_hidden = require("@zag-js/aria-hidden");
|
|
798
808
|
var import_focus_trap = require("focus-trap");
|
|
799
809
|
var { and, or } = import_core.guards;
|
|
800
810
|
function machine(ctx = {}) {
|
|
801
811
|
return (0, import_core.createMachine)({
|
|
802
812
|
id: "popover",
|
|
803
813
|
initial: "unknown",
|
|
804
|
-
context: __spreadValues({
|
|
805
|
-
isTitleRendered: true,
|
|
806
|
-
isDescriptionRendered: true,
|
|
807
|
-
isAnchorRendered: false,
|
|
814
|
+
context: __spreadProps(__spreadValues({
|
|
808
815
|
uid: "",
|
|
809
816
|
closeOnBlur: true,
|
|
810
817
|
closeOnEsc: true,
|
|
@@ -814,7 +821,13 @@ function machine(ctx = {}) {
|
|
|
814
821
|
placement: "bottom"
|
|
815
822
|
}, ctx.positioning),
|
|
816
823
|
currentPlacement: void 0
|
|
817
|
-
}, ctx),
|
|
824
|
+
}, ctx), {
|
|
825
|
+
renderedElements: {
|
|
826
|
+
title: true,
|
|
827
|
+
description: true,
|
|
828
|
+
anchor: false
|
|
829
|
+
}
|
|
830
|
+
}),
|
|
818
831
|
computed: {
|
|
819
832
|
currentPortalled: (ctx2) => !!ctx2.modal || !!ctx2.portalled
|
|
820
833
|
},
|
|
@@ -843,13 +856,7 @@ function machine(ctx = {}) {
|
|
|
843
856
|
"disableOutsidePointerEvents",
|
|
844
857
|
"computePlacement"
|
|
845
858
|
],
|
|
846
|
-
entry:
|
|
847
|
-
{
|
|
848
|
-
guard: "autoFocus",
|
|
849
|
-
actions: ["setInitialFocus", "invokeOnOpen"]
|
|
850
|
-
},
|
|
851
|
-
{ actions: ["focusContent", "invokeOnOpen"] }
|
|
852
|
-
]),
|
|
859
|
+
entry: ["setInitialFocus", "invokeOnOpen"],
|
|
853
860
|
on: {
|
|
854
861
|
CLOSE: {
|
|
855
862
|
target: "closed",
|
|
@@ -892,7 +899,7 @@ function machine(ctx = {}) {
|
|
|
892
899
|
activities: {
|
|
893
900
|
computePlacement(ctx2) {
|
|
894
901
|
ctx2.currentPlacement = ctx2.positioning.placement;
|
|
895
|
-
const anchorEl = ctx2.
|
|
902
|
+
const anchorEl = ctx2.renderedElements.anchor ? dom.getAnchorEl(ctx2) : dom.getTriggerEl(ctx2);
|
|
896
903
|
return (0, import_popper2.getPlacement)(anchorEl, dom.getPositionerEl(ctx2), __spreadProps(__spreadValues({}, ctx2.positioning), {
|
|
897
904
|
onComplete(data) {
|
|
898
905
|
ctx2.currentPlacement = data.placement;
|
|
@@ -970,9 +977,11 @@ function machine(ctx = {}) {
|
|
|
970
977
|
actions: {
|
|
971
978
|
checkRenderedElements(ctx2) {
|
|
972
979
|
raf(() => {
|
|
973
|
-
ctx2.
|
|
974
|
-
|
|
975
|
-
|
|
980
|
+
Object.assign(ctx2.renderedElements, {
|
|
981
|
+
title: !!dom.getTitleEl(ctx2),
|
|
982
|
+
description: !!dom.getDescriptionEl(ctx2),
|
|
983
|
+
anchor: !!dom.getAnchorEl(ctx2)
|
|
984
|
+
});
|
|
976
985
|
});
|
|
977
986
|
},
|
|
978
987
|
setupDocument(ctx2, evt) {
|
|
@@ -985,12 +994,6 @@ function machine(ctx = {}) {
|
|
|
985
994
|
clearPointerDown(ctx2) {
|
|
986
995
|
ctx2.pointerdownNode = null;
|
|
987
996
|
},
|
|
988
|
-
focusContent(ctx2) {
|
|
989
|
-
raf(() => {
|
|
990
|
-
var _a;
|
|
991
|
-
(_a = dom.getContentEl(ctx2)) == null ? void 0 : _a.focus();
|
|
992
|
-
});
|
|
993
|
-
},
|
|
994
997
|
setInitialFocus(ctx2) {
|
|
995
998
|
raf(() => {
|
|
996
999
|
var _a;
|