# Tabs URL: /lynx/components/tabs Source: https://github.com/daangn/seed-design/blob/dev/docs/content/lynx/components/tabs.mdx A component that divides content on one screen into tabs and switches between tabs by selection or left/right swipe. Lynx Engine 최소 버전: 3.6 사용 XElement: , 사용 가능 버전: @seed-design/lynx-react@0.5.0, @seed-design/lynx-css@0.9.0 ## Preview ```tsx import "./styles"; import { useSeedClassName } from "@seed-design/lynx-react"; import { TabsContent, TabsList, TabsRoot, TabsTrigger } from "@/components/ui/tabs"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 라벨1 라벨2 라벨3 Content 1 Content 2 Content 3 ); } ``` ## Installation - npm: npx @seed-design/cli add ui:tabs - pnpm: pnpm dlx @seed-design/cli add ui:tabs - yarn: yarn dlx @seed-design/cli add ui:tabs - bun: bun x @seed-design/cli add ui:tabs ## Props ### `TabsRoot` ### `TabsList` ### `TabsTrigger` ### `TabsCarousel` ### `TabsContent` ## Usage ```tsx import { TabsCarousel, TabsContent, TabsList, TabsRoot, TabsTrigger, } from "@/components/ui/tabs"; export function App() { return ( First Second First content Second content ); } ``` Registry's `TabsList` automatically adds `Tabs.Indicator`. `TabsCarousel` also assembles `Tabs.CarouselCamera` internally, so you only need to pass each `TabsContent` as children. `TabsCarousel` uses Lynx native ``. You must specify a height for the Carousel that fits your app's layout, and setting `swipeable` allows you to change tabs by swiping left and right. On iOS, the back gesture starting within 32px from the left edge of the screen takes priority. If you need to match your app's gesture area, adjust the width with `iosBackGestureEdgeWidth`. The `scrollAlign` of `TabsList` specifies how the selected tab is aligned in the horizontal list, and can use `"nearest"`, `"start"`, `"center"`, `"end"`. The default is `"start"`, which aligns the selected tab to the start of the list. Chip Tabs' `ChipTabsList` supports the same options but the default is `"nearest"`. ## Examples ### Layout Fill (Default) ```tsx import "./styles"; import { useSeedClassName } from "@seed-design/lynx-react"; import { TabsContent, TabsList, TabsRoot, TabsTrigger } from "@/components/ui/tabs"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 라벨1 라벨2 라벨3 Content 1 Content 2 Content 3 ); } ``` ### Layout Hug ```tsx import "./styles"; import { useSeedClassName } from "@seed-design/lynx-react"; import { TabsContent, TabsList, TabsRoot, TabsTrigger } from "@/components/ui/tabs"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 라벨1 라벨2 라벨3 Content 1 Content 2 Content 3 ); } ``` ### Size Medium ```tsx import "./styles"; import { useSeedClassName } from "@seed-design/lynx-react"; import { TabsContent, TabsList, TabsRoot, TabsTrigger } from "@/components/ui/tabs"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 라벨1 라벨2 라벨3 Content 1 Content 2 Content 3 ); } ``` ### Size Small (Default) ```tsx import "./styles"; import { useSeedClassName } from "@seed-design/lynx-react"; import { TabsContent, TabsList, TabsRoot, TabsTrigger } from "@/components/ui/tabs"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 라벨1 라벨2 라벨3 Content 1 Content 2 Content 3 ); } ``` ### Transition Lynx's `TabsCarousel` calls the native viewpager's `selectTab` with `smooth: false` when selecting a tab, so the content changes immediately. If you need a transition effect, render the content directly based on the selected value instead of `TabsCarousel` and apply animation in your app. ### Swipeable When you tap a Trigger or drag the content left and right, the selected value and Indicator move together. ```tsx import "./styles"; import { useSeedClassName } from "@seed-design/lynx-react"; import { TabsCarousel, TabsContent, TabsList, TabsRoot, TabsTrigger } from "@/components/ui/tabs"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 라벨1 라벨2 라벨3 Content 1 Content 2 Content 3 ); } ``` ### Carousel Prevent Drag Lynx does not support `carouselPreventDrag`. Place interactive elements that conflict with dragging outside of the Carousel. ### Disabled A `disabled` Trigger cannot be tapped. When the Carousel reaches a disabled tab, it moves to the next active tab. ```tsx import "./styles"; import { useSeedClassName } from "@seed-design/lynx-react"; import { TabsContent, TabsList, TabsRoot, TabsTrigger } from "@/components/ui/tabs"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 라벨1 라벨2 라벨3 Content 1 Content 2 Content 3 ); } ``` ### Notification ```tsx import "./styles"; import { useSeedClassName } from "@seed-design/lynx-react"; import { TabsContent, TabsList, TabsRoot, TabsTrigger } from "@/components/ui/tabs"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 라벨1 라벨2 라벨3 Content 1 Content 2 Content 3 ); } ``` ### Sticky List Use when tabs take up the entire screen and `TabsList` needs to be fixed at the top of the screen. ```tsx import "./styles"; import { useSeedClassName } from "@seed-design/lynx-react"; import { TabsContent, TabsList, TabsRoot, TabsTrigger } from "@/components/ui/tabs"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 라벨1 라벨2 라벨3 Content 1 Content 2 Content 3 ); } ``` ### Standalone Use when not using `TabsContent` and composing the content area directly. In this configuration, the swipe functionality provided by Tabs cannot be used. ```tsx import "./styles"; import { useState } from "@lynx-js/react"; import { useSeedClassName } from "@seed-design/lynx-react"; import { TabsList, TabsRoot, TabsTrigger } from "@/components/ui/tabs"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); const [activeTab, setActiveTab] = useState("1"); function handleValueChange(value: string) { "background only"; setActiveTab(value); } return ( 라벨1 라벨2 라벨3 {activeTab === "1" && ( Content 1 )} {activeTab === "2" && ( Content 2 )} {activeTab === "3" && ( Content 3 )} ); } ``` ### Dynamic Height Without `autoHeight`, `lazyMount`, `unmountOnExit` of `TabsCarousel`, placing `TabsContent` outside the Carousel allows you to adjust the position of content below based on the height of the selected content. This configuration does not provide swipe. ```tsx import "./styles"; import { useSeedClassName } from "@seed-design/lynx-react"; import { TabsContent, TabsList, TabsRoot, TabsTrigger } from "@/components/ui/tabs"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 라벨1 라벨2 라벨3 Content 1 Content 2 Content 3 아래 콘텐츠 ); } ``` ### Scroll to Top `TabsTrigger`'s `bindtap` is also called when re-tapping an already selected Trigger. The example below starts showing from the fourth item, and when you re-tap the selected tab, the `scroll-view` of the current content moves to the top. ```tsx import "./styles"; import { useCallback, useRef, useState } from "@lynx-js/react"; import type { NodesRef } from "@lynx-js/types"; import { useSeedClassName } from "@seed-design/lynx-react"; import { TabsCarousel, TabsContent, TabsList, TabsRoot, TabsTrigger } from "@/components/ui/tabs"; const SCROLL_ITEMS = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; function scrollToTop(ref: NodesRef | null) { "background only"; ref?.invoke({ method: "scrollTo", params: { offset: 0, smooth: true } }).exec(); } export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); const [currentTab, setCurrentTab] = useState("1"); const firstContentRef = useRef(null); const secondContentRef = useRef(null); const setFirstContentRef = useCallback((node: NodesRef | null) => { "background only"; firstContentRef.current = node; }, []); const setSecondContentRef = useCallback((node: NodesRef | null) => { "background only"; secondContentRef.current = node; }, []); function handleFirstTriggerTap() { "background only"; if (currentTab === "1") scrollToTop(firstContentRef.current); } function handleSecondTriggerTap() { "background only"; if (currentTab === "2") scrollToTop(secondContentRef.current); } return ( 라벨1 라벨2 {SCROLL_ITEMS.map((item) => ( Content 1 · {item} ))} {SCROLL_ITEMS.map((item) => ( Content 2 · {item} ))} ); } ``` ## Web Version Differences | Item | React Web | Lynx | | ------------------- | --------------------------------- | ----------------------------------------------------------------- | | Rendering elements | HTML `div`, `button` | Native `view`, `text`, `scroll-view`, `viewpager` | | Tab selection event | `onClick` based | `bindtap` based, public state event is `onValueChange` | | Carousel | Embla Carousel | Native `` | | Horizontal List | CSS overflow | Native `` | | Control method | `value`, `defaultValue` | Same | | Accessibility | ARIA `tablist`, `tab`, `tabpanel` | Lynx `accessibility-*` attributes | | Indicator | DOM measurement and CSS variables | `bindlayoutchange` measurement and viewpager offset interpolation | Verify swipe momentum, skipping disabled tabs, and Indicator movement using Lynx Explorer from the QR code tab. The browser preview in the documentation and gesture results on native devices may differ. ## Unsupported Lynx Features The current Lynx implementation does not support the following Web features. - Vertical `orientation` - Keyboard arrow keys, Home/End, roving focus - RTL order and swipe direction reversal - `asChild` - `lazyMount`, `unmountOnExit` - Carousel's `loop`, `autoHeight`, `dragThreshold` - `carouselPreventDrag` - Content transition animation Lynx's native viewpager must maintain page slots, so Carousel content is not lazy unmounted.