Forms · NumberInput label: the name assistive technology reads, drawn nowhere

This commit is contained in:
ZacharyZhang-NY committed 2026-10-05 12:34:19 -04:00
1 parent 47caebdd36
commit 718617939e
3 files changed
+22

No files matched your search

+12
View File
@@ -224,6 +224,7 @@ pub struct NumberInput {
on_change: Option<OnChange>,
on_commit: Option<OnChange>,
scrub_label: Option<SharedString>,
label: SharedString,
}
impl NumberInput {
@@ -241,9 +242,16 @@ impl NumberInput {
on_change: None,
on_commit: None,
scrub_label: None,
label: SharedString::default(),
}
}
/// The name assistive technology reads, drawn nowhere.
pub fn label(mut self, text: impl Into<SharedString>) -> Self {
self.label = text.into();
self
}
pub fn range(mut self, min: f64, max: f64) -> Self {
assert!(min <= max, "number range {min}..{max} is empty");
self.min = min;
@@ -316,6 +324,10 @@ impl RenderOnce for NumberInput {
numeric.limits = (min, max, step, self.precision);
});
let input = state.read(cx).input.clone();
if input.read(cx).label_text() != &self.label {
let label = self.label.clone();
input.update(cx, |input, cx| input.set_label(label, cx));
}
let shown = format::number(value, self.precision, Separators::EN);
let editing = input.read(cx).focus().is_focused(window);
if !editing && input.read(cx).text() != shown {
+9
View File
@@ -204,6 +204,10 @@ impl TextInput {
&self.placeholder
}
pub fn label_text(&self) -> &SharedString {
&self.label
}
pub fn selection(&self) -> Range<usize> {
self.selection.clone()
}
@@ -221,6 +225,11 @@ impl TextInput {
cx.notify();
}
pub fn set_label(&mut self, text: impl Into<SharedString>, cx: &mut Context<Self>) {
self.label = text.into();
cx.notify();
}
pub fn set_masked(&mut self, masked: bool, cx: &mut Context<Self>) {
self.masked = masked;
cx.notify();