Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

TabView

A container that displays one panel at a time, selected by tab headers.

When To Use It

Use TabView when multiple related panels share the same area and users need quick switching between them (for example General/Audio/Advanced settings pages).

Constructing a TabView

TabView::new takes a list and a builder that returns TabPair for each item.

#[derive(Clone)]
struct SettingsTab {
	title: String,
}

let tabs = Signal::new(vec![
	SettingsTab { title: String::from("General") },
	SettingsTab { title: String::from("Audio") },
]);

TabView::new(cx, tabs, |_, _index, tab| {
	TabPair::new(
		move |cx| Label::new(cx, tab.title.clone()),
		move |cx| Label::new(cx, format!("{} content", tab.title)),
	)
})
.on_select(|cx, index| cx.emit(AppEvent::SelectTab(index)));

Vertical layout and externally controlled selection:

TabView::new(cx, tabs, |_, index, tab| {
	TabPair::new(
		move |cx| Label::new(cx, tab.title.clone()),
		move |cx| Label::new(cx, format!("Panel {}", index)),
	)
})
.vertical()
.with_selected(selected_tab_index);

TabView Modifiers

ModifierTypeDescriptionDefault
verticalfn vertical(self) -> SelfSwitches tab layout to vertical mode (no argument).horizontal
on_selectFn(&mut EventContext, usize)Called when selected tab changes.-
with_selectedimpl Res<impl Into<usize>>Programmatically sets selected tab index.0

Components and Styling

SelectorDescription
tabviewRoot tab view element.
tabview.verticalVertical orientation class on root.
tabview .tabview-headerHeader scroll area container.
tabview .tabview-content-wrapperActive panel content container.
tabheaderIndividual tab header item.
tabheader:checkedActive tab header state.
tabheader.verticalVertical tab header class.

Accessibility

  • Keep tab labels short and unique.
  • Track selected index in app state via on_select or with_selected.
  • Ensure focus order remains clear when switching tabs.