Slider
A slider that sets an i32 signal, with a value text for a unit.
Result
slider.rs
use hypersig::html::div;
use hypersig::style::Style;
use hypersig::style::value::rem;
use hypersig::{Page, Signals};
use hypersig_ui::Slider;
use serde::{Deserialize, Serialize};
#[derive(Signals, Serialize, Deserialize)]
pub struct Player {
volume: i32,
}
pub fn page() -> Page<Player> {
let volume = Player::volume();
Page::new(
"Player",
Player { volume: 40 },
)
.child(
div().css(Style::new().max_width(rem(20))).child(
Slider::new(
"Volume",
volume,
)
.step(5)
.value_text(volume.to_text().concat(" %")),
),
)
}Accessibility
It is a native <input type="range">, so the browser gives it role="slider", its keys, and dragging with a pointer or a finger. The input is transparent and lies over a track and a thumb drawn from the value, so the slider looks the same in every browser.
value_text shows a value such as "40 %" beside the label and gives it to assistive technology as aria-valuetext. The drawn thumb can sit a few pixels off the browser's own transparent thumb near either end.
| Key | What it does |
|---|---|
| Arrow keys | Move the value by one step. |
| Page Up, Page Down | Move the value by a larger step. |
| Home, End | Move to the lowest or the highest value. |
API
| Item | Summary |
|---|---|
Slider::new | A slider from 0 to 100 in steps of 1, labeled label, bound to value. |
range | Sets the lowest and the highest value. |
step | Sets how far one arrow key press moves the value. |
value_text | Shows text beside the label and gives it to assistive technology as aria-valuetext. |
disabled | Disables the slider while when is true, and dims it. |