日本語

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.

KeyWhat it does
Arrow keysMove the value by one step.
Page Up, Page DownMove the value by a larger step.
Home, EndMove to the lowest or the highest value.

API

ItemSummary
Slider::newA slider from 0 to 100 in steps of 1, labeled label, bound to value.
rangeSets the lowest and the highest value.
stepSets how far one arrow key press moves the value.
value_textShows text beside the label and gives it to assistive technology as aria-valuetext.
disabledDisables the slider while when is true, and dims it.