@lumx/react 3.6.5-alpha.4 → 3.6.5

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
@@ -4067,14 +4067,14 @@ const skipRender = (predicate, Component) => {
4067
4067
  */
4068
4068
  const OnBeforeUnmount = _ref => {
4069
4069
  let {
4070
- callback
4070
+ callbackRef
4071
4071
  } = _ref;
4072
4072
  useLayoutEffect(() => {
4073
4073
  return () => {
4074
- var _callback$current;
4074
+ var _callbackRef$current;
4075
4075
  // On unmount
4076
4076
  // eslint-disable-next-line react-hooks/exhaustive-deps
4077
- (_callback$current = callback.current) === null || _callback$current === void 0 ? void 0 : _callback$current.call(callback);
4077
+ (_callbackRef$current = callbackRef.current) === null || _callbackRef$current === void 0 ? void 0 : _callbackRef$current.call(callbackRef);
4078
4078
  };
4079
4079
  },
4080
4080
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -4092,32 +4092,34 @@ function useRestoreFocusOnClose(_ref, popoverElement) {
4092
4092
  anchorRef,
4093
4093
  parentElement
4094
4094
  } = _ref;
4095
- // eslint-disable-next-line @typescript-eslint/no-empty-function
4096
- const onBeforeUnmountRef = React.useRef(() => {});
4097
- const anchor = anchorRef.current;
4098
- const elementToFocus =
4099
- // Provided parent element
4100
- (parentElement === null || parentElement === void 0 ? void 0 : parentElement.current) || (
4101
- // Or first focusable element in anchor
4102
- anchor ? getFirstAndLastFocusable(anchor).first : undefined) ||
4103
- // Fallback to anchor
4104
- anchor;
4095
+ const onBeforeUnmountRef = React.useRef();
4105
4096
  React.useEffect(() => {
4106
- if (!popoverElement || !focusAnchorOnClose || !elementToFocus) return;
4097
+ if (!popoverElement || !focusAnchorOnClose) {
4098
+ onBeforeUnmountRef.current = undefined;
4099
+ return;
4100
+ }
4107
4101
  onBeforeUnmountRef.current = () => {
4108
4102
  const isFocusWithin = popoverElement === null || popoverElement === void 0 ? void 0 : popoverElement.contains(document.activeElement);
4109
4103
  if (!isFocusWithin) return;
4110
4104
 
4111
- // Focus on next render
4105
+ // On next render
4112
4106
  setTimeout(() => {
4113
- elementToFocus.focus({
4107
+ const anchor = anchorRef.current;
4108
+ const elementToFocus =
4109
+ // Provided parent element
4110
+ (parentElement === null || parentElement === void 0 ? void 0 : parentElement.current) || (
4111
+ // Or first focusable element in anchor
4112
+ anchor ? getFirstAndLastFocusable(anchor).first : undefined) ||
4113
+ // Fallback to anchor
4114
+ anchor;
4115
+ elementToFocus === null || elementToFocus === void 0 ? void 0 : elementToFocus.focus({
4114
4116
  preventScroll: true
4115
4117
  });
4116
4118
  }, 0);
4117
4119
  };
4118
- }, [anchor, elementToFocus, focusAnchorOnClose, popoverElement]);
4120
+ }, [anchorRef, focusAnchorOnClose, parentElement, popoverElement]);
4119
4121
  return /*#__PURE__*/React.createElement(OnBeforeUnmount, {
4120
- callback: onBeforeUnmountRef
4122
+ callbackRef: onBeforeUnmountRef
4121
4123
  });
4122
4124
  }
4123
4125