Skip to main content

Tabs

Struct Tabs 

Source
pub struct Tabs<S, T> { /* private fields */ }
Expand description

A tab list named label whose selection is the signal selected, with one panel per tab.

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. Tab enters the list at the selected tab, the arrow keys, Home, and End move between tabs, and 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.

use hypersig::Signals;
use hypersig::html::p;
use hypersig_ui::Tabs;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Clone, Copy, PartialEq)]
enum Section {
    Account,
    Password,
}

#[derive(Signals, Serialize, Deserialize)]
struct Settings {
    section: Section,
}

let tabs = Tabs::new("Settings", Settings::section())
    .tab(Section::Account, "Account", p().text("Your name and email."))
    .tab(Section::Password, "Password", p().text("Change your password."));
let html = tabs.render().render();
assert!(html.contains(r#"role="tablist""#));
assert!(html.contains(r#"aria-controls="ui-section-panel-1""#));

Implementations§

Source§

impl<S, T: Serialize + PartialEq> Tabs<S, T>

Source

pub fn new(label: impl Into<String>, selected: Sig<S, T>) -> Self

An empty tab list named label for assistive technology.

Source

pub fn tab(self, value: T, title: impl Into<String>, panel: El<S>) -> Self

Adds a tab titled title that selects value and shows panel.

Source

pub fn render(self) -> El<S>

The tab list followed by the panels, in a <div>.

Trait Implementations§

Source§

impl<S: Debug, T: Debug> Debug for Tabs<S, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S, T: Serialize + PartialEq> From<Tabs<S, T>> for El<S>

Source§

fn from(tabs: Tabs<S, T>) -> Self

Converts to this type from the input type.
Source§

impl<S, T: Serialize + PartialEq> From<Tabs<S, T>> for Node<S>

Source§

fn from(tabs: Tabs<S, T>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<S, T> Freeze for Tabs<S, T>

§

impl<S, T> RefUnwindSafe for Tabs<S, T>
where T: RefUnwindSafe,

§

impl<S, T> Send for Tabs<S, T>
where T: Send,

§

impl<S, T> Sync for Tabs<S, T>
where T: Sync,

§

impl<S, T> Unpin for Tabs<S, T>
where T: Unpin,

§

impl<S, T> UnsafeUnpin for Tabs<S, T>

§

impl<S, T> UnwindSafe for Tabs<S, T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.