@dloizides/ui-layout 1.23.0 → 1.24.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
@@ -322,14 +322,21 @@ var BORDER_RADIUS = 8;
322
322
  var BORDER_WIDTH2 = 1;
323
323
  var MENU_PADDING = 4;
324
324
  var MENU_BOX_SHADOW = "0px 2px 8px rgba(0, 0, 0, 0.15)";
325
- function buildPortalPopoverStyle(rect, minWidth = 0) {
325
+ var MENU_VIEWPORT_MARGIN = 8;
326
+ function buildPortalPopoverStyle(rect, minWidth = 0, viewportWidth = 0) {
327
+ const width = Math.max(rect.width, minWidth);
328
+ let left = rect.left;
329
+ if (viewportWidth > 0) {
330
+ const maxLeft = viewportWidth - width - MENU_VIEWPORT_MARGIN;
331
+ left = Math.max(MENU_VIEWPORT_MARGIN, Math.min(rect.left, maxLeft));
332
+ }
326
333
  return {
327
334
  // RN's ViewStyle union omits 'fixed', but react-native-web honours it at runtime.
328
335
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- web-only position value
329
336
  position: "fixed",
330
337
  top: rect.bottom + MENU_TOP_GAP,
331
- left: rect.left,
332
- width: Math.max(rect.width, minWidth),
338
+ left,
339
+ width,
333
340
  zIndex: MENU_Z_INDEX,
334
341
  borderWidth: BORDER_WIDTH2,
335
342
  borderRadius: BORDER_RADIUS,
@@ -610,11 +617,13 @@ var InlineMenu = ({
610
617
  });
611
618
  const popoverStyle = useMemo(() => {
612
619
  const themed = { borderColor: colors.border, backgroundColor: colors.surface };
613
- if (IS_WEB2)
620
+ if (IS_WEB2) {
621
+ const viewportWidth = typeof window !== "undefined" ? window.innerWidth : 0;
614
622
  return [
615
- buildPortalPopoverStyle(rect ?? { left: 0, width: 0, bottom: 0 }, menuMinWidth),
623
+ buildPortalPopoverStyle(rect ?? { left: 0, width: 0, bottom: 0 }, menuMinWidth, viewportWidth),
616
624
  themed
617
625
  ];
626
+ }
618
627
  return [styles6.popover, { minWidth: menuMinWidth }, themed];
619
628
  }, [colors.border, colors.surface, menuMinWidth, rect]);
620
629
  const menu = /* @__PURE__ */ jsx(