@aurora-ds/components 1.7.19 → 1.7.20

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/cjs/index.js CHANGED
@@ -3561,6 +3561,10 @@ const MENU_MIN_WIDTH_PX = 224;
3561
3561
  */
3562
3562
  const useMenuPosition = ({ anchorEl, open, menuRef, minWidth, gap = 4, placement = 'bottom', }) => {
3563
3563
  const [style, setStyle] = React.useState({});
3564
+ // Stays false until the rAF second pass has run with the real panel dimensions.
3565
+ // Keeps the panel invisible during the initial style={} state and the first
3566
+ // pass (menuHeight = 0) to prevent the position-jump flickering.
3567
+ const [isPositioned, setIsPositioned] = React.useState(false);
3564
3568
  const computePosition = React.useCallback(() => {
3565
3569
  if (!anchorEl) {
3566
3570
  return;
@@ -3641,14 +3645,19 @@ const useMenuPosition = ({ anchorEl, open, menuRef, minWidth, gap = 4, placement
3641
3645
  }
3642
3646
  else {
3643
3647
  setStyle({});
3648
+ setIsPositioned(false);
3644
3649
  }
3645
3650
  }, [open, computePosition]);
3646
- // Second pass: recompute after the panel renders to get actual height/width
3651
+ // Second pass: recompute after the panel renders to get actual height/width,
3652
+ // then mark as positioned so the panel becomes visible.
3647
3653
  React.useEffect(() => {
3648
3654
  if (!open) {
3649
3655
  return;
3650
3656
  }
3651
- const id = requestAnimationFrame(computePosition);
3657
+ const id = requestAnimationFrame(() => {
3658
+ computePosition();
3659
+ setIsPositioned(true);
3660
+ });
3652
3661
  return () => cancelAnimationFrame(id);
3653
3662
  }, [open, computePosition]);
3654
3663
  // Keep the menu glued to its anchor on scroll (nested containers) and resize.
@@ -3663,7 +3672,7 @@ const useMenuPosition = ({ anchorEl, open, menuRef, minWidth, gap = 4, placement
3663
3672
  window.removeEventListener('resize', computePosition);
3664
3673
  };
3665
3674
  }, [open, computePosition]);
3666
- return { style };
3675
+ return { style: { ...style, visibility: isPositioned ? 'visible' : 'hidden' } };
3667
3676
  };
3668
3677
 
3669
3678
  /** Custom DOM event fired on a submenu trigger item to request it opens. */