@sproutsocial/seeds-react-menu 1.18.3 → 1.18.4

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.js CHANGED
@@ -2650,6 +2650,9 @@ var import_jsx_runtime32 = require("react/jsx-runtime");
2650
2650
  var StyledDiv = (0, import_styled_components12.default)(import_react30.motion.div)`
2651
2651
  overflow: hidden;
2652
2652
  `;
2653
+ var RETURN_FOCUS_DELAY = 200;
2654
+ var RETURN_FOCUS_RETRY_DELAY = 50;
2655
+ var RETURN_FOCUS_BUDGET = 1e3;
2653
2656
  var NestedMenuPopout = ({
2654
2657
  content,
2655
2658
  menuToggleElement,
@@ -2660,16 +2663,43 @@ var NestedMenuPopout = ({
2660
2663
  ...popoutProps
2661
2664
  }) => {
2662
2665
  const { activeMenuContext, rootMenuContextProps, resetSelectedMenuPath } = useNestedMenuContext();
2666
+ const closeTimerRef = (0, import_react29.useRef)();
2667
+ const retryTimerRef = (0, import_react29.useRef)();
2668
+ (0, import_react29.useEffect)(
2669
+ () => () => {
2670
+ clearTimeout(closeTimerRef.current);
2671
+ clearTimeout(retryTimerRef.current);
2672
+ },
2673
+ []
2674
+ );
2675
+ const attemptReturnFocus = (deadline) => {
2676
+ const toggleElement = toggleElementRef.current;
2677
+ if (toggleElement) {
2678
+ if (document.activeElement === toggleElement) {
2679
+ return;
2680
+ }
2681
+ toggleElement.focus();
2682
+ if (document.activeElement === toggleElement) {
2683
+ return;
2684
+ }
2685
+ }
2686
+ if (Date.now() < deadline) {
2687
+ retryTimerRef.current = setTimeout(
2688
+ () => attemptReturnFocus(deadline),
2689
+ RETURN_FOCUS_RETRY_DELAY
2690
+ );
2691
+ }
2692
+ };
2663
2693
  return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
2664
2694
  MenuPopout,
2665
2695
  {
2666
2696
  lockPlacement: true,
2667
2697
  onClose: () => {
2668
2698
  onClose?.();
2669
- setTimeout(() => {
2670
- toggleElementRef.current?.focus();
2699
+ closeTimerRef.current = setTimeout(() => {
2700
+ attemptReturnFocus(Date.now() + RETURN_FOCUS_BUDGET);
2671
2701
  resetSelectedMenuPath?.();
2672
- }, 200);
2702
+ }, RETURN_FOCUS_DELAY);
2673
2703
  },
2674
2704
  isOpen: !!rootMenuContextProps.isOpen,
2675
2705
  openMenu: rootMenuContextProps.openMenu,