Tabs
Flexible navigation tool with various modes and features.
Flexible navigation tool with various modes and features.
To set up the tabs correctly, you’ll need to understand its anatomy and how we name its parts.
Each part includes a
data-part
attribute to help identify them in the DOM.
Learn how to use the Tabs
component in your project. Let’s take a look at the
most basic example:
import { Tabs } from '@ark-ui/react'
const Basic = () => (
<Tabs.Root>
<Tabs.List>
<Tabs.Trigger value="react">React</Tabs.Trigger>
<Tabs.Trigger value="vue">Vue</Tabs.Trigger>
<Tabs.Trigger value="solid">Solid</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="react">React Content</Tabs.Content>
<Tabs.Content value="vue">Vue Content</Tabs.Content>
<Tabs.Content value="solid">Solid Content</Tabs.Content>
</Tabs.Root>
)
import { Tabs } from '@ark-ui/solid'
const Basic = () => (
<Tabs.Root>
<Tabs.List>
<Tabs.Trigger value="react">React</Tabs.Trigger>
<Tabs.Trigger value="vue">Vue</Tabs.Trigger>
<Tabs.Trigger value="solid">Solid</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="react">React Content</Tabs.Content>
<Tabs.Content value="vue">Vue Content</Tabs.Content>
<Tabs.Content value="solid">Solid Content</Tabs.Content>
</Tabs.Root>
)
<script setup lang="ts">
import { ref } from 'vue'
import { Tabs } from '@ark-ui/vue'
const value = ref('react')
</script>
<template>
<Tabs.Root>
<Tabs.List>
<Tabs.Trigger value="react">React</Tabs.Trigger>
<Tabs.Trigger value="vue">Vue</Tabs.Trigger>
<Tabs.Trigger value="solid">Solid</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="react">React Content</Tabs.Content>
<Tabs.Content value="vue">Vue Content</Tabs.Content>
<Tabs.Content value="solid">Solid Content</Tabs.Content>
</Tabs.Root>
</template>
To set a default tab on initial render, use the defaultValue
prop:
import { Tabs } from '@ark-ui/react'
const InitialTab = () => (
<Tabs.Root defaultValue="react">
<Tabs.List>
<Tabs.Trigger value="react">React</Tabs.Trigger>
<Tabs.Trigger value="vue">Vue</Tabs.Trigger>
<Tabs.Trigger value="solid">Solid</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="react">React Content</Tabs.Content>
<Tabs.Content value="vue">Vue Content</Tabs.Content>
<Tabs.Content value="solid">Solid Content</Tabs.Content>
</Tabs.Root>
)
import { Tabs } from '@ark-ui/solid'
const InitialTab = () => (
<Tabs.Root value="react">
<Tabs.List>
<Tabs.Trigger value="react">React</Tabs.Trigger>
<Tabs.Trigger value="vue">Vue</Tabs.Trigger>
<Tabs.Trigger value="solid">Solid</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="react">React Content</Tabs.Content>
<Tabs.Content value="vue">Vue Content</Tabs.Content>
<Tabs.Content value="solid">Solid Content</Tabs.Content>
</Tabs.Root>
)
<script setup lang="ts">
import { ref } from 'vue'
import { Tabs } from '@ark-ui/vue'
const value = ref('react')
</script>
<template>
<Tabs.Root v-model="value">
<Tabs.List>
<Tabs.Trigger value="react">React</Tabs.Trigger>
<Tabs.Trigger value="vue">Vue</Tabs.Trigger>
<Tabs.Trigger value="solid">Solid</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="react">React Content</Tabs.Content>
<Tabs.Content value="vue">Vue Content</Tabs.Content>
<Tabs.Content value="solid">Solid Content</Tabs.Content>
</Tabs.Root>
</template>
To provide a visual cue for the selected tab, use the Tabs.Indicator
component:
import { Tabs } from '@ark-ui/react'
const Indicator = () => (
<Tabs.Root>
<Tabs.List>
<Tabs.Trigger value="react">React</Tabs.Trigger>
<Tabs.Trigger value="vue">Vue</Tabs.Trigger>
<Tabs.Trigger value="solid">Solid</Tabs.Trigger>
<Tabs.Indicator />
</Tabs.List>
<Tabs.Content value="react">React Content</Tabs.Content>
<Tabs.Content value="vue">Vue Content</Tabs.Content>
<Tabs.Content value="solid">Solid Content</Tabs.Content>
</Tabs.Root>
)
import { Tabs } from '@ark-ui/solid'
const Indicator = () => (
<Tabs.Root>
<Tabs.List>
<Tabs.Trigger value="react">React</Tabs.Trigger>
<Tabs.Trigger value="vue">Vue</Tabs.Trigger>
<Tabs.Trigger value="solid">Solid</Tabs.Trigger>
<Tabs.Indicator />
</Tabs.List>
<Tabs.Content value="react">React Content</Tabs.Content>
<Tabs.Content value="vue">Vue Content</Tabs.Content>
<Tabs.Content value="solid">Solid Content</Tabs.Content>
</Tabs.Root>
)
<script setup lang="ts">
import { ref } from 'vue'
import { Tabs } from '@ark-ui/vue'
const value = ref('react')
</script>
<template>
<Tabs.Root>
<Tabs.List>
<Tabs.Trigger value="react">React</Tabs.Trigger>
<Tabs.Trigger value="vue">Vue</Tabs.Trigger>
<Tabs.Trigger value="solid">Solid</Tabs.Trigger>
<Tabs.Indicator />
</Tabs.List>
<Tabs.Content value="react">React Content</Tabs.Content>
<Tabs.Content value="vue">Vue Content</Tabs.Content>
<Tabs.Content value="solid">Solid Content</Tabs.Content>
</Tabs.Root>
</template>
Lazy mounting is a feature that allows the content of a tab to be rendered only
when the tab is first activated. This is useful for performance optimization,
especially when tab content is large or complex. To enable lazy mounting, use
the lazyMount
prop on the Tabs.Content
component.
In addition, the unmountOnExit
prop can be used in conjunction with
lazyMount
to unmount the tab content when the tab is deactivated, freeing up
resources. The next time the tab is activated, its content will be re-rendered.
import { Tabs } from '@ark-ui/react'
const LazyMount = () => (
<Tabs.Root lazyMount unmountOnExit>
<Tabs.List>
<Tabs.Trigger value="react">React</Tabs.Trigger>
<Tabs.Trigger value="vue">Vue</Tabs.Trigger>
<Tabs.Trigger value="solid">Solid</Tabs.Trigger>
<Tabs.Indicator />
</Tabs.List>
<Tabs.Content value="react">React Content</Tabs.Content>
<Tabs.Content value="vue">Vue Content</Tabs.Content>
<Tabs.Content value="solid">Solid Content</Tabs.Content>
</Tabs.Root>
)
import { Tabs } from '@ark-ui/solid'
const LazyMount = () => (
<Tabs.Root lazyMount unmountOnExit>
<Tabs.List>
<Tabs.Trigger value="react">React</Tabs.Trigger>
<Tabs.Trigger value="vue">Vue</Tabs.Trigger>
<Tabs.Trigger value="solid">Solid</Tabs.Trigger>
<Tabs.Indicator />
</Tabs.List>
<Tabs.Content value="react">React Content</Tabs.Content>
<Tabs.Content value="vue">Vue Content</Tabs.Content>
<Tabs.Content value="solid">Solid Content</Tabs.Content>
</Tabs.Root>
)
<script setup lang="ts">
import { ref } from 'vue'
import { Tabs } from '@ark-ui/vue'
const value = ref('react')
</script>
<template>
<Tabs.Root lazyMount unmountOnExit>
<Tabs.List>
<Tabs.Trigger value="react">React</Tabs.Trigger>
<Tabs.Trigger value="vue">Vue</Tabs.Trigger>
<Tabs.Trigger value="solid">Solid</Tabs.Trigger>
<Tabs.Indicator />
</Tabs.List>
<Tabs.Content value="react">React Content</Tabs.Content>
<Tabs.Content value="vue">Vue Content</Tabs.Content>
<Tabs.Content value="solid">Solid Content</Tabs.Content>
</Tabs.Root>
</template>
To disable a tab, simply pass the disabled
prop to the Tabs.Trigger
component:
import { Tabs } from '@ark-ui/react'
const DisabledTab = () => (
<Tabs.Root defaultValue="react">
<Tabs.List>
<Tabs.Trigger value="react">React</Tabs.Trigger>
<Tabs.Trigger value="vue" disabled>
Vue
</Tabs.Trigger>
<Tabs.Trigger value="solid">Solid</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="react">React Content</Tabs.Content>
<Tabs.Content value="vue">Vue Content</Tabs.Content>
<Tabs.Content value="solid">Solid Content</Tabs.Content>
</Tabs.Root>
)
import { Tabs } from '@ark-ui/solid'
const DisabledTab = () => (
<Tabs.Root value="react">
<Tabs.List>
<Tabs.Trigger value="react">React</Tabs.Trigger>
<Tabs.Trigger value="vue" disabled>
Vue
</Tabs.Trigger>
<Tabs.Trigger value="solid">Solid</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="react">React Content</Tabs.Content>
<Tabs.Content value="vue">Vue Content</Tabs.Content>
<Tabs.Content value="solid">Solid Content</Tabs.Content>
</Tabs.Root>
)
<script setup lang="ts">
import { ref } from 'vue'
import { Tabs } from '@ark-ui/vue'
const value = ref('react')
</script>
<template>
<Tabs.Root defaultValue="react">
<Tabs.List>
<Tabs.Trigger value="react">React</Tabs.Trigger>
<Tabs.Trigger value="vue" disabled>Vue</Tabs.Trigger>
<Tabs.Trigger value="solid">Solid</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="react">React Content</Tabs.Content>
<Tabs.Content value="vue">Vue Content</Tabs.Content>
<Tabs.Content value="solid">Solid Content</Tabs.Content>
</Tabs.Root>
</template>
To create a controlled Tabs component, manage the current selected tab using the
value
prop and update it when the onValueChange
event handler is called:
import { Tabs } from '@ark-ui/react'
import { useState } from 'react'
const Controlled = () => {
const [value, setValue] = useState<string | null>('react')
return (
<Tabs.Root value={value} onValueChange={(e) => setValue(e.value)}>
<Tabs.List>
<Tabs.Trigger value="react">React</Tabs.Trigger>
<Tabs.Trigger value="vue">Vue</Tabs.Trigger>
<Tabs.Trigger value="solid">Solid</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="react">React Content</Tabs.Content>
<Tabs.Content value="vue">Vue Content</Tabs.Content>
<Tabs.Content value="solid">Solid Content</Tabs.Content>
</Tabs.Root>
)
}
import { Tabs } from '@ark-ui/solid'
import { createSignal } from 'solid-js'
const Controlled = () => {
const [value, setValue] = createSignal<string | null>('react')
return (
<Tabs.Root value={value()} onValueChange={(e) => setValue(e.value)}>
<Tabs.List>
<Tabs.Trigger value="react">React</Tabs.Trigger>
<Tabs.Trigger value="vue">Vue</Tabs.Trigger>
<Tabs.Trigger value="solid">Solid</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="react">React Content</Tabs.Content>
<Tabs.Content value="vue">Vue Content</Tabs.Content>
<Tabs.Content value="solid">Solid Content</Tabs.Content>
</Tabs.Root>
)
}
<script setup lang="ts">
import { ref } from 'vue'
import { Tabs } from '@ark-ui/vue'
const value = ref('react')
</script>
<template>
<Tabs.Root v-model="value">
<Tabs.List>
<Tabs.Trigger value="react">React</Tabs.Trigger>
<Tabs.Trigger value="vue">Vue</Tabs.Trigger>
<Tabs.Trigger value="solid">Solid</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="react">React Content</Tabs.Content>
<Tabs.Content value="vue">Vue Content</Tabs.Content>
<Tabs.Content value="solid">Solid Content</Tabs.Content>
</Tabs.Root>
</template>
When using frameworks like Next.js, Remix, or React Router, controlling the active tabs based on the URL can be useful.
To achieve this, you need to do two things:
value
prop to the current URL path.onValueChange
event and update the URL path.Here’s an example using Remix Router
import { Tabs } from '@ark-ui/react/tabs'
import { useLocation, useNavigate, Link } from '@remix-run/react'
export default function App() {
const { pathname } = useLocation()
const navigate = useNavigate()
const lastPathFragment = pathname.substring(pathname.lastIndexOf('/') + 1)
const activeTab = lastPathFragment.length > 0 ? lastPathFragment : 'homepage'
return (
<Tabs.Root
value={activeTab}
onValueChange={({ value }) => {
navigate(`/${value === 'home' ? '' : value}`)
}}
>
<Tabs.List>
<Tabs.Trigger asChild value="home">
<Link to="">Home</Link>
</Tabs.Trigger>
<Tabs.Trigger asChild value="page-1">
<Link to="page-1">Page 1</Link>
</Tabs.Trigger>
<Tabs.Trigger asChild value="page-2">
<Link to="page-2">Page 2</Link>
</Tabs.Trigger>
</Tabs.List>
</Tabs.Root>
)
}
The default orientation of the tabs is horizontal
. To change the orientation,
set the orientation
prop to vertical
.
import { Tabs } from '@ark-ui/react'
const Vertical = () => (
<Tabs.Root orientation="vertical" defaultValue="react">
<Tabs.List>
<Tabs.Trigger value="react">React</Tabs.Trigger>
<Tabs.Trigger value="vue">Vue</Tabs.Trigger>
<Tabs.Trigger value="solid">Solid</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="react">React Content</Tabs.Content>
<Tabs.Content value="vue">Vue Content</Tabs.Content>
<Tabs.Content value="solid">Solid Content</Tabs.Content>
</Tabs.Root>
)
import { Tabs } from '@ark-ui/solid'
const Vertical = () => (
<Tabs.Root orientation="vertical" value="react">
<Tabs.List>
<Tabs.Trigger value="react">React</Tabs.Trigger>
<Tabs.Trigger value="vue">Vue</Tabs.Trigger>
<Tabs.Trigger value="solid">Solid</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="react">React Content</Tabs.Content>
<Tabs.Content value="vue">Vue Content</Tabs.Content>
<Tabs.Content value="solid">Solid Content</Tabs.Content>
</Tabs.Root>
)
<script setup lang="ts">
import { ref } from 'vue'
import { Tabs } from '@ark-ui/vue'
const value = ref('react')
</script>
<template>
<Tabs.Root v-model="value" orientation="vertical">
<Tabs.List>
<Tabs.Trigger value="react">React</Tabs.Trigger>
<Tabs.Trigger value="vue">Vue</Tabs.Trigger>
<Tabs.Trigger value="solid">Solid</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="react">React Content</Tabs.Content>
<Tabs.Content value="vue">Vue Content</Tabs.Content>
<Tabs.Content value="solid">Solid Content</Tabs.Content>
</Tabs.Root>
</template>
By default, the tab can be selected when it receives focus from either the keyboard or pointer interaction. This is called automatic tab activation.
In contrast, manual tab activation means the tab is selected with the
Enter key or by clicking on the tab.
import { Tabs } from '@ark-ui/react'
const Manual = () => (
<Tabs.Root activationMode="manual" defaultValue="react">
<Tabs.List>
<Tabs.Trigger value="react">React</Tabs.Trigger>
<Tabs.Trigger value="vue">Vue</Tabs.Trigger>
<Tabs.Trigger value="solid">Solid</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="react">React Content</Tabs.Content>
<Tabs.Content value="vue">Vue Content</Tabs.Content>
<Tabs.Content value="solid">Solid Content</Tabs.Content>
</Tabs.Root>
)
import { Tabs } from '@ark-ui/solid'
const Manual = () => (
<Tabs.Root activationMode="manual" value="react">
<Tabs.List>
<Tabs.Trigger value="react">React</Tabs.Trigger>
<Tabs.Trigger value="vue">Vue</Tabs.Trigger>
<Tabs.Trigger value="solid">Solid</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="react">React Content</Tabs.Content>
<Tabs.Content value="vue">Vue Content</Tabs.Content>
<Tabs.Content value="solid">Solid Content</Tabs.Content>
</Tabs.Root>
)
<script setup lang="ts">
import { ref } from 'vue'
import { Tabs } from '@ark-ui/vue'
const value = ref('react')
</script>
<template>
<Tabs.Root v-model="value" activationMode="manual">
<Tabs.List>
<Tabs.Trigger value="react">React</Tabs.Trigger>
<Tabs.Trigger value="vue">Vue</Tabs.Trigger>
<Tabs.Trigger value="solid">Solid</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="react">React Content</Tabs.Content>
<Tabs.Content value="vue">Vue Content</Tabs.Content>
<Tabs.Content value="solid">Solid Content</Tabs.Content>
</Tabs.Root>
</template>
asChild Render as a different element type. | boolean |
activationMode The activation mode of the tabs. Can be `manual` or `automatic` - `manual`: Tabs are activated when clicked or press `enter` key. - `automatic`: Tabs are activated when receiving focus | 'manual' | 'automatic' | "automatic" |
asChild Render as a different element type. | boolean | |
defaultValue The initial value of the tabs. | string | |
dir The document's text/writing direction. | 'ltr' | 'rtl' | "ltr" |
getRootNode A root node to correctly resolve document in custom environments. E.x.: Iframes, Electron. | () => Node | ShadowRoot | Document | |
id The unique identifier of the machine. | string | |
ids The ids of the elements in the tabs. Useful for composition. | Partial<{
root: string
trigger: string
tablist: string
content: string
indicator: string
}> | |
lazyMount Whether to enable lazy mounting | boolean | false |
loop Whether the keyboard navigation will loop from last tab to first, and vice versa. | boolean | true |
onExitComplete Function called when the animation ends in the closed state. | () => void | |
onFocusChange Callback to be called when the focused tab changes | (details: FocusChangeDetails) => void | |
onValueChange Callback to be called when the selected/active tab changes | (details: ValueChangeDetails) => void | |
orientation The orientation of the tabs. Can be `horizontal` or `vertical` - `horizontal`: only left and right arrow key navigation will work. - `vertical`: only up and down arrow key navigation will work. | 'horizontal' | 'vertical' | "horizontal" |
present Whether the node is present (controlled by the user) | boolean | |
translations Specifies the localized strings that identifies the accessibility elements and their states | IntlTranslations | |
unmountOnExit Whether to unmount on exit. | boolean | false |
value The selected tab id | string |
value | string | |
asChild Render as a different element type. | boolean |
value | string | |
asChild Render as a different element type. | boolean | |
disabled | boolean |
asChild Render as a different element type. | boolean |
Previous
SwitchNext
Tags Input