diff --git a/frontend/src/components/ui/Tabs.js b/frontend/src/components/ui/Tabs.js
index 61baaa6..89e3bf5 100644
--- a/frontend/src/components/ui/Tabs.js
+++ b/frontend/src/components/ui/Tabs.js
@@ -1,4 +1,4 @@
-import React, { createContext, useContext } from 'react';
+import React, { createContext, useContext, useRef, useEffect, useState } from 'react';
const TabsContext = createContext();
@@ -13,23 +13,55 @@ const Tabs = ({ value, onValueChange, children, className = '' }) => {
};
const TabsList = ({ children, className = '', ...props }) => {
+ const { value: currentValue } = useContext(TabsContext);
+ const [indicatorStyle, setIndicatorStyle] = useState({ left: 0, width: 0 });
+ const tabsRef = useRef({});
+
+ useEffect(() => {
+ const activeTab = tabsRef.current[currentValue];
+ if (activeTab) {
+ setIndicatorStyle({
+ left: activeTab.offsetLeft,
+ width: activeTab.offsetWidth,
+ });
+ }
+ }, [currentValue]);
+
return (
-
- {children}
+
+
+ {React.Children.map(children, (child) =>
+ React.cloneElement(child, { tabsRef })
+ )}
);
};
-const TabsTrigger = ({ value, children, className = '', ...props }) => {
+const TabsTrigger = ({ value, children, className = '', tabsRef, ...props }) => {
const { value: currentValue, onValueChange } = useContext(TabsContext);
const isActive = currentValue === value;
+ const buttonRef = useRef(null);
+
+ useEffect(() => {
+ if (tabsRef && buttonRef.current) {
+ tabsRef.current[value] = buttonRef.current;
+ }
+ }, [tabsRef, value]);
return (