Forms, a11y · Checkbox, Switch, Radio, RadioGroup, Slider and Select name their role, label and state (#3)

A slider's thumb reports its value, the bounds it can reach and its orientation; a select's trigger its value, placeholder and whether its list is open; a disabled control says so in its description.
This commit is contained in:
ZacharyZhang-NY committed 2026-10-03 01:35:48 -04:00
1 parent ec586e371b
commit 875cdfdc9b
8 files changed
+71 -12

No files matched your search

+8 -2
View File
@@ -2,13 +2,13 @@ use std::rc::Rc;
use gpui::{
Animation, AnimationExt, App, ElementId, InteractiveElement, IntoElement, MouseButton,
ParentElement, RenderOnce, SharedString, StatefulInteractiveElement, Styled, Window, div,
ParentElement, RenderOnce, Role, SharedString, StatefulInteractiveElement, Styled, Window, div,
prelude::*, transparent_black,
};
use super::options::OnFlag;
use crate::{
motion,
i18n, motion,
primitives::tab_stop,
theme::{ActiveTheme, Elevation, Mix, TextSize},
};
@@ -119,6 +119,12 @@ impl RenderOnce for Switch {
let (id, next, on_change) = (self.id.clone(), !self.on, self.on_change);
div()
.id(self.id)
.role(Role::Switch)
.aria_toggled(self.on.into())
.when_some(self.label.clone(), |row, label| row.aria_label(label))
.when(self.disabled, |row| {
row.aria_description(i18n::text(cx, "state.unavailable", &[]))
})
.track_focus(&focus)
.flex()
.items_center()