Tabs
Splits content into panels and shows one at a time, picked from a row of tabs.
Usage
import { Tabs } from '@leverui/components';
<Tabs.Root>
<Tabs.List>
<Tabs.Trigger />
<Tabs.Indicator />
</Tabs.List>
<Tabs.Content />
</Tabs.Root>
Examples
Variants
Use the variant prop to change the visual style of the tabs.
Lazy Mounted
Use the lazyMount and/or unmountOnExit prop to only render the tab content when it is active. This can be useful for performance optimization.
Indicator
Render the Tabs.Indicator component to display a visual indicator of the active tab.
Custom Indicator
Customize the indicator appearance using CSS variables like --leverui-tabs-indicator-bg and --leverui-tabs-indicator-shadow.
Links
Pass the asChild to the Tabs.Trigger component to render a link as a tab. When a tab is clicked, the link will be navigated to.
When using custom router links, you need to set the navigate prop on the Tabs.Root component.
import { Tabs } from '@leverui/components';
import { useNavigate } from '@solidjs/router';
/** Send each tab change through the application router. */
function Demo() {
const navigate = useNavigate();
return <Tabs.Root navigate={({ value }) => navigate(`/${value}`)}>{/* ... */}</Tabs.Root>;
}
Fitted
Use the fitted prop to make the tabs fit the width of the container.
Controlled
Use the value and onValueChange prop to control the active tab.
Store
An alternative way to control the tabs is to use the RootProvider component and the useTabs store function. This way you can access the tabs state and methods from outside the tabs.
selected: membersDisabled Tab
Set the disabled prop on the Tabs.Trigger component to disable a tab.
Manual activation
By default, the tabs are selected when the arrow keys are pressed. Disable this behavior by setting the activationMode prop to manual. In this mode, the tabs will only be selected when clicked or the enter key is pressed.
Dynamic
Here's an example of how to dynamically add and remove tabs.
Tab content 1
Each tab here has its own panel. Press the plus button to add a tab, and it opens straight away. Press the small close button on a tab to remove it. You cannot remove the last tab, so there is always one panel to show.
Tab content 2
Each tab here has its own panel. Press the plus button to add a tab, and it opens straight away. Press the small close button on a tab to remove it. You cannot remove the last tab, so there is always one panel to show.
Tab content 3
Each tab here has its own panel. Press the plus button to add a tab, and it opens straight away. Press the small close button on a tab to remove it. You cannot remove the last tab, so there is always one panel to show.
Tab content 4
Each tab here has its own panel. Press the plus button to add a tab, and it opens straight away. Press the small close button on a tab to remove it. You cannot remove the last tab, so there is always one panel to show.
Responsive Orientation
Responsive values are not supported for the orientation prop because it affects keyboard navigation and aria-orientation behavior, not just styling. The orientation changes how arrow keys work (horizontal uses left/right, vertical uses up/down). To achieve responsive orientation, use the useBreakpointValue function to change the orientation based on the screen size.
Animation
Use the data-state attribute in CSS to animate the tabs.
Guide
Styling active tab
The active tab has a data-selected attribute.
<Tabs.Trigger class="active-blue" value="members">
Tab
</Tabs.Trigger>
.active-blue[data-selected] {
background: var(--leverui-colors-blue-500);
color: white;
}
Props
Root
| Prop | Default | Type | Description |
|---|---|---|---|
activationMode | automatic | 'manual' | 'automatic' | automatic selects a tab on focus. manual selects on click or Enter. |
loopFocus | true | boolean | Wrap keyboard focus from the last tab to the first. |
orientation | horizontal | 'horizontal' | 'vertical' | Tabs in a row or a column. The arrow keys follow. |
colorPalette | gray | 'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | Color palette. |
size | md | 'sm' | 'md' | 'lg' | Tabs size. Responsive. |
variant | line | 'line' | 'subtle' | 'enclosed' | 'outline' | 'plain' | Tabs style. Responsive. |
as | div | Native HTML tag | HTML tag to render. |
asChild | — | Solid render function | Render your own element with the root's props. |
unstyled | false | boolean | Turn off the default styles. |
virtualFocus | false | boolean | Keep browser focus off the triggers. Arrow keys move the focused value instead. |
defaultValue | — | string | Tab selected at first. |
deselectable | — | boolean | Let a click on the active tab deselect it. |
id | — | string | Unique id for the tabs' state machine. |
ids | — | Element ID map | Ids of the tab elements. |
lazyMount | false | boolean | Render a panel only once its tab is first selected. |
navigate | — | (details: NavigateDetails) => void | Called to go to the selected tab when the triggers are links. |
onFocusChange | — | (details: FocusChangeDetails) => void | Called when the focused tab changes. |
onValueChange | — | (details: ValueChangeDetails) => void | Called when the selected tab changes. |
translations | — | IntlTranslations | Translated strings for the accessibility elements. |
unmountOnExit | false | boolean | Remove a panel from the page when its tab is deselected. |
value | — | string | Selected tab. Controlled. |
fitted | — | boolean | Stretch the tabs to fill their container. Responsive. |
justify | — | 'start' | 'center' | 'end' | Where the tabs line up in the list. Responsive. |
Trigger
| Prop | Default | Type | Description |
|---|---|---|---|
as | button | Native HTML tag | HTML tag to render. |
asChild | — | Solid render function | Render your own element with the trigger's props. |
Content
| Prop | Default | Type | Description |
|---|---|---|---|
as | div | Native HTML tag | HTML tag to render. |
asChild | — | Solid render function | Render your own element with the panel's props. |
Each trigger value must match the value of one content panel. Give each tab
list a label. Keep keyboard directions consistent with the orientation. With
activationMode="manual", focus moves first and the tab is selected
afterwards, which helps when a panel is slow to load.
size, variant, fitted, and justify also take an object, or an array
with gaps, that sets a value at the base, sm, md, lg, xl, and 2xl
breakpoints. They are applied with CSS, so they work on a static page.
Examples: size={{ base: 'sm', md: 'lg' }},
fitted={{ base: true, md: false }}. Without base, the tabs start from the
default.
Customize with CSS
Override the --leverui-* theme variables, such as
--leverui-tabs-indicator-bg, --leverui-tabs-indicator-shadow, and
--leverui-tabs-trigger-radius, or style the .leverui-tabs__* part classes.
Every part accepts class and style. unstyled on the root or a single part
turns off its default styles.
Explorer
Click a part name to highlight it in the preview.
Component Anatomy
Hover to highlight, click to select parts