日本語

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.

KeyWhat it does
TabMoves focus into the list at the selected tab, then on to the panel.
Left, RightMove to the previous or next tab and select it.
Home, EndMove to the first or last tab and select it.

API

ItemSummary
Tabs::newAn empty tab list named label for assistive technology.
tabAdds a tab titled title that selects value and shows panel.