@dloizides/ui-layout 1.6.0 → 1.7.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/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.7.1
4
+
5
+ Fix: the modal-variant dismiss backdrop was a pressable WRAPPING the option buttons,
6
+ producing invalid DOM on web ("<button> cannot contain a nested <button>") + a React
7
+ console.error. The backdrop is now an absolute-fill SIBLING behind the dialog — same
8
+ tap-to-dismiss behaviour, no nesting. No API change.
9
+
10
+
11
+ ## 1.7.0
12
+
13
+ - **`ModalDropdown` inline-menu (`variant={DropdownVariant.Menu}`) z-index / clipping fix.** On
14
+ wide/desktop web the open inline menu painted UNDERNEATH later content (adjacent filter fields,
15
+ the results table, cards) so options were hidden/clipped. Root cause: react-native-web renders
16
+ **every `View`** with `position: relative; z-index: 0`, making each View its own stacking context —
17
+ so the popover's `zIndex: 1000` was trapped inside its anchor / the app's field wrapper and could
18
+ never rise above later-painting siblings.
19
+ - **Fix:** on web the menu is now rendered in a **portal to `document.body`** with `position: fixed`
20
+ at the trigger's measured viewport rect (recomputed on scroll/resize) and a high `zIndex`. A portal
21
+ escapes every ancestor stacking context AND every ancestor `overflow: hidden`, so the menu always
22
+ paints on top and is never clipped — the same "menu above the table" outcome as
23
+ `@dloizides/ui-tables` `SizeDropdown`. The anchor wrapper is also lifted to a raised `zIndex` while
24
+ open (defence-in-depth; the primary lift on native).
25
+ - **Native-safe:** the portal + `document`/`window` listeners are all behind `Platform.OS === 'web'`;
26
+ native keeps the in-tree `position:absolute` popover + `elevation`. `react-dom` is added as an
27
+ **optional** peer (already present in every react-native-web consumer).
28
+ - Outside-click dismissal now consults the portalled popover's own node too, so clicking an option
29
+ still selects (a portalled option is no longer a DOM descendant of the anchor). Keyboard nav
30
+ (↑/↓, Home/End, Enter, Escape), `role="menu"`/`menuitem`, `aria-expanded`/`aria-selected`, and the
31
+ modal variant on narrow/native are all unchanged.
32
+ - **Additive / backward-compatible:** the `ModalDropdown` API is unchanged; erevna / katalogos / kefi
33
+ are unaffected.
34
+
3
35
  ## 1.6.0
4
36
 
5
37
  - **Accessibility (WCAG 2.1 AA) hardening — additive + backward-compatible.**
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ var React8 = require('react');
4
4
  var reactNative = require('react-native');
5
5
  var uiFeedback = require('@dloizides/ui-feedback');
6
6
  var jsxRuntime = require('react/jsx-runtime');
7
+ var reactDom = require('react-dom');
7
8
  var uiIcons = require('@dloizides/ui-icons');
8
9
 
9
10
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -311,6 +312,37 @@ var DropdownVariant = /* @__PURE__ */ ((DropdownVariant2) => {
311
312
  DropdownVariant2["Modal"] = "modal";
312
313
  return DropdownVariant2;
313
314
  })(DropdownVariant || {});
315
+
316
+ // src/ModalDropdown/menuStacking.ts
317
+ var MENU_Z_INDEX = 1e3;
318
+ var ANCHOR_OPEN_Z_INDEX = 1e3;
319
+ var MENU_ELEVATION = 8;
320
+ var MENU_TOP_GAP = 4;
321
+ var MENU_MAX_HEIGHT = 300;
322
+ var BORDER_RADIUS = 8;
323
+ var BORDER_WIDTH2 = 1;
324
+ var MENU_PADDING = 4;
325
+ var MENU_BOX_SHADOW = "0px 2px 8px rgba(0, 0, 0, 0.15)";
326
+ function buildPortalPopoverStyle(rect) {
327
+ return {
328
+ // RN's ViewStyle union omits 'fixed', but react-native-web honours it at runtime.
329
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- web-only position value
330
+ position: "fixed",
331
+ top: rect.bottom + MENU_TOP_GAP,
332
+ left: rect.left,
333
+ width: rect.width,
334
+ zIndex: MENU_Z_INDEX,
335
+ borderWidth: BORDER_WIDTH2,
336
+ borderRadius: BORDER_RADIUS,
337
+ padding: MENU_PADDING,
338
+ maxHeight: MENU_MAX_HEIGHT,
339
+ boxShadow: MENU_BOX_SHADOW,
340
+ elevation: MENU_ELEVATION
341
+ };
342
+ }
343
+ function buildAnchorStackStyle(isMenuOpen) {
344
+ return isMenuOpen ? { zIndex: ANCHOR_OPEN_Z_INDEX, elevation: MENU_ELEVATION } : null;
345
+ }
314
346
  var OPTION_BORDER_RADIUS = 4;
315
347
  var BODY_FONT_SIZE = 14;
316
348
  var SELECTED_FONT_WEIGHT = "600";
@@ -355,6 +387,11 @@ var OptionRow = ({
355
387
  }
356
388
  );
357
389
  };
390
+ function refContains(ref, target) {
391
+ if (ref === void 0) return false;
392
+ const node = ref.current;
393
+ return node !== null && target !== null && node.contains(target);
394
+ }
358
395
  var clampIndex = (index, itemCount) => {
359
396
  if (index < 0) return 0;
360
397
  const lastIndex = itemCount - 1;
@@ -392,15 +429,15 @@ function buildKeyHandler(params) {
392
429
  };
393
430
  }
394
431
  function useMenuKeyboard(params) {
395
- const { containerRef, enabled, onClose } = params;
432
+ const { containerRef, menuRef, enabled, onClose } = params;
396
433
  React8.useEffect(() => {
397
434
  if (reactNative.Platform.OS !== "web" || !enabled) return;
398
435
  const onKeyDown = buildKeyHandler(params);
399
436
  const onMouseDown = (event) => {
400
- const node = containerRef.current;
401
437
  const target = event.target instanceof Node ? event.target : null;
402
- const clickedOutside = node !== null && (target === null || !node.contains(target));
403
- if (clickedOutside) onClose();
438
+ const insideAnchor = refContains(containerRef, target);
439
+ const insideMenu = refContains(menuRef, target);
440
+ if (!insideAnchor && !insideMenu) onClose();
404
441
  };
405
442
  document.addEventListener("keydown", onKeyDown);
406
443
  document.addEventListener("mousedown", onMouseDown);
@@ -408,17 +445,14 @@ function useMenuKeyboard(params) {
408
445
  document.removeEventListener("keydown", onKeyDown);
409
446
  document.removeEventListener("mousedown", onMouseDown);
410
447
  };
411
- }, [containerRef, enabled, onClose, params]);
448
+ }, [containerRef, menuRef, enabled, onClose, params]);
412
449
  }
413
- var BORDER_RADIUS = 8;
414
- var BORDER_WIDTH2 = 1;
415
- var MENU_PADDING = 4;
416
- var MENU_MAX_HEIGHT = 300;
417
- var MENU_TOP_GAP = 4;
418
- var MENU_Z_INDEX = 1e3;
419
- var MENU_ELEVATION = 8;
420
- var MENU_BOX_SHADOW = "0px 2px 8px rgba(0, 0, 0, 0.15)";
450
+ var IS_WEB = reactNative.Platform.OS === "web";
451
+ var BORDER_RADIUS2 = 8;
452
+ var BORDER_WIDTH3 = 1;
453
+ var MENU_PADDING2 = 4;
421
454
  var styles7 = reactNative.StyleSheet.create({
455
+ /** Native (in-tree) popover — anchored absolutely just under the trigger. */
422
456
  popover: {
423
457
  position: "absolute",
424
458
  top: "100%",
@@ -426,14 +460,38 @@ var styles7 = reactNative.StyleSheet.create({
426
460
  right: 0,
427
461
  marginTop: MENU_TOP_GAP,
428
462
  zIndex: MENU_Z_INDEX,
429
- borderWidth: BORDER_WIDTH2,
430
- borderRadius: BORDER_RADIUS,
431
- padding: MENU_PADDING,
463
+ borderWidth: BORDER_WIDTH3,
464
+ borderRadius: BORDER_RADIUS2,
465
+ padding: MENU_PADDING2,
432
466
  maxHeight: MENU_MAX_HEIGHT,
433
467
  boxShadow: MENU_BOX_SHADOW,
434
468
  elevation: MENU_ELEVATION
435
469
  }
436
470
  });
471
+ function readAnchorRect(containerRef) {
472
+ if (!IS_WEB) return null;
473
+ const node = containerRef.current;
474
+ if (node === null || typeof node.getBoundingClientRect !== "function") return null;
475
+ const r = node.getBoundingClientRect();
476
+ return { top: r.top, left: r.left, width: r.width, bottom: r.bottom };
477
+ }
478
+ function useAnchorRect(containerRef) {
479
+ const [rect, setRect] = React8.useState(() => readAnchorRect(containerRef));
480
+ React8.useLayoutEffect(() => {
481
+ if (!IS_WEB) return void 0;
482
+ const measure = () => {
483
+ setRect(readAnchorRect(containerRef));
484
+ };
485
+ measure();
486
+ window.addEventListener("scroll", measure, true);
487
+ window.addEventListener("resize", measure);
488
+ return () => {
489
+ window.removeEventListener("scroll", measure, true);
490
+ window.removeEventListener("resize", measure);
491
+ };
492
+ }, [containerRef]);
493
+ return rect;
494
+ }
437
495
  var InlineMenu = ({
438
496
  testID,
439
497
  accessibilityLabel,
@@ -445,6 +503,8 @@ var InlineMenu = ({
445
503
  }) => {
446
504
  const { theme } = uiFeedback.useUi();
447
505
  const { colors } = theme;
506
+ const menuRef = React8.useRef(null);
507
+ const rect = useAnchorRect(containerRef);
448
508
  const selectedIndex = React8.useMemo(
449
509
  () => Math.max(0, options.findIndex((opt) => opt.value === value)),
450
510
  [options, value]
@@ -465,19 +525,22 @@ var InlineMenu = ({
465
525
  );
466
526
  useMenuKeyboard({
467
527
  containerRef,
528
+ menuRef,
468
529
  enabled: true,
469
530
  itemCount: options.length,
470
531
  onHighlightChange: setHighlightedIndex,
471
532
  onSelectHighlighted: selectHighlighted,
472
533
  onClose
473
534
  });
474
- const popoverStyle = React8.useMemo(
475
- () => [styles7.popover, { borderColor: colors.border, backgroundColor: colors.surface }],
476
- [colors.border, colors.surface]
477
- );
478
- return /* @__PURE__ */ jsxRuntime.jsx(
535
+ const popoverStyle = React8.useMemo(() => {
536
+ const themed = { borderColor: colors.border, backgroundColor: colors.surface };
537
+ if (IS_WEB) return [buildPortalPopoverStyle(rect ?? { left: 0, width: 0, bottom: 0 }), themed];
538
+ return [styles7.popover, themed];
539
+ }, [colors.border, colors.surface, rect]);
540
+ const menu = /* @__PURE__ */ jsxRuntime.jsx(
479
541
  reactNative.View,
480
542
  {
543
+ ref: menuRef,
481
544
  accessibilityRole: "menu",
482
545
  "aria-label": accessibilityLabel,
483
546
  style: popoverStyle,
@@ -495,6 +558,8 @@ var InlineMenu = ({
495
558
  )) })
496
559
  }
497
560
  );
561
+ if (IS_WEB) return reactDom.createPortal(menu, document.body);
562
+ return menu;
498
563
  };
499
564
  var MENU_BREAKPOINT = 768;
500
565
  var WEB_PLATFORM = "web";
@@ -507,8 +572,8 @@ function useResolvedDropdownVariant(explicit) {
507
572
  const { width } = reactNative.useWindowDimensions();
508
573
  return resolveDropdownVariant(explicit, width, reactNative.Platform.OS);
509
574
  }
510
- var BORDER_RADIUS2 = 8;
511
- var BORDER_WIDTH3 = 1;
575
+ var BORDER_RADIUS3 = 8;
576
+ var BORDER_WIDTH4 = 1;
512
577
  var BODY_FONT_SIZE2 = 14;
513
578
  var MODAL_PADDING = 8;
514
579
  var MODAL_MIN_WIDTH = 200;
@@ -518,8 +583,8 @@ var CONTAINER_PADDING_V = 10;
518
583
  var styles8 = reactNative.StyleSheet.create({
519
584
  anchor: { position: "relative" },
520
585
  container: {
521
- borderWidth: BORDER_WIDTH3,
522
- borderRadius: BORDER_RADIUS2,
586
+ borderWidth: BORDER_WIDTH4,
587
+ borderRadius: BORDER_RADIUS3,
523
588
  paddingHorizontal: CONTAINER_PADDING_H,
524
589
  paddingVertical: CONTAINER_PADDING_V
525
590
  },
@@ -531,7 +596,7 @@ var styles8 = reactNative.StyleSheet.create({
531
596
  backgroundColor: uiFeedback.MODAL_OVERLAY_COLOR
532
597
  },
533
598
  modalContent: {
534
- borderRadius: BORDER_RADIUS2,
599
+ borderRadius: BORDER_RADIUS3,
535
600
  padding: MODAL_PADDING,
536
601
  minWidth: MODAL_MIN_WIDTH,
537
602
  maxHeight: MODAL_MAX_HEIGHT
@@ -575,6 +640,10 @@ var ModalDropdown = ({
575
640
  () => [styles8.container, { borderColor: colors.border, backgroundColor: colors.surface }],
576
641
  [colors.border, colors.surface]
577
642
  );
643
+ const anchorStyle = React8.useMemo(
644
+ () => [styles8.anchor, buildAnchorStackStyle(isMenu && isOpen)],
645
+ [isMenu, isOpen]
646
+ );
578
647
  const modalContentStyle = React8.useMemo(
579
648
  () => [styles8.modalContent, { backgroundColor: colors.surface }],
580
649
  [colors.surface]
@@ -592,7 +661,7 @@ var ModalDropdown = ({
592
661
  [handleSelect, testID, value]
593
662
  );
594
663
  const keyExtractor = React8.useCallback((item) => String(item.value), []);
595
- return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { ref: anchorRef, style: styles8.anchor, children: [
664
+ return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { ref: anchorRef, style: anchorStyle, children: [
596
665
  /* @__PURE__ */ jsxRuntime.jsx(
597
666
  reactNative.TouchableOpacity,
598
667
  {
@@ -620,30 +689,32 @@ var ModalDropdown = ({
620
689
  onSelect: handleSelect
621
690
  }
622
691
  ) : null,
623
- !isMenu ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Modal, { transparent: true, animationType: "fade", visible: isOpen, onRequestClose: handleClose, children: /* @__PURE__ */ jsxRuntime.jsx(
624
- reactNative.TouchableOpacity,
625
- {
626
- accessible: true,
627
- accessibilityHint: t("common.dismissDropdownHint"),
628
- accessibilityLabel: t("common.dismissDropdown"),
629
- accessibilityRole: "button",
630
- activeOpacity: 1,
631
- style: styles8.modalOverlay,
632
- testID: `${testID}-backdrop`,
633
- onPress: handleClose,
634
- children: /* @__PURE__ */ jsxRuntime.jsx(
635
- reactNative.View,
636
- {
637
- ref: dialogRef,
638
- accessibilityViewIsModal: true,
639
- "aria-label": accessibilityLabel,
640
- role: "dialog",
641
- style: modalContentStyle,
642
- children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.FlatList, { data: [...options], keyExtractor, renderItem: renderModalOption })
643
- }
644
- )
645
- }
646
- ) }) : null
692
+ !isMenu ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Modal, { transparent: true, animationType: "fade", visible: isOpen, onRequestClose: handleClose, children: /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: styles8.modalOverlay, children: [
693
+ /* @__PURE__ */ jsxRuntime.jsx(
694
+ reactNative.TouchableOpacity,
695
+ {
696
+ accessible: true,
697
+ accessibilityHint: t("common.dismissDropdownHint"),
698
+ accessibilityLabel: t("common.dismissDropdown"),
699
+ accessibilityRole: "button",
700
+ activeOpacity: 1,
701
+ style: reactNative.StyleSheet.absoluteFill,
702
+ testID: `${testID}-backdrop`,
703
+ onPress: handleClose
704
+ }
705
+ ),
706
+ /* @__PURE__ */ jsxRuntime.jsx(
707
+ reactNative.View,
708
+ {
709
+ ref: dialogRef,
710
+ accessibilityViewIsModal: true,
711
+ "aria-label": accessibilityLabel,
712
+ role: "dialog",
713
+ style: modalContentStyle,
714
+ children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.FlatList, { data: [...options], keyExtractor, renderItem: renderModalOption })
715
+ }
716
+ )
717
+ ] }) }) : null
647
718
  ] });
648
719
  };
649
720
  var CLOSE_ICON_SIZE = 18;