Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

gpui: Expose accessibility identifiers to platform clients (#61926)

Chris Hynescc053a4a6fa2
diff --git a/crates/gpui/src/elements/div.rs b/crates/gpui/src/elements/div.rs
index 811322546f2..b9c1a964792 100644
--- a/crates/gpui/src/elements/div.rs
+++ b/crates/gpui/src/elements/div.rs
@@ -1255,6 +1255,18 @@ pub trait StatefulInteractiveElement: InteractiveElement {
self
}
+ /// Set the author-provided identifier exposed to accessibility clients.
+ ///
+ /// Unlike the GPUI element ID, this value is visible outside the process.
+ /// Keep it stable and unique within its accessibility tree.
+ /// AccessKit maps it to platform identifiers where supported, including
+ /// UIA `AutomationId` on Windows, `AXIdentifier` on macOS, and AT-SPI
+ /// `AccessibleId` on Linux stacks whose deployed adapter exposes it.
+ fn accessibility_id(mut self, id: impl Into<SharedString>) -> Self {
+ self.interactivity().aria.author_id = Some(id.into());
+ self
+ }
+
/// Set the accessible label for this element.
fn aria_label(mut self, label: impl Into<SharedString>) -> Self {
self.interactivity().aria.label = Some(label.into());
@@ -1982,6 +1994,7 @@ impl IntoElement for Div {
#[derive(Default)]
pub(crate) struct AriaProperties {
+ pub(crate) author_id: Option<SharedString>,
pub(crate) label: Option<SharedString>,
pub(crate) description: Option<SharedString>,
pub(crate) keyshortcuts: Option<SharedString>,
@@ -3364,6 +3377,9 @@ impl Interactivity {
}
pub(crate) fn write_a11y_info(&self, node: &mut accesskit::Node) {
+ if let Some(id) = &self.aria.author_id {
+ node.set_author_id(id.to_string());
+ }
if let Some(label) = &self.aria.label {
node.set_label(label.to_string());
}
@@ -4703,9 +4719,22 @@ mod tests {
);
}
+ #[test]
+ fn test_accessibility_id_builder_writes_author_id() {
+ let mut element = div()
+ .id("buffer-font-size")
+ .accessibility_id("settings.buffer-font-size");
+ let mut node = accesskit::Node::new(accesskit::Role::SpinButton);
+
+ element.interactivity().write_a11y_info(&mut node);
+
+ assert_eq!(node.author_id(), Some("settings.buffer-font-size"));
+ }
+
#[test]
fn test_write_a11y_info_string_and_numeric_properties() {
let mut interactivity = Interactivity::default();
+ interactivity.aria.author_id = Some("settings.buffer-font-size".into());
interactivity.aria.label = Some("Buffer Font Size".into());
interactivity.aria.value = Some("15".into());
interactivity.aria.placeholder = Some("Search".into());
@@ -4717,6 +4746,7 @@ mod tests {
let mut node = accesskit::Node::new(accesskit::Role::SpinButton);
interactivity.write_a11y_info(&mut node);
+ assert_eq!(node.author_id(), Some("settings.buffer-font-size"));
assert_eq!(node.label(), Some("Buffer Font Size"));
assert_eq!(node.value(), Some("15"));
assert_eq!(node.placeholder(), Some("Search"));