@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/dist/index.mjs CHANGED
@@ -321,15 +321,23 @@ var MENU_MAX_HEIGHT = 300;
321
321
  var BORDER_RADIUS = 8;
322
322
  var BORDER_WIDTH2 = 1;
323
323
  var MENU_PADDING = 4;
324
+ var MENU_SCROLL_MAX_HEIGHT = MENU_MAX_HEIGHT - (BORDER_WIDTH2 + MENU_PADDING) * 2;
324
325
  var MENU_BOX_SHADOW = "0px 2px 8px rgba(0, 0, 0, 0.15)";
325
- function buildPortalPopoverStyle(rect, minWidth = 0) {
326
+ var MENU_VIEWPORT_MARGIN = 8;
327
+ function buildPortalPopoverStyle(rect, minWidth = 0, viewportWidth = 0) {
328
+ const width = Math.max(rect.width, minWidth);
329
+ let left = rect.left;
330
+ if (viewportWidth > 0) {
331
+ const maxLeft = viewportWidth - width - MENU_VIEWPORT_MARGIN;
332
+ left = Math.max(MENU_VIEWPORT_MARGIN, Math.min(rect.left, maxLeft));
333
+ }
326
334
  return {
327
335
  // RN's ViewStyle union omits 'fixed', but react-native-web honours it at runtime.
328
336
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- web-only position value
329
337
  position: "fixed",
330
338
  top: rect.bottom + MENU_TOP_GAP,
331
- left: rect.left,
332
- width: Math.max(rect.width, minWidth),
339
+ left,
340
+ width,
333
341
  zIndex: MENU_Z_INDEX,
334
342
  borderWidth: BORDER_WIDTH2,
335
343
  borderRadius: BORDER_RADIUS,
@@ -563,7 +571,10 @@ var styles6 = StyleSheet.create({
563
571
  // The enter/exit fade+scale lives on an INNER wrapper so the outer popover keeps its raw DOM
564
572
  // node (the `menuRef` outside-click / keyboard logic and the web portal target depend on it).
565
573
  // `transformOrigin: 'top'` makes the scale grow downward FROM the anchor rather than the centre.
566
- animated: { transformOrigin: "top" }
574
+ animated: { transformOrigin: "top" },
575
+ // Bound the scroll viewport so a list longer than the popover scrolls (with a scrollbar) instead of
576
+ // overflowing the frame — the popover's own maxHeight cannot do this (see MENU_SCROLL_MAX_HEIGHT).
577
+ scroll: { maxHeight: MENU_SCROLL_MAX_HEIGHT }
567
578
  });
568
579
  var InlineMenu = ({
569
580
  testID,
@@ -610,11 +621,13 @@ var InlineMenu = ({
610
621
  });
611
622
  const popoverStyle = useMemo(() => {
612
623
  const themed = { borderColor: colors.border, backgroundColor: colors.surface };
613
- if (IS_WEB2)
624
+ if (IS_WEB2) {
625
+ const viewportWidth = typeof window !== "undefined" ? window.innerWidth : 0;
614
626
  return [
615
- buildPortalPopoverStyle(rect ?? { left: 0, width: 0, bottom: 0 }, menuMinWidth),
627
+ buildPortalPopoverStyle(rect ?? { left: 0, width: 0, bottom: 0 }, menuMinWidth, viewportWidth),
616
628
  themed
617
629
  ];
630
+ }
618
631
  return [styles6.popover, { minWidth: menuMinWidth }, themed];
619
632
  }, [colors.border, colors.surface, menuMinWidth, rect]);
620
633
  const menu = /* @__PURE__ */ jsx(
@@ -625,7 +638,7 @@ var InlineMenu = ({
625
638
  "aria-label": accessibilityLabel,
626
639
  style: popoverStyle,
627
640
  testID: `${testID}-menu`,
628
- children: /* @__PURE__ */ jsx(Animated.View, { style: [styles6.animated, animatedStyle], children: /* @__PURE__ */ jsx(ScrollView, { keyboardShouldPersistTaps: "handled", children: options.map((option, index) => /* @__PURE__ */ jsx(
641
+ children: /* @__PURE__ */ jsx(Animated.View, { style: [styles6.animated, animatedStyle], children: /* @__PURE__ */ jsx(ScrollView, { style: styles6.scroll, keyboardShouldPersistTaps: "handled", children: options.map((option, index) => /* @__PURE__ */ jsx(
629
642
  OptionRow,
630
643
  {
631
644
  isHighlighted: index === highlightedIndex,