Tabs
A tab list that keeps the selected tab in a signal, with one panel per tab.
Result
tabs.rs
use hypersig::html::p;
use hypersig::{Page, Signals};
use hypersig_ui::Tabs;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq)]
pub enum Section {
Account,
Password,
Billing,
}
#[derive(Signals, Serialize, Deserialize)]
pub struct Settings {
section: Section,
}
pub fn page() -> Page<Settings> {
let initial = Settings {
section: Section::Account,
};
Page::new(
"Settings",
initial,
)
.child(
Tabs::new(
"Settings",
Settings::section(),
)
.tab(
Section::Account,
"Account",
p().text("Change your name and email."),
)
.tab(
Section::Password,
"Password",
p().text("Passwords are at least twelve characters."),
)
.tab(
Section::Billing,
"Billing",
p().text("Invoices arrive on the first of each month."),
),
)
}Accessibility
It follows the WAI-ARIA tabs pattern. The list has role="tablist", each tab role="tab" with aria-selected and aria-controls, and each panel role="tabpanel" labeled by its tab. A tab is selected as it gains focus, through El::roving_focus. The ids are derived from the signal's path and the tab's position.
| Key | What it does |
|---|---|
| Tab | Moves focus into the list at the selected tab, then on to the panel. |
| Left, Right | Move to the previous or next tab and select it. |
| Home, End | Move to the first or last tab and select it. |