Tabs
A component that divides content on one screen into tabs and switches between tabs by selection or left/right swipe.
<viewpager><viewpager-item>Installation
Install dependencies
Copy the code below and paste it in
Props
TabsRoot
Prop
Type
value?string | undefineddefaultValue?string | undefinedonValueChange?((value: string) => void) | undefinedstyle?CSSProperties | undefinedchildren?ReactNodeclassName?string | undefinedTabsList
Prop
Type
style?CSSProperties | undefinedchildren?ReactNodeclassName?string | undefinedmain-thread:bindbgload?EventHandler<BaseImageLoadEvent<Element>> | undefinedmain-thread:catchbgload?EventHandler<BaseImageLoadEvent<Element>> | undefinedmain-thread:capture-bindbgload?EventHandler<BaseImageLoadEvent<Element>> | undefinedmain-thread:capture-catchbgload?EventHandler<BaseImageLoadEvent<Element>> | undefinedmain-thread:global-bindbgload?EventHandler<BaseImageLoadEvent<Element>> | undefinedmain-thread:bindbgerror?EventHandler<BaseImageErrorEvent<Element>> | undefinedmain-thread:catchbgerror?EventHandler<BaseImageErrorEvent<Element>> | undefinedmain-thread:capture-bindbgerror?EventHandler<BaseImageErrorEvent<Element>> | undefinedmain-thread:capture-catchbgerror?EventHandler<BaseImageErrorEvent<Element>> | undefinedmain-thread:global-bindbgerror?EventHandler<BaseImageErrorEvent<Element>> | undefinedmain-thread:bindtouchstart?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:catchtouchstart?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:capture-bindtouchstart?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:capture-catchtouchstart?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:global-bindtouchstart?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:bindtouchmove?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:catchtouchmove?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:capture-bindtouchmove?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:capture-catchtouchmove?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:global-bindtouchmove?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:bindtouchcancel?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:catchtouchcancel?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:capture-bindtouchcancel?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:capture-catchtouchcancel?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:global-bindtouchcancel?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:bindtouchend?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:catchtouchend?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:capture-bindtouchend?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:capture-catchtouchend?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:global-bindtouchend?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:bindlongpress?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:catchlongpress?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:capture-bindlongpress?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:capture-catchlongpress?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:global-bindlongpress?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:bindtransitionstart?EventHandler<BaseTransitionEvent<Element>> | undefinedmain-thread:catchtransitionstart?EventHandler<BaseTransitionEvent<Element>> | undefinedmain-thread:capture-bindtransitionstart?EventHandler<BaseTransitionEvent<Element>> | undefinedmain-thread:capture-catchtransitionstart?EventHandler<BaseTransitionEvent<Element>> | undefinedmain-thread:global-bindtransitionstart?EventHandler<BaseTransitionEvent<Element>> | undefinedmain-thread:bindtransitioncancel?EventHandler<BaseTransitionEvent<Element>> | undefinedmain-thread:catchtransitioncancel?EventHandler<BaseTransitionEvent<Element>> | undefinedmain-thread:capture-bindtransitioncancel?EventHandler<BaseTransitionEvent<Element>> | undefinedmain-thread:capture-catchtransitioncancel?EventHandler<BaseTransitionEvent<Element>> | undefinedmain-thread:global-bindtransitioncancel?EventHandler<BaseTransitionEvent<Element>> | undefinedmain-thread:bindtransitionend?EventHandler<BaseTransitionEvent<Element>> | undefinedmain-thread:catchtransitionend?EventHandler<BaseTransitionEvent<Element>> | undefinedmain-thread:capture-bindtransitionend?EventHandler<BaseTransitionEvent<Element>> | undefinedmain-thread:capture-catchtransitionend?EventHandler<BaseTransitionEvent<Element>> | undefinedmain-thread:global-bindtransitionend?EventHandler<BaseTransitionEvent<Element>> | undefinedmain-thread:bindanimationstart?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:catchanimationstart?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:capture-bindanimationstart?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:capture-catchanimationstart?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:global-bindanimationstart?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:bindanimationiteration?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:catchanimationiteration?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:capture-bindanimationiteration?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:capture-catchanimationiteration?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:global-bindanimationiteration?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:bindanimationcancel?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:catchanimationcancel?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:capture-bindanimationcancel?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:capture-catchanimationcancel?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:global-bindanimationcancel?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:bindanimationend?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:catchanimationend?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:capture-bindanimationend?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:capture-catchanimationend?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:global-bindanimationend?EventHandler<BaseAnimationEvent<Element>> | undefinedmain-thread:bindmousedown?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:catchmousedown?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-bindmousedown?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-catchmousedown?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:global-bindmousedown?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:bindmouseup?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:catchmouseup?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-bindmouseup?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-catchmouseup?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:global-bindmouseup?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:bindmousemove?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:catchmousemove?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-bindmousemove?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-catchmousemove?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:global-bindmousemove?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:bindmouseenter?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:catchmouseenter?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-bindmouseenter?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-catchmouseenter?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:global-bindmouseenter?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:bindmouseleave?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:catchmouseleave?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-bindmouseleave?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-catchmouseleave?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:global-bindmouseleave?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:bindmouseclick?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:catchmouseclick?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-bindmouseclick?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-catchmouseclick?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:global-bindmouseclick?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:bindmousedblclick?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:catchmousedblclick?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-bindmousedblclick?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-catchmousedblclick?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:global-bindmousedblclick?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:bindmouselongpress?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:catchmouselongpress?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-bindmouselongpress?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-catchmouselongpress?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:global-bindmouselongpress?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:bindwheel?EventHandler<BaseWheelEvent<Element>> | undefinedmain-thread:catchwheel?EventHandler<BaseWheelEvent<Element>> | undefinedmain-thread:capture-bindwheel?EventHandler<BaseWheelEvent<Element>> | undefinedmain-thread:capture-catchwheel?EventHandler<BaseWheelEvent<Element>> | undefinedmain-thread:global-bindwheel?EventHandler<BaseWheelEvent<Element>> | undefinedmain-thread:bindzoom?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:catchzoom?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-bindzoom?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:capture-catchzoom?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:global-bindzoom?EventHandler<BaseMouseEvent<Element>> | undefinedmain-thread:bindkeydown?EventHandler<BaseKeyEvent<Element>> | undefinedmain-thread:catchkeydown?EventHandler<BaseKeyEvent<Element>> | undefinedmain-thread:capture-bindkeydown?EventHandler<BaseKeyEvent<Element>> | undefinedmain-thread:capture-catchkeydown?EventHandler<BaseKeyEvent<Element>> | undefinedmain-thread:global-bindkeydown?EventHandler<BaseKeyEvent<Element>> | undefinedmain-thread:bindkeyup?EventHandler<BaseKeyEvent<Element>> | undefinedmain-thread:catchkeyup?EventHandler<BaseKeyEvent<Element>> | undefinedmain-thread:capture-bindkeyup?EventHandler<BaseKeyEvent<Element>> | undefinedmain-thread:capture-catchkeyup?EventHandler<BaseKeyEvent<Element>> | undefinedmain-thread:global-bindkeyup?EventHandler<BaseKeyEvent<Element>> | undefinedmain-thread:bindfocus?EventHandler<BaseCommonEvent<Element>> | undefinedmain-thread:catchfocus?EventHandler<BaseCommonEvent<Element>> | undefinedmain-thread:capture-bindfocus?EventHandler<BaseCommonEvent<Element>> | undefinedmain-thread:capture-catchfocus?EventHandler<BaseCommonEvent<Element>> | undefinedmain-thread:global-bindfocus?EventHandler<BaseCommonEvent<Element>> | undefinedmain-thread:bindblur?EventHandler<BaseCommonEvent<Element>> | undefinedmain-thread:catchblur?EventHandler<BaseCommonEvent<Element>> | undefinedmain-thread:capture-bindblur?EventHandler<BaseCommonEvent<Element>> | undefinedmain-thread:capture-catchblur?EventHandler<BaseCommonEvent<Element>> | undefinedmain-thread:global-bindblur?EventHandler<BaseCommonEvent<Element>> | undefinedmain-thread:bindlayoutchange?EventHandler<LayoutChangeDetailEvent<Element>> | undefinedmain-thread:catchlayoutchange?EventHandler<LayoutChangeDetailEvent<Element>> | undefinedmain-thread:capture-bindlayoutchange?EventHandler<LayoutChangeDetailEvent<Element>> | undefinedmain-thread:capture-catchlayoutchange?EventHandler<LayoutChangeDetailEvent<Element>> | undefinedmain-thread:global-bindlayoutchange?EventHandler<LayoutChangeDetailEvent<Element>> | undefinedmain-thread:binduiappear?EventHandler<UIAppearanceDetailEvent<Element>> | undefinedmain-thread:catchuiappear?EventHandler<UIAppearanceDetailEvent<Element>> | undefinedmain-thread:capture-binduiappear?EventHandler<UIAppearanceDetailEvent<Element>> | undefinedmain-thread:capture-catchuiappear?EventHandler<UIAppearanceDetailEvent<Element>> | undefinedmain-thread:global-binduiappear?EventHandler<UIAppearanceDetailEvent<Element>> | undefinedmain-thread:binduidisappear?EventHandler<UIAppearanceDetailEvent<Element>> | undefinedmain-thread:catchuidisappear?EventHandler<UIAppearanceDetailEvent<Element>> | undefinedmain-thread:capture-binduidisappear?EventHandler<UIAppearanceDetailEvent<Element>> | undefinedmain-thread:capture-catchuidisappear?EventHandler<UIAppearanceDetailEvent<Element>> | undefinedmain-thread:global-binduidisappear?EventHandler<UIAppearanceDetailEvent<Element>> | undefinedmain-thread:bindaccessibilityaction?EventHandler<AccessibilityActionDetailEvent<Element>> | undefinedmain-thread:catchaccessibilityaction?EventHandler<AccessibilityActionDetailEvent<Element>> | undefinedmain-thread:capture-bindaccessibilityaction?EventHandler<AccessibilityActionDetailEvent<Element>> | undefinedmain-thread:capture-catchaccessibilityaction?EventHandler<AccessibilityActionDetailEvent<Element>> | undefinedmain-thread:global-bindaccessibilityaction?EventHandler<AccessibilityActionDetailEvent<Element>> | undefinedmain-thread:bindtap?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:catchtap?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:capture-bindtap?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:capture-catchtap?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:global-bindtap?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:bindlongtap?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:catchlongtap?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:capture-bindlongtap?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:capture-catchlongtap?EventHandler<BaseTouchEvent<Element>> | undefinedmain-thread:global-bindlongtap?EventHandler<BaseTouchEvent<Element>> | undefinedTabsTrigger
Prop
Type
notification?boolean | undefineddisabled?boolean | undefinedclassName?string | undefinedbindtap?EventHandler<BaseTouchEvent<Target>> | undefinedchildrenstring | numberstyle?CSSProperties | undefinedaccessibility-label?string | undefinedvaluestringTabsCarousel
Prop
Type
swipeable?boolean | undefinedonSettle?(() => void) | undefinedstyle?CSSProperties | undefinedchildren?ReactNodeclassName?string | undefinedTabsContent
Prop
Type
valuestringstyle?CSSProperties | undefinedchildren?ReactNodeclassName?string | undefinedUsage
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 <viewpager>. 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)
Layout Hug
Size Medium
Size Small (Default)
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.
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.
Notification
Sticky List
Use when tabs take up the entire screen and TabsList needs to be fixed at the top of the screen.
Standalone
Use when not using TabsContent and composing the content area directly.
In this configuration, the swipe functionality provided by Tabs cannot be used.
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.
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.
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 <viewpager> |
| Horizontal List | CSS overflow | Native <scroll-view> |
| 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
asChildlazyMount,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.