@dloizides/ui-layout 1.23.0 → 1.25.0

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,24 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.24.0
4
+
5
+ **The inline dropdown popover now stays inside the viewport — a floored menu can no longer spill off the right edge.**
6
+
7
+ `buildPortalPopoverStyle` positioned the fixed popover at `left: rect.left` with no horizontal
8
+ clamp. That was fine while the menu matched its trigger's width, but a COMPACT trigger with a
9
+ `menuMinWidth` floor (e.g. the `@dloizides/ui-nav` "More ▾" overflow menu, whose trigger sits near
10
+ the right of the bar) opens a menu WIDER than its trigger — which then extended past the right edge
11
+ of the viewport and clipped its lower/right content ("some items get hidden").
12
+
13
+ - **`buildPortalPopoverStyle(rect, minWidth, viewportWidth?)`** takes an optional `viewportWidth`.
14
+ When given, the popover's `left` is clamped so its right edge clears `MENU_VIEWPORT_MARGIN` (8px) —
15
+ sliding it left, right-aligning it to the trigger in the limit — while never crossing the left
16
+ margin. `viewportWidth = 0` (the default, and the native/pure path) keeps the exact prior
17
+ trigger-anchored behaviour, so every existing caller is unchanged.
18
+ - **`InlineMenu`** passes `window.innerWidth` on web (re-read whenever the tracked trigger rect
19
+ re-measures on scroll/resize); native is untouched.
20
+ - New export `MENU_VIEWPORT_MARGIN`.
21
+
3
22
  ## 1.23.0
4
23
 
5
24
  **Modals, the dropdown popover and the accordion body now ANIMATE on web — adopts `@dloizides/ui-motion`.**
package/dist/index.js CHANGED
@@ -327,15 +327,23 @@ var MENU_MAX_HEIGHT = 300;
327
327
  var BORDER_RADIUS = 8;
328
328
  var BORDER_WIDTH2 = 1;
329
329
  var MENU_PADDING = 4;
330
+ var MENU_SCROLL_MAX_HEIGHT = MENU_MAX_HEIGHT - (BORDER_WIDTH2 + MENU_PADDING) * 2;
330
331
  var MENU_BOX_SHADOW = "0px 2px 8px rgba(0, 0, 0, 0.15)";
331
- function buildPortalPopoverStyle(rect, minWidth = 0) {
332
+ var MENU_VIEWPORT_MARGIN = 8;
333
+ function buildPortalPopoverStyle(rect, minWidth = 0, viewportWidth = 0) {
334
+ const width = Math.max(rect.width, minWidth);
335
+ let left = rect.left;
336
+ if (viewportWidth > 0) {
337
+ const maxLeft = viewportWidth - width - MENU_VIEWPORT_MARGIN;
338
+ left = Math.max(MENU_VIEWPORT_MARGIN, Math.min(rect.left, maxLeft));
339
+ }
332
340
  return {
333
341
  // RN's ViewStyle union omits 'fixed', but react-native-web honours it at runtime.
334
342
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- web-only position value
335
343
  position: "fixed",
336
344
  top: rect.bottom + MENU_TOP_GAP,
337
- left: rect.left,
338
- width: Math.max(rect.width, minWidth),
345
+ left,
346
+ width,
339
347
  zIndex: MENU_Z_INDEX,
340
348
  borderWidth: BORDER_WIDTH2,
341
349
  borderRadius: BORDER_RADIUS,
@@ -569,7 +577,10 @@ var styles6 = reactNative.StyleSheet.create({
569
577
  // The enter/exit fade+scale lives on an INNER wrapper so the outer popover keeps its raw DOM
570
578
  // node (the `menuRef` outside-click / keyboard logic and the web portal target depend on it).
571
579
  // `transformOrigin: 'top'` makes the scale grow downward FROM the anchor rather than the centre.
572
- animated: { transformOrigin: "top" }
580
+ animated: { transformOrigin: "top" },
581
+ // Bound the scroll viewport so a list longer than the popover scrolls (with a scrollbar) instead of
582
+ // overflowing the frame — the popover's own maxHeight cannot do this (see MENU_SCROLL_MAX_HEIGHT).
583
+ scroll: { maxHeight: MENU_SCROLL_MAX_HEIGHT }
573
584
  });
574
585
  var InlineMenu = ({
575
586
  testID,
@@ -616,11 +627,13 @@ var InlineMenu = ({
616
627
  });
617
628
  const popoverStyle = React10.useMemo(() => {
618
629
  const themed = { borderColor: colors.border, backgroundColor: colors.surface };
619
- if (IS_WEB2)
630
+ if (IS_WEB2) {
631
+ const viewportWidth = typeof window !== "undefined" ? window.innerWidth : 0;
620
632
  return [
621
- buildPortalPopoverStyle(rect ?? { left: 0, width: 0, bottom: 0 }, menuMinWidth),
633
+ buildPortalPopoverStyle(rect ?? { left: 0, width: 0, bottom: 0 }, menuMinWidth, viewportWidth),
622
634
  themed
623
635
  ];
636
+ }
624
637
  return [styles6.popover, { minWidth: menuMinWidth }, themed];
625
638
  }, [colors.border, colors.surface, menuMinWidth, rect]);
626
639
  const menu = /* @__PURE__ */ jsxRuntime.jsx(
@@ -631,7 +644,7 @@ var InlineMenu = ({
631
644
  "aria-label": accessibilityLabel,
632
645
  style: popoverStyle,
633
646
  testID: `${testID}-menu`,
634
- children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Animated.View, { style: [styles6.animated, animatedStyle], children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.ScrollView, { keyboardShouldPersistTaps: "handled", children: options.map((option, index) => /* @__PURE__ */ jsxRuntime.jsx(
647
+ children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Animated.View, { style: [styles6.animated, animatedStyle], children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.ScrollView, { style: styles6.scroll, keyboardShouldPersistTaps: "handled", children: options.map((option, index) => /* @__PURE__ */ jsxRuntime.jsx(
635
648
  OptionRow,
636
649
  {
637
650
  isHighlighted: index === highlightedIndex,