diff --git a/src/app/(after-login)/mypage/_components/MyWritings.tsx b/src/app/(after-login)/mypage/_components/MyWritings.tsx index fb06e4c..599a460 100644 --- a/src/app/(after-login)/mypage/_components/MyWritings.tsx +++ b/src/app/(after-login)/mypage/_components/MyWritings.tsx @@ -37,9 +37,9 @@ export default function MyWritings() { return ( - + - + - + - + { const [activeTab, setActiveTab] = useState(0); return ( - - + + 탭 1 - + 탭 2 @@ -34,10 +34,10 @@ describe('Tab 컴포넌트 테스트', () => { return ( - + 내용 1 - + 내용 2 diff --git a/src/components/Tab.tsx b/src/components/Tab.tsx index d0e2fe8..b444bc4 100644 --- a/src/components/Tab.tsx +++ b/src/components/Tab.tsx @@ -7,13 +7,15 @@ import { cn } from '@/utils/helper'; interface TabListProps { children: React.ReactNode; className?: string; + activeTab: number; + setActiveTab: (tab: number) => void; } interface TabBtnProps { children: React.ReactNode; className?: string; activeClass?: string; - tabIndex: number; + index: number; activeTab: number; setActiveTab: (tab: number) => void; } @@ -26,7 +28,7 @@ interface TabItemsContainerProps { interface TabItemProps { children: React.ReactNode; className?: string; - tabIndex: number; + index: number; activeTab: number; animation?: { enabled?: boolean; @@ -53,9 +55,31 @@ export function Tabs({ children }: { children: React.ReactNode }) { ); } -export function TabList({ children, className }: TabListProps) { +export function TabList({ children, className, activeTab, setActiveTab }: TabListProps) { + const tabs = React.Children.toArray(children); + const totalTabs = tabs.length; + + const handleKeyDown = (e: React.KeyboardEvent) => { + if (e.key === 'ArrowRight') { + e.preventDefault(); + const nextTab = (activeTab + 1) % totalTabs; + setActiveTab(nextTab); + (document.querySelectorAll('[role="tab"]')[nextTab] as HTMLButtonElement)?.focus(); + } + + if (e.key === 'ArrowLeft') { + e.preventDefault(); + const prevTab = (activeTab - 1 + totalTabs) % totalTabs; + setActiveTab(prevTab); + (document.querySelectorAll('[role="tab"]')[prevTab] as HTMLButtonElement)?.focus(); + } + }; return ( -
    +
      {children}
    ); @@ -65,24 +89,27 @@ export function TabBtn({ children, activeClass, className, - tabIndex, + index, activeTab, setActiveTab, }: TabBtnProps) { const active = 'text-black-600 font-semibold'; - const isActive = activeTab === tabIndex; + const isActive = activeTab === index; return (
  • @@ -94,8 +121,8 @@ export function TabItemsContainer({ children, className }: TabItemsContainerProp return
      {children}
    ; } -export function TabItem({ children, className, tabIndex, activeTab, animation }: TabItemProps) { - const isActive = activeTab === tabIndex; +export function TabItem({ children, className, index, activeTab, animation }: TabItemProps) { + const isActive = activeTab === index; const { enabled = true, direction = 'y', directionValue = 20, duration = 0.25 } = animation || {}; const [isFirstRender, setIsFirstRender] = useState(true);