diff --git a/crates/gpui/src/elements/div.rs b/crates/gpui/src/elements/div.rs index f16f4bad523..4abbc1e65dd 100644 --- a/crates/gpui/src/elements/div.rs +++ b/crates/gpui/src/elements/div.rs @@ -1624,6 +1624,14 @@ pub trait StatefulInteractiveElement: InteractiveElement { self } + /// Set the URL this element links to (maps to the AccessKit `url` + /// property), the target a web page exposes for an ``. This only + /// describes the element to assistive technology; it does not open the URL. + fn aria_url(mut self, url: impl Into) -> Self { + self.interactivity().aria.url = Some(url.into()); + self + } + /// Set the minimum numeric value for this element. fn aria_min_numeric_value(mut self, value: f64) -> Self { self.interactivity().aria.min_numeric_value = Some(value); @@ -2463,6 +2471,7 @@ pub(crate) struct AriaProperties { pub(crate) numeric_value_step: Option, pub(crate) value: Option, pub(crate) placeholder: Option, + pub(crate) url: Option, pub(crate) orientation: Option, pub(crate) level: Option, pub(crate) position_in_set: Option, @@ -4022,6 +4031,9 @@ impl Interactivity { if let Some(placeholder) = &self.aria.placeholder { node.set_placeholder(placeholder.to_string()); } + if let Some(url) = &self.aria.url { + node.set_url(url.to_string()); + } if let Some(orientation) = self.aria.orientation { node.set_orientation(orientation); } @@ -5479,6 +5491,16 @@ mod tests { assert_eq!(node.author_id(), Some("settings.buffer-font-size")); } + #[test] + fn test_aria_url_builder_writes_url() { + let mut element = div().id("docs-link").aria_url("https://example.com/docs"); + let mut node = accesskit::Node::new(accesskit::Role::Link); + + element.interactivity().write_a11y_info(&mut node); + + assert_eq!(node.url(), Some("https://example.com/docs")); + } + #[test] fn test_write_a11y_info_string_and_numeric_properties() { let mut interactivity = Interactivity::default();