Skip to main content

toggle

Function toggle 

Source
pub fn toggle<S, R: Writable>(pressed: Sig<S, bool, R>) -> El<S>
Expand description

A button that is pressed while pressed is true, and flips it when clicked.

It is a native <button> with aria-pressed, so a screen reader announces it as a toggle button that is pressed or not pressed, and Enter and Space flip it. Keep its text the same in both states, since the state is announced on its own. It needs no id, so it works on a field of a list item.

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

#[derive(Signals, Serialize, Deserialize)]
struct Editor {
    bold: bool,
}

let html = Page::new("Editor", Editor { bold: true })
    .child(toggle(Editor::bold()).text("Bold"))
    .render();
assert!(html.contains(r#"aria-pressed="true""#));