Biji UI

Tabs

A set of layered panels that display one at a time, activated by corresponding tab triggers.

Update your profile details.

Installation

biji-ui = { version = "0.5.0", features = ["tabs"] }

Usage

use leptos::prelude::*;
use biji_ui::components::tabs;

#[component]
pub fn MyTabs() -> impl IntoView {
    view! {
        <tabs::Root default_value="account" class="w-full max-w-md">
            <tabs::List class="flex border-b border-border">
                <tabs::Trigger
                    value="account"
                    class="px-4 py-2 text-sm font-medium border-b-2 -mb-px data-[state=active]:border-primary data-[state=inactive]:border-transparent"
                >
                    "Account"
                </tabs::Trigger>
                <tabs::Trigger
                    value="password"
                    class="px-4 py-2 text-sm font-medium border-b-2 -mb-px data-[state=active]:border-primary data-[state=inactive]:border-transparent"
                >
                    "Password"
                </tabs::Trigger>
            </tabs::List>
            <tabs::Content value="account" class="p-4 text-sm">
                "Manage your account settings here."
            </tabs::Content>
            <tabs::Content value="password" class="p-4 text-sm">
                "Change your password here."
            </tabs::Content>
        </tabs::Root>
    }
}

RootWith

Use RootWith to access TabsState inline via the let: binding — useful for driving external UI from the active tab value.

Active: account

Manage your account settings here.
use leptos::prelude::*;
use biji_ui::components::tabs;

#[component]
pub fn MyTabs() -> impl IntoView {
    view! {
        <tabs::RootWith default_value="account" class="w-full max-w-md" let:t>
            <p class="mb-2 text-sm text-muted-foreground">
                {move || format!("Active tab: {}", t.value.get().unwrap_or_default())}
            </p>
            <tabs::List class="flex border-b border-border">
                <tabs::Trigger
                    value="account"
                    class="px-4 py-2 text-sm font-medium border-b-2 -mb-px data-[state=active]:border-primary data-[state=inactive]:border-transparent"
                >
                    "Account"
                </tabs::Trigger>
                <tabs::Trigger
                    value="password"
                    class="px-4 py-2 text-sm font-medium border-b-2 -mb-px data-[state=active]:border-primary data-[state=inactive]:border-transparent"
                >
                    "Password"
                </tabs::Trigger>
            </tabs::List>
            <tabs::Content value="account" class="p-4 text-sm">
                "Manage your account settings here."
            </tabs::Content>
            <tabs::Content value="password" class="p-4 text-sm">
                "Change your password here."
            </tabs::Content>
        </tabs::RootWith>
    }
}

API Reference

Root / RootWith

NameTypeDefaultDescription
classString""CSS class applied to the root wrapper element.
valueOption<String>NoneThe initially active tab value.
orientationOrientationHorizontalThe axis along which tabs are arranged.
activation_modeActivationModeAutomaticWhether arrow key navigation also activates tabs (Automatic) or only moves focus (Manual).
on_value_changeOption<Callback<String>>NoneCallback fired when the active tab changes.

List

NameTypeDefaultDescription
classString""CSS class applied to the tab list element.

Trigger

NameTypeDefaultDescription
valueString The value this tab trigger activates.
classString""CSS class applied to the tab trigger button.
disabledboolfalseWhen true, the tab cannot be activated.

Content

NameTypeDefaultDescription
valueString The tab value whose panel this renders.
classString""CSS class applied to the tab panel element.

Orientation

NameTypeDefaultDescription
HorizontalOrientationdefaultTabs are arranged left-to-right. Arrow Left/Right navigates.
VerticalOrientation Tabs are arranged top-to-bottom. Arrow Up/Down navigates.

ActivationMode

NameTypeDefaultDescription
AutomaticActivationModedefaultArrow key navigation both moves focus and activates the tab.
ManualActivationMode Arrow key navigation only moves focus; Enter or Space activates the tab.

Data Attributes

AttributeDescription
data-state"active" when the tab is selected; "inactive" otherwise. Present on Trigger and Content.
data-disabledPresent on Trigger when the tab is disabled.
data-orientation"horizontal" or "vertical". Present on Root, Trigger, and Content.

Keyboard Navigation

KeyDescription
ArrowRight / ArrowDownMoves focus to the next tab (ArrowRight for horizontal, ArrowDown for vertical). Activates it in Automatic mode.
ArrowLeft / ArrowUpMoves focus to the previous tab. Activates it in Automatic mode.
HomeMoves focus to the first tab. Activates it in Automatic mode.
EndMoves focus to the last tab. Activates it in Automatic mode.
Enter / SpaceActivates the focused tab (primarily useful in Manual activation mode).