Skip to main content

Listbox

Struct Listbox 

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

A list named label whose selected option is the signal selected.

It follows the WAI-ARIA listbox pattern for a single selection. The list has role="listbox" and each option role="option" with aria-selected. Tab enters the list at the selected option, or at the first where none is selected, and the arrow keys, Home, and End move between options through El::roving_focus, selecting each as it gains focus. The ids are derived from the signal’s path and the option’s position.

use hypersig::Signals;
use hypersig_ui::Listbox;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Clone, Copy, PartialEq)]
enum Plan {
    Hobby,
    Pro,
}

#[derive(Signals, Serialize, Deserialize)]
struct Billing {
    plan: Plan,
}

let plans = Listbox::new("Plan", Billing::plan())
    .option(Plan::Hobby, "Hobby")
    .option(Plan::Pro, "Pro");
let html = plans.render().render();
assert!(html.contains(r#"role="listbox""#));
assert!(html.contains(r#"id="ui-plan-option-1""#));

Implementations§

Source§

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

Source

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

An empty list named label for assistive technology.

Source

pub fn option(self, value: T, title: impl Into<String>) -> Self

Adds an option labeled title that selects value.

Source

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

The list and its options.

Trait Implementations§

Source§

impl<S: Debug, T: Debug> Debug for Listbox<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<Listbox<S, T>> for El<S>

Source§

fn from(listbox: Listbox<S, T>) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(listbox: Listbox<S, T>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

§

impl<S, T> UnwindSafe for Listbox<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.