@lumx/react 3.11.0 → 3.11.1-alpha.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/index.js CHANGED
@@ -4520,7 +4520,6 @@ function usePopoverStyle(_ref5) {
4520
4520
  fitWithinViewportHeight,
4521
4521
  boundaryRef,
4522
4522
  anchorRef,
4523
- children,
4524
4523
  placement,
4525
4524
  style,
4526
4525
  zIndex
@@ -4576,9 +4575,34 @@ function usePopoverStyle(_ref5) {
4576
4575
  placement,
4577
4576
  modifiers
4578
4577
  });
4578
+
4579
+ // Auto update popover
4579
4580
  useEffect(() => {
4580
- update === null || update === void 0 ? void 0 : update();
4581
- }, [children, update]);
4581
+ const {
4582
+ current: anchorElement
4583
+ } = anchorRef;
4584
+ if (!update || !popperElement || !anchorElement || !(WINDOW !== null && WINDOW !== void 0 && WINDOW.ResizeObserver)) {
4585
+ return undefined;
4586
+ }
4587
+
4588
+ // Only update once per frame
4589
+ let frame;
4590
+ function limitedUpdate() {
4591
+ if (frame) return;
4592
+ frame = requestAnimationFrame(() => {
4593
+ update === null || update === void 0 ? void 0 : update();
4594
+ frame = undefined;
4595
+ });
4596
+ }
4597
+
4598
+ // On anchor or popover resize
4599
+ const resizeObserver = new ResizeObserver(limitedUpdate);
4600
+ resizeObserver.observe(anchorElement);
4601
+ resizeObserver.observe(popperElement);
4602
+ return () => {
4603
+ resizeObserver.disconnect();
4604
+ };
4605
+ }, [anchorRef, popperElement, update]);
4582
4606
  const position = (_state$placement = state === null || state === void 0 ? void 0 : state.placement) !== null && _state$placement !== void 0 ? _state$placement : placement;
4583
4607
  const popoverStyle = useMemo(() => {
4584
4608
  const newStyles = _objectSpread2(_objectSpread2(_objectSpread2({}, style), styles.popper), {}, {
@@ -4587,6 +4611,9 @@ function usePopoverStyle(_ref5) {
4587
4611
  if (fitWithinViewportHeight && !newStyles.maxHeight) {
4588
4612
  newStyles.maxHeight = (WINDOW === null || WINDOW === void 0 ? void 0 : WINDOW.innerHeight) || (DOCUMENT === null || DOCUMENT === void 0 ? void 0 : DOCUMENT.documentElement.clientHeight);
4589
4613
  }
4614
+
4615
+ // Do not show the popover while it's not properly placed
4616
+ if (!newStyles.transform) newStyles.visibility = 'hidden';
4590
4617
  return newStyles;
4591
4618
  }, [style, styles.popper, zIndex, fitWithinViewportHeight]);
4592
4619
  return {
@@ -4680,7 +4707,6 @@ const _InnerPopover = forwardRef((props, ref) => {
4680
4707
  fitWithinViewportHeight,
4681
4708
  boundaryRef,
4682
4709
  anchorRef,
4683
- children,
4684
4710
  placement,
4685
4711
  style,
4686
4712
  zIndex