@trackunit/react-components 1.21.7 → 1.21.8

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.cjs.js CHANGED
@@ -7816,6 +7816,33 @@ const TabContent = ({ className, "data-testid": dataTestId, children, ref, ...re
7816
7816
  return (jsxRuntime.jsx(reactTabs.Content, { className: cvaTabContent({ className }), "data-testid": dataTestId ? `${dataTestId}-content` : undefined, ref: ref, ...rest, children: children }));
7817
7817
  };
7818
7818
 
7819
+ /**
7820
+ * Scrolls the active tab into the visible area of the TabList container,
7821
+ * using direct scrollLeft manipulation so ancestor scroll containers are unaffected.
7822
+ */
7823
+ const useScrollActiveTabIntoView = ({ listRef, enabled, }) => {
7824
+ react.useLayoutEffect(() => {
7825
+ if (!enabled)
7826
+ return;
7827
+ const element = listRef.current;
7828
+ if (!element)
7829
+ return;
7830
+ const activeTab = element.querySelector('[aria-selected="true"]');
7831
+ if (!activeTab)
7832
+ return;
7833
+ const tabLeft = activeTab.offsetLeft;
7834
+ const tabRight = tabLeft + activeTab.offsetWidth;
7835
+ const visibleLeft = element.scrollLeft;
7836
+ const visibleRight = visibleLeft + element.clientWidth;
7837
+ if (tabLeft < visibleLeft) {
7838
+ element.scrollLeft = tabLeft;
7839
+ }
7840
+ else if (tabRight > visibleRight) {
7841
+ element.scrollLeft = tabRight - element.clientWidth;
7842
+ }
7843
+ }, [enabled, listRef]);
7844
+ };
7845
+
7819
7846
  /**
7820
7847
  * TabList is the container for Tab triggers inside a Tabs component.
7821
7848
  * It renders a horizontal row of tab triggers and handles horizontal scroll behavior when tabs overflow.
@@ -7870,24 +7897,7 @@ const TabList = ({ className, "data-testid": dataTestId, children, autoScrollToA
7870
7897
  element.removeEventListener("wheel", handleWheel);
7871
7898
  };
7872
7899
  }, []);
7873
- // Auto-scroll active tab into view when enabled
7874
- react.useLayoutEffect(() => {
7875
- if (!autoScrollToActive) {
7876
- return;
7877
- }
7878
- const element = listRef.current;
7879
- if (!element)
7880
- return;
7881
- // Find the active tab using a radix UI build in selector
7882
- const activeTab = element.querySelector('[aria-selected="true"]');
7883
- if (activeTab && typeof activeTab.scrollIntoView === "function") {
7884
- activeTab.scrollIntoView({
7885
- behavior: "instant",
7886
- block: "nearest",
7887
- inline: "center",
7888
- });
7889
- }
7890
- }, [autoScrollToActive]);
7900
+ useScrollActiveTabIntoView({ listRef, enabled: autoScrollToActive });
7891
7901
  return (jsxRuntime.jsx(reactTabs.List, { className: cvaTabList({ className }), "data-testid": dataTestId, ref: mergedRef, ...rest, children: children }));
7892
7902
  };
7893
7903
 
package/index.esm.js CHANGED
@@ -7814,6 +7814,33 @@ const TabContent = ({ className, "data-testid": dataTestId, children, ref, ...re
7814
7814
  return (jsx(Content$1, { className: cvaTabContent({ className }), "data-testid": dataTestId ? `${dataTestId}-content` : undefined, ref: ref, ...rest, children: children }));
7815
7815
  };
7816
7816
 
7817
+ /**
7818
+ * Scrolls the active tab into the visible area of the TabList container,
7819
+ * using direct scrollLeft manipulation so ancestor scroll containers are unaffected.
7820
+ */
7821
+ const useScrollActiveTabIntoView = ({ listRef, enabled, }) => {
7822
+ useLayoutEffect(() => {
7823
+ if (!enabled)
7824
+ return;
7825
+ const element = listRef.current;
7826
+ if (!element)
7827
+ return;
7828
+ const activeTab = element.querySelector('[aria-selected="true"]');
7829
+ if (!activeTab)
7830
+ return;
7831
+ const tabLeft = activeTab.offsetLeft;
7832
+ const tabRight = tabLeft + activeTab.offsetWidth;
7833
+ const visibleLeft = element.scrollLeft;
7834
+ const visibleRight = visibleLeft + element.clientWidth;
7835
+ if (tabLeft < visibleLeft) {
7836
+ element.scrollLeft = tabLeft;
7837
+ }
7838
+ else if (tabRight > visibleRight) {
7839
+ element.scrollLeft = tabRight - element.clientWidth;
7840
+ }
7841
+ }, [enabled, listRef]);
7842
+ };
7843
+
7817
7844
  /**
7818
7845
  * TabList is the container for Tab triggers inside a Tabs component.
7819
7846
  * It renders a horizontal row of tab triggers and handles horizontal scroll behavior when tabs overflow.
@@ -7868,24 +7895,7 @@ const TabList = ({ className, "data-testid": dataTestId, children, autoScrollToA
7868
7895
  element.removeEventListener("wheel", handleWheel);
7869
7896
  };
7870
7897
  }, []);
7871
- // Auto-scroll active tab into view when enabled
7872
- useLayoutEffect(() => {
7873
- if (!autoScrollToActive) {
7874
- return;
7875
- }
7876
- const element = listRef.current;
7877
- if (!element)
7878
- return;
7879
- // Find the active tab using a radix UI build in selector
7880
- const activeTab = element.querySelector('[aria-selected="true"]');
7881
- if (activeTab && typeof activeTab.scrollIntoView === "function") {
7882
- activeTab.scrollIntoView({
7883
- behavior: "instant",
7884
- block: "nearest",
7885
- inline: "center",
7886
- });
7887
- }
7888
- }, [autoScrollToActive]);
7898
+ useScrollActiveTabIntoView({ listRef, enabled: autoScrollToActive });
7889
7899
  return (jsx(List$1, { className: cvaTabList({ className }), "data-testid": dataTestId, ref: mergedRef, ...rest, children: children }));
7890
7900
  };
7891
7901
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-components",
3
- "version": "1.21.7",
3
+ "version": "1.21.8",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -0,0 +1,9 @@
1
+ import { type RefObject } from "react";
2
+ /**
3
+ * Scrolls the active tab into the visible area of the TabList container,
4
+ * using direct scrollLeft manipulation so ancestor scroll containers are unaffected.
5
+ */
6
+ export declare const useScrollActiveTabIntoView: ({ listRef, enabled, }: {
7
+ readonly listRef: RefObject<HTMLDivElement | null>;
8
+ readonly enabled: boolean;
9
+ }) => void;