Navigation

Tabs

Organise content into switchable panels.

Rust
1use herogpui::components::tabs::{TabItem, Tabs};

Usage

Tab labels use a 20px line height independently of surrounding text.

Rust
1use herogpui::prelude::{TabItem, Tabs};
2use gpui::prelude::*;
3
4Tabs::new(
5    "tabs-usage",
6    vec![
7        TabItem::new("photos", "Photos")
8            .content(gpui::div().child("Your photo library.")),
9        TabItem::new("music", "Music")
10            .content(gpui::div().child("Playlists and albums.")),
11        TabItem::new("videos", "Videos")
12            .content(gpui::div().child("Everything you have filmed.")),
13    ],
14    "photos",
15)

Live HeroGPUI compiled to WebAssembly. Select any example without loading another WASM instance.

Anatomy

Rust types

TabsTabItem

Tabs is assembled from these builders. The API reference lists each one.

Customization

Appearance builders and theme tokens Tabs uses.

Styling

Tabs styling
StyleDescription
flex + gap(px(8)) + orientation layoutRoot orientation and spacing.
relative + default fill + radius_lg * 2.5Primary list tray.
raw overflow scroller; chevrons are measured but edge fades are absentScrollable viewport follows the configured axis without remapping wheel input from the other axis; fading overflow edges remain unavailable.
16px transparent occluding chevrons driven by ScrollHandle boundsPrevious and next overflow controls.
hover opacity snaps; no property interpolation or programmatic focus ringChevron interaction feedback.
flex_shrink_0 + p(px(4)) + horizontal min widthPrimary list sizing and inset.
flex_col + gap(px(4)) + min_w(px(80))Vertical list geometry.
32px height + 16px padding + control_radius + 14px medium textTab box and 14px typography with a fixed 20px line height.
state colors and opacity swap on a frameProperty interpolation between tab states.
segment foreground + indicator + adjacent separator motionSelected primary-tab styling.
hover(.. opacity(0.7))Pointer hover treatment in both variants.
with_focus_ringKeyboard focus treatment.
absolute hairline_radius + muted alpha 0.25 childSeparator ownership and fill.
border-width hairline with 50% or 90% relative spanOrientation-specific separator geometry.
SeparatorMotion + Curve::Smooth + reduce_motion snapSelection-adjacent separator fade.
w_full + p(px(8)) + 16px orientation marginActive panel size, inset and orientation spacing.
measured absolute child + segment fill + control_radius + surface shadowPrimary selected-segment surface.
IndicatorMotion + Curve::OutFluid + reduce_motion snapSelection indicator geometry motion.
border-only container + zero list inset + no separators + square tabsSecondary variant reset.
accent indicator without radius or shadowSecondary selection line.
orientation border + 2px indicator targetSecondary tray border and indicator axis.

API reference

Builders

Tabs builders
BuilderTypeDefaultDescription
variant(TabsVariant)TabsVariantTabsVariant::PrimaryVisual style variant: a filled segment or an underline.
orientation(Orientation)OrientationOrientation::HorizontalTab-list and panel layout orientation.
selected_key(key)keyControlled selected tab key.
default_selected_key(key)keyInitial selected key for uncontrolled tabs.
on_selection_change(callback)Fn(key: Key) -> ()Reports the selected key from tab activation.
new(key, label)key, labelUnique tab identifier and selection key.
is_disabled(bool)boolfalseRemoves one tab from pointer and roving-keyboard activation.

Parts

Tabs parts
PartDescription
TabsRoot flex container that orients the list and active panel.
TabsContainer owning the scroller and overflow chevrons.
TabsScrollable row or column and its shared roving focus handle.
TabItemOne keyed, selectable tab segment.
TabItemOptional pointer-inert hairline before a primary tab.
TabsMeasured filled pill or accent line following the selected tab.
TabItemContent associated with the selected tab key.

States

Tabs states
BuilderStateDescription
selected_key / active branchSelectedMoves the indicator and applies selected foreground styling.
hover(.. opacity(0.7))HoveredDims an enabled, unselected tab to 70% opacity.
with_focus_ring + focus_visibleFocus visibleDraws the shared roving stop's focus-visible ring.
is_disabled || item.is_disabledDisabledDims the tab and removes it from pointer and keyboard activation.
selected_key + on_selection_changeControlled selectionMoves roving focus and reports changes without mutating owner state.
default_selected_key + keyed selection stateUncontrolled selectionHolds selection and repairs it when the selected item disappears.