Tabs

Splits content into panels and shows one at a time, picked from a row of tabs.

Invite people and choose their roles.

Usage

Code
import { Tabs } from '@leverui/components';
Code
<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.

Invite people and choose their roles.
Invite people and choose their roles.
Invite people and choose their roles.
Invite people and choose their roles.
Invite people and choose their roles.

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.

Tab 1: Content 0

Indicator

Render the Tabs.Indicator component to display a visual indicator of the active tab.

Invite people and choose their roles.

Custom Indicator

Customize the indicator appearance using CSS variables like --leverui-tabs-indicator-bg and --leverui-tabs-indicator-shadow.

Invite people and choose their roles.

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.

Invite people and choose their roles.

When using custom router links, you need to set the navigate prop on the Tabs.Root component.

Code
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.

First panel

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: members
Invite people and choose their roles.

Disabled 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.

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.

Invite people and choose their roles.

Animation

Use the data-state attribute in CSS to animate the tabs.

This panel fades and grows into place when it opens.

Guide

Styling active tab

The active tab has a data-selected attribute.

Code
<Tabs.Trigger class="active-blue" value="members">
  Tab
</Tabs.Trigger>
Code
.active-blue[data-selected] {
  background: var(--leverui-colors-blue-500);
  color: white;
}

Props

Root

PropDefaultTypeDescription
activationModeautomatic'manual' | 'automatic'automatic selects a tab on focus. manual selects on click or Enter.
loopFocustruebooleanWrap keyboard focus from the last tab to the first.
orientationhorizontal'horizontal' | 'vertical'Tabs in a row or a column. The arrow keys follow.
colorPalettegray'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink'Color palette.
sizemd'sm' | 'md' | 'lg'Tabs size. Responsive.
variantline'line' | 'subtle' | 'enclosed' | 'outline' | 'plain'Tabs style. Responsive.
asdivNative HTML tagHTML tag to render.
asChild—Solid render functionRender your own element with the root's props.
unstyledfalsebooleanTurn off the default styles.
virtualFocusfalsebooleanKeep browser focus off the triggers. Arrow keys move the focused value instead.
defaultValue—stringTab selected at first.
deselectable—booleanLet a click on the active tab deselect it.
id—stringUnique id for the tabs' state machine.
ids—Element ID mapIds of the tab elements.
lazyMountfalsebooleanRender a panel only once its tab is first selected.
navigate—(details: NavigateDetails) => voidCalled to go to the selected tab when the triggers are links.
onFocusChange—(details: FocusChangeDetails) => voidCalled when the focused tab changes.
onValueChange—(details: ValueChangeDetails) => voidCalled when the selected tab changes.
translations—IntlTranslationsTranslated strings for the accessibility elements.
unmountOnExitfalsebooleanRemove a panel from the page when its tab is deselected.
value—stringSelected tab. Controlled.
fitted—booleanStretch the tabs to fill their container. Responsive.
justify—'start' | 'center' | 'end'Where the tabs line up in the list. Responsive.

Trigger

PropDefaultTypeDescription
asbuttonNative HTML tagHTML tag to render.
asChild—Solid render functionRender your own element with the trigger's props.

Content

PropDefaultTypeDescription
asdivNative HTML tagHTML tag to render.
asChild—Solid render functionRender 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