@flytedan/flytebot-design-system 0.17.0 → 0.17.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/dist/index.cjs CHANGED
@@ -11889,6 +11889,42 @@ var FOCUSABLE_SELECTOR = 'a[href], button:not([disabled]), textarea:not([disable
11889
11889
  function getFocusable(container) {
11890
11890
  return Array.from(container.querySelectorAll(FOCUSABLE_SELECTOR));
11891
11891
  }
11892
+ function useFocusTrap(navRef, active) {
11893
+ React55.useEffect(() => {
11894
+ if (!active) return;
11895
+ const container = navRef.current;
11896
+ if (!container) return;
11897
+ const previouslyFocused = document.activeElement;
11898
+ const focusable = getFocusable(container);
11899
+ (focusable[0] ?? container).focus();
11900
+ const handler = (e) => {
11901
+ if (e.key !== "Tab") return;
11902
+ const items = getFocusable(container);
11903
+ if (items.length === 0) {
11904
+ e.preventDefault();
11905
+ return;
11906
+ }
11907
+ const first = items[0];
11908
+ const last = items[items.length - 1];
11909
+ const activeElement = document.activeElement;
11910
+ const outside = !(activeElement instanceof Node) || !container.contains(activeElement);
11911
+ if (e.shiftKey) {
11912
+ if (outside || activeElement === first) {
11913
+ e.preventDefault();
11914
+ last.focus();
11915
+ }
11916
+ } else if (outside || activeElement === last) {
11917
+ e.preventDefault();
11918
+ first.focus();
11919
+ }
11920
+ };
11921
+ document.addEventListener("keydown", handler);
11922
+ return () => {
11923
+ document.removeEventListener("keydown", handler);
11924
+ previouslyFocused?.focus?.();
11925
+ };
11926
+ }, [active, navRef]);
11927
+ }
11892
11928
  function useResponsiveRail(options = {}) {
11893
11929
  const { breakpoint = 1024, initialOpen = true, onPersist } = options;
11894
11930
  const navRef = React55.useRef(null);
@@ -11929,40 +11965,7 @@ function useResponsiveRail(options = {}) {
11929
11965
  document.body.style.overflow = previousOverflow;
11930
11966
  };
11931
11967
  }, [overlay, open]);
11932
- React55.useEffect(() => {
11933
- if (!overlay || !open) return;
11934
- const container = navRef.current;
11935
- if (!container) return;
11936
- const previouslyFocused = document.activeElement;
11937
- const focusable = getFocusable(container);
11938
- (focusable[0] ?? container).focus();
11939
- const handler = (e) => {
11940
- if (e.key !== "Tab") return;
11941
- const items = getFocusable(container);
11942
- if (items.length === 0) {
11943
- e.preventDefault();
11944
- return;
11945
- }
11946
- const first = items[0];
11947
- const last = items[items.length - 1];
11948
- const active = document.activeElement;
11949
- const outside = !(active instanceof Node) || !container.contains(active);
11950
- if (e.shiftKey) {
11951
- if (outside || active === first) {
11952
- e.preventDefault();
11953
- last.focus();
11954
- }
11955
- } else if (outside || active === last) {
11956
- e.preventDefault();
11957
- first.focus();
11958
- }
11959
- };
11960
- document.addEventListener("keydown", handler);
11961
- return () => {
11962
- document.removeEventListener("keydown", handler);
11963
- previouslyFocused?.focus?.();
11964
- };
11965
- }, [overlay, open]);
11968
+ useFocusTrap(navRef, overlay && open);
11966
11969
  return { open, overlay, navRef, toggle, close, setOpen };
11967
11970
  }
11968
11971
  // Annotate the CommonJS export names for ESM import in node: