@hexdspace/react 0.1.31 → 0.1.32

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.
Files changed (2) hide show
  1. package/dist/index.js +43 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2849,6 +2849,24 @@ function useWindowTimeout() {
2849
2849
  React13.useEffect(() => clear, [clear]);
2850
2850
  return { set, clear };
2851
2851
  }
2852
+ function getFocusableElements() {
2853
+ const selector = [
2854
+ "a[href]",
2855
+ "button:not([disabled])",
2856
+ "textarea:not([disabled])",
2857
+ "input:not([disabled])",
2858
+ "select:not([disabled])",
2859
+ '[tabindex]:not([tabindex="-1"])'
2860
+ ].join(",");
2861
+ return Array.from(document.querySelectorAll(selector));
2862
+ }
2863
+ function getNextFocusableElement(currentElement, reverse = false) {
2864
+ const focusableElements = getFocusableElements();
2865
+ const currentIndex = focusableElements.indexOf(currentElement);
2866
+ if (currentIndex === -1) return null;
2867
+ const nextIndex = reverse ? currentIndex - 1 : currentIndex + 1;
2868
+ return focusableElements[nextIndex] || null;
2869
+ }
2852
2870
  function DropdownMenu({
2853
2871
  trigger,
2854
2872
  children,
@@ -2930,9 +2948,29 @@ function DropdownMenu({
2930
2948
  className: contentClassName,
2931
2949
  style: contentStyle,
2932
2950
  ref: contentPropRef,
2951
+ onKeyDown: userOnKeyDown,
2933
2952
  ...restContentProps
2934
2953
  } = contentPropsWithRef ?? {};
2935
2954
  const composedContentRef = useComposedRefs(contentRef, contentPropRef);
2955
+ const handleContentKeyDown = React13.useCallback(
2956
+ (event) => {
2957
+ userOnKeyDown?.(event);
2958
+ if (event.key === "Tab" && !event.defaultPrevented) {
2959
+ event.preventDefault();
2960
+ const triggerElement2 = triggerRef.current;
2961
+ if (!triggerElement2) return;
2962
+ const reverse = event.shiftKey;
2963
+ const nextElement = getNextFocusableElement(triggerElement2, reverse);
2964
+ handleOpenChange(false);
2965
+ if (nextElement) {
2966
+ setTimeout(() => {
2967
+ nextElement.focus();
2968
+ }, 0);
2969
+ }
2970
+ }
2971
+ },
2972
+ [handleOpenChange, userOnKeyDown]
2973
+ );
2936
2974
  const onPointerDownOutside = (event) => {
2937
2975
  restContentProps.onPointerDownOutside?.(event);
2938
2976
  };
@@ -2941,6 +2979,7 @@ function DropdownMenu({
2941
2979
  };
2942
2980
  const resolvedContentProps = hoverOpen ? {
2943
2981
  ...restContentProps,
2982
+ onKeyDown: handleContentKeyDown,
2944
2983
  onPointerEnter: (event) => {
2945
2984
  restContentProps.onPointerEnter?.(event);
2946
2985
  closeTimer.clear();
@@ -2956,7 +2995,10 @@ function DropdownMenu({
2956
2995
  },
2957
2996
  onPointerDownOutside,
2958
2997
  onInteractOutside
2959
- } : restContentProps;
2998
+ } : {
2999
+ ...restContentProps,
3000
+ onKeyDown: handleContentKeyDown
3001
+ };
2960
3002
  return /* @__PURE__ */ jsxs11(DropdownMenuPrimitive.Root, { open: resolvedOpen, onOpenChange: handleOpenChange, modal, children: [
2961
3003
  /* @__PURE__ */ jsx19(DropdownMenuPrimitive.Trigger, { asChild: true, children: resolvedTrigger }),
2962
3004
  /* @__PURE__ */ jsx19(DropdownMenuPrimitive.Portal, { forceMount: true, container: portalContainer, children: /* @__PURE__ */ jsx19(AnimatePresence4, { children: resolvedOpen ? /* @__PURE__ */ jsx19(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hexdspace/react",
3
- "version": "0.1.31",
3
+ "version": "0.1.32",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",