pixelize-design-library 3.3.1 → 3.3.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.
@@ -43,6 +43,15 @@ const truncateLabel = (label, max) => max !== undefined && label.length > max ?
43
43
  const asIdSet = (values) => new Set((values !== null && values !== void 0 ? values : []).map((v) => v.toString()));
44
44
  /** Regression-guarded id scheme — tickets e2e (`e2e/tests/helpers/selectV2.ts`) resolves it verbatim. */
45
45
  const optionDomId = (listboxId, id) => `${listboxId}-option-${id.toString().replace(/[^a-zA-Z0-9_-]/g, "-")}`;
46
+ // NOTE: a Drawer/Modal aria-hides sibling portals on open, which hid this popup's options too.
47
+ const unhideFromModal = (popup, trigger) => {
48
+ if (trigger.closest('[aria-hidden="true"]'))
49
+ return;
50
+ for (let node = popup.parentElement; node && !node.contains(trigger); node = node.parentElement) {
51
+ if (node.getAttribute("aria-hidden") === "true" && node.hasAttribute("data-aria-hidden"))
52
+ node.removeAttribute("aria-hidden");
53
+ }
54
+ };
46
55
  const parseRemToPx = (value, fallbackPx) => {
47
56
  const match = /^(\d*\.?\d+)rem$/.exec(value);
48
57
  return match ? parseFloat(match[1]) * 16 : fallbackPx;
@@ -52,7 +61,9 @@ const OptionRow = React.memo(function OptionRow({ option, index, listboxId, isSe
52
61
  const solidDisabledInk = option.isDisabled ? ink.disabled : null;
53
62
  const checkSlotPx = Math.max(CHECK_SLOT_MIN_PX, spec.iconSize);
54
63
  const checkSlot = (_jsx(Box, { as: "span", "aria-hidden": true, display: "inline-flex", justifyContent: "center", flexShrink: 0, width: `${checkSlotPx}px`, children: isSingleSelected ? _jsx(Box, { as: Check, size: spec.iconSize, color: theme.colors.accentText }) : null }));
55
- return (_jsxs(Box, { id: optionDomId(listboxId, option.id), "data-index": index, role: "option", "aria-selected": isSelected, "aria-disabled": option.isDisabled, onMouseEnter: () => onActivate(index), onClick: () => onSelect(option), mx: spec.mx, px: spec.px, py: spec.py, minH: spec.minH, borderRadius: "md", cursor: option.isDisabled ? "not-allowed" : "pointer", display: "flex", alignItems: "center", gap: spec.gap, fontSize: spec.fontSize, fontWeight: optionRowWeight(isSingleSelected), color: solidDisabledInk !== null && solidDisabledInk !== void 0 ? solidDisabledInk : (isSingleSelected ? ink.selected : ink.rest), bg: selectRowFill(backgrounds, { isSelected, isActive }), boxShadow: showRing ? keyboardRingShadow(backgrounds.keyboardRing) : undefined, transition: ROW_TRANSITION, sx: option.isDisabled && !ink.disabled ? { ...reducedMotionSx(), ...DISABLED_CONTENT_SX } : reducedMotionSx(), children: [!isMulti && checkPlacement === "start" ? checkSlot : null, isMulti ? (_jsx(Checkbox, { id: `${optionDomId(listboxId, option.id)}-checkbox`, isChecked: isSelected, isDisabled: option.isDisabled, pointerEvents: "none", tabIndex: -1, sx: DECORATIVE_CHECKBOX_SX })) : null, renderOption ? (_jsx(Box, { flex: 1, minW: 0, children: renderOption(option, { isSelected, isActive }) })) : (_jsxs(_Fragment, { children: [option.icon ? (_jsx(Box, { as: "span", display: "inline-flex", flexShrink: 0, children: option.icon })) : null, _jsxs(Box, { flex: 1, minW: 0, isTruncated: true, children: [_jsx(Box, { as: "span", isTruncated: true, children: option.label }), option.description ? (_jsx(Box, { as: "span", display: "block", fontSize: spec.descriptionFontSize, color: solidDisabledInk !== null && solidDisabledInk !== void 0 ? solidDisabledInk : ink.description, isTruncated: true, children: option.description })) : null] })] })), renderOptionEnd ? (_jsx(Box, { as: "span", display: "inline-flex", flexShrink: 0, children: renderOptionEnd(option, { isSelected, isActive }) })) : null, optionAction ? (_jsx(Box, { as: "span", "aria-hidden": true, title: optionAction.label, onMouseDown: (event) => event.preventDefault(), onClick: (event) => {
64
+ const rowId = optionDomId(listboxId, option.id);
65
+ const hasOwnText = !renderOption;
66
+ return (_jsxs(Box, { id: rowId, "data-index": index, role: "option", "aria-labelledby": hasOwnText ? `${rowId}-label` : undefined, "aria-describedby": hasOwnText && option.description ? `${rowId}-description` : undefined, "aria-selected": isSelected, "aria-disabled": option.isDisabled, onMouseEnter: () => onActivate(index), onClick: () => onSelect(option), mx: spec.mx, px: spec.px, py: spec.py, minH: spec.minH, borderRadius: "md", cursor: option.isDisabled ? "not-allowed" : "pointer", display: "flex", alignItems: "center", gap: spec.gap, fontSize: spec.fontSize, fontWeight: optionRowWeight(isSingleSelected), color: solidDisabledInk !== null && solidDisabledInk !== void 0 ? solidDisabledInk : (isSingleSelected ? ink.selected : ink.rest), bg: selectRowFill(backgrounds, { isSelected, isActive }), boxShadow: showRing ? keyboardRingShadow(backgrounds.keyboardRing) : undefined, transition: ROW_TRANSITION, sx: option.isDisabled && !ink.disabled ? { ...reducedMotionSx(), ...DISABLED_CONTENT_SX } : reducedMotionSx(), children: [!isMulti && checkPlacement === "start" ? checkSlot : null, isMulti ? (_jsx(Checkbox, { id: `${rowId}-checkbox`, isChecked: isSelected, isDisabled: option.isDisabled, pointerEvents: "none", tabIndex: -1, sx: DECORATIVE_CHECKBOX_SX })) : null, renderOption ? (_jsx(Box, { flex: 1, minW: 0, children: renderOption(option, { isSelected, isActive }) })) : (_jsxs(_Fragment, { children: [option.icon ? (_jsx(Box, { as: "span", display: "inline-flex", flexShrink: 0, children: option.icon })) : null, _jsxs(Box, { flex: 1, minW: 0, isTruncated: true, children: [_jsx(Box, { as: "span", id: `${rowId}-label`, isTruncated: true, children: option.label }), option.description ? (_jsx(Box, { as: "span", id: `${rowId}-description`, display: "block", fontSize: spec.descriptionFontSize, color: solidDisabledInk !== null && solidDisabledInk !== void 0 ? solidDisabledInk : ink.description, isTruncated: true, children: option.description })) : null] })] })), renderOptionEnd ? (_jsx(Box, { as: "span", display: "inline-flex", flexShrink: 0, children: renderOptionEnd(option, { isSelected, isActive }) })) : null, optionAction ? (_jsx(Box, { as: "span", "aria-hidden": true, title: optionAction.label, onMouseDown: (event) => event.preventDefault(), onClick: (event) => {
56
67
  event.stopPropagation();
57
68
  optionAction.onAction(option);
58
69
  }, display: "inline-flex", alignItems: "center", justifyContent: "center", flexShrink: 0, cursor: "pointer", color: ink.description, _hover: { color: ink.selected }, children: optionAction.icon })) : null, !isMulti && checkPlacement === "end" ? checkSlot : null] }));
@@ -134,7 +145,7 @@ const SelectPopup = forwardRef(function SelectPopup(props, ref) {
134
145
  const handleOpen = () => {
135
146
  if (!isInteractive)
136
147
  return;
137
- requestExclusiveOpen();
148
+ requestExclusiveOpen(triggerRef.current);
138
149
  onFocus === null || onFocus === void 0 ? void 0 : onFocus();
139
150
  onOpen();
140
151
  const firstSelected = props.isMulti
@@ -224,6 +235,17 @@ const SelectPopup = forwardRef(function SelectPopup(props, ref) {
224
235
  return;
225
236
  setTriggerWidth(node.getBoundingClientRect().width);
226
237
  }, [isOpen]);
238
+ useEffect(() => {
239
+ if (!isOpen)
240
+ return;
241
+ const reveal = () => {
242
+ if (listRef.current && triggerRef.current)
243
+ unhideFromModal(listRef.current, triggerRef.current);
244
+ };
245
+ reveal();
246
+ const frame = requestAnimationFrame(reveal);
247
+ return () => cancelAnimationFrame(frame);
248
+ }, [isOpen]);
227
249
  useEffect(() => {
228
250
  if (!isOpen || !isSearchable)
229
251
  return;
@@ -1,16 +1,21 @@
1
- let active = null;
2
- export const exclusiveOpen = (id, close) => {
3
- if (active && active.id !== id) {
4
- active.close();
1
+ let stack = [];
2
+ export const exclusiveOpen = (id, close, options = {}) => {
3
+ var _a;
4
+ stack = stack.filter((entry) => entry.id !== id);
5
+ const { anchor } = options;
6
+ while (stack.length > 0) {
7
+ const top = stack[stack.length - 1];
8
+ if (anchor && ((_a = top.contains) === null || _a === void 0 ? void 0 : _a.call(top, anchor)))
9
+ break;
10
+ stack.pop();
11
+ top.close();
5
12
  }
6
- active = { id, close };
13
+ stack.push({ id, close, contains: options.contains });
7
14
  };
8
15
  export const exclusiveClose = (id) => {
9
- if ((active === null || active === void 0 ? void 0 : active.id) === id) {
10
- active = null;
11
- }
16
+ stack = stack.filter((entry) => entry.id !== id);
12
17
  };
13
18
  /** Test-only reset — not exported from the package root. */
14
19
  export const resetExclusiveOverlay = () => {
15
- active = null;
20
+ stack = [];
16
21
  };
@@ -1,13 +1,16 @@
1
1
  import { useCallback, useEffect, useId, useRef } from "react";
2
2
  import { exclusiveClose, exclusiveOpen } from "./exclusiveOverlay.js";
3
3
  // NOTE: registers with the global dismiss coordinator — call requestOpen() before opening.
4
- export const useExclusiveOverlay = (isOpen, onClose) => {
4
+ export const useExclusiveOverlay = (isOpen, onClose, contentRef) => {
5
5
  const id = useId();
6
6
  const onCloseRef = useRef(onClose);
7
7
  onCloseRef.current = onClose;
8
- const requestOpen = useCallback(() => {
9
- exclusiveOpen(id, () => onCloseRef.current());
10
- }, [id]);
8
+ const requestOpen = useCallback((anchor) => {
9
+ exclusiveOpen(id, () => onCloseRef.current(), {
10
+ anchor,
11
+ contains: contentRef ? (node) => { var _a; return Boolean((_a = contentRef.current) === null || _a === void 0 ? void 0 : _a.contains(node)); } : undefined,
12
+ });
13
+ }, [id, contentRef]);
11
14
  useEffect(() => {
12
15
  if (!isOpen) {
13
16
  exclusiveClose(id);
@@ -1,4 +1,17 @@
1
1
  import { useEffect, useRef } from "react";
2
+ const ownedIds = (root) => Array.from(root.querySelectorAll("[aria-controls], [aria-owns]")).flatMap((el) => { var _a, _b; return `${(_a = el.getAttribute("aria-controls")) !== null && _a !== void 0 ? _a : ""} ${(_b = el.getAttribute("aria-owns")) !== null && _b !== void 0 ? _b : ""}`.split(/\s+/).filter(Boolean); });
3
+ const ownsTarget = (root, target) => {
4
+ if (!root)
5
+ return false;
6
+ const ids = ownedIds(root);
7
+ if (ids.length === 0)
8
+ return false;
9
+ for (let node = target instanceof Element ? target : target.parentElement; node; node = node.parentElement) {
10
+ if (node.id && ids.includes(node.id))
11
+ return true;
12
+ }
13
+ return false;
14
+ };
2
15
  /** Calls `onOutside` for a document `mousedown` outside every ref; a null ref contains nothing. Unlike Chakra's `useOutsideClick` it never waits for `mouseup`. */
3
16
  export const useOutsideMouseDown = (refs, onOutside, { enabled = true, capture = false, includeClick = false } = {}) => {
4
17
  const latest = useRef({ refs, onOutside });
@@ -10,7 +23,9 @@ export const useOutsideMouseDown = (refs, onOutside, { enabled = true, capture =
10
23
  return;
11
24
  const handle = (event) => {
12
25
  const target = event.target;
13
- if (latest.current.refs.some((ref) => { var _a; return (_a = ref.current) === null || _a === void 0 ? void 0 : _a.contains(target); }))
26
+ if (!target.isConnected)
27
+ return;
28
+ if (latest.current.refs.some((ref) => { var _a; return ((_a = ref.current) === null || _a === void 0 ? void 0 : _a.contains(target)) || ownsTarget(ref.current, target); }))
14
29
  return;
15
30
  latest.current.onOutside(event);
16
31
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pixelize-design-library",
3
- "version": "3.3.1",
3
+ "version": "3.3.3",
4
4
  "description": "React component library for Pixelize apps: themeable Chakra-based components, design tokens and light/dark brand theming.",
5
5
  "keywords": [
6
6
  "react",