@broberg/app-shell 0.11.0 → 0.11.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/README.md +11 -1
- package/css/app-shell.css +7 -7
- package/dist/preact.cjs +29 -1
- package/dist/preact.cjs.map +1 -1
- package/dist/preact.js +29 -1
- package/dist/preact.js.map +1 -1
- package/package.json +1 -1
package/dist/preact.js
CHANGED
|
@@ -845,6 +845,33 @@ function Segmented(props) {
|
|
|
845
845
|
}
|
|
846
846
|
function Dropdown(props) {
|
|
847
847
|
const [state, setState] = useState({ open: false, highlighted: -1 });
|
|
848
|
+
const btnRef = useRef(null);
|
|
849
|
+
const listRef = useRef(null);
|
|
850
|
+
const [pos, setPos] = useState(void 0);
|
|
851
|
+
useLayoutEffect(() => {
|
|
852
|
+
if (!state.open || !btnRef.current) return setPos(void 0);
|
|
853
|
+
const r = btnRef.current.getBoundingClientRect();
|
|
854
|
+
const vw = window.innerWidth, vh = window.innerHeight, m = 8;
|
|
855
|
+
const h = listRef.current?.offsetHeight ?? 0;
|
|
856
|
+
const width = Math.min(Math.max(r.width, 160), vw - 2 * m);
|
|
857
|
+
const left = Math.max(m, Math.min(r.right - width, vw - width - m));
|
|
858
|
+
const below = r.bottom + 4;
|
|
859
|
+
const top = below + h <= vh - m || r.top - 4 - h < m ? Math.min(below, vh - m - h) : r.top - 4 - h;
|
|
860
|
+
setPos({ position: "fixed", left: `${left}px`, top: `${Math.max(m, top)}px`, width: `${width}px` });
|
|
861
|
+
}, [state.open]);
|
|
862
|
+
useEffect(() => {
|
|
863
|
+
if (!state.open) return;
|
|
864
|
+
const close = (e) => {
|
|
865
|
+
if (e.target instanceof Node && listRef.current?.contains(e.target)) return;
|
|
866
|
+
setState((st) => ({ ...st, open: false }));
|
|
867
|
+
};
|
|
868
|
+
window.addEventListener("scroll", close, true);
|
|
869
|
+
window.addEventListener("resize", close);
|
|
870
|
+
return () => {
|
|
871
|
+
window.removeEventListener("scroll", close, true);
|
|
872
|
+
window.removeEventListener("resize", close);
|
|
873
|
+
};
|
|
874
|
+
}, [state.open]);
|
|
848
875
|
const current = Math.max(0, props.options.findIndex(([v]) => v === props.value));
|
|
849
876
|
const choose = (i) => {
|
|
850
877
|
setState({ open: false, highlighted: i });
|
|
@@ -865,6 +892,7 @@ function Dropdown(props) {
|
|
|
865
892
|
/* @__PURE__ */ jsxs(
|
|
866
893
|
"button",
|
|
867
894
|
{
|
|
895
|
+
ref: btnRef,
|
|
868
896
|
type: "button",
|
|
869
897
|
class: "bas-dd__btn",
|
|
870
898
|
"data-testid": props.testid,
|
|
@@ -880,7 +908,7 @@ function Dropdown(props) {
|
|
|
880
908
|
]
|
|
881
909
|
}
|
|
882
910
|
),
|
|
883
|
-
state.open ? /* @__PURE__ */ jsx("ul", { class: "bas-dd__list", role: "listbox", "aria-label": props.label, "data-testid": `${props.testid}-list`, children: props.options.map(([v, label], i) => /* @__PURE__ */ jsxs(
|
|
911
|
+
state.open ? /* @__PURE__ */ jsx("ul", { ref: listRef, class: "bas-dd__list", style: pos ?? { position: "fixed", visibility: "hidden" }, role: "listbox", "aria-label": props.label, "data-testid": `${props.testid}-list`, children: props.options.map(([v, label], i) => /* @__PURE__ */ jsxs(
|
|
884
912
|
"li",
|
|
885
913
|
{
|
|
886
914
|
id: optId(v),
|