Toast · an alert or status role named by its title, so screen readers hear every notice

This commit is contained in:
ZacharyZhang-NY committed 2026-10-08 12:48:47 -04:00
1 parent ea4ed4cbb7
commit 3fcbd6f139
1 file changed
+9 -1
+9 -1
View File
@@ -3,7 +3,7 @@ use std::{rc::Rc, time::Duration};
use gpui::{
Anchor, Animation, AnimationExt, AnyElement, App, ClickEvent, Context, ElementId, Entity,
FontWeight, HoverListenerMode, InteractiveElement, IntoElement, ParentElement, Pixels,
RenderOnce, SharedString, StatefulInteractiveElement, Styled, Task, Window, anchored, canvas,
RenderOnce, Role, SharedString, StatefulInteractiveElement, Styled, Task, Window, anchored, canvas,
div, point, prelude::*, relative,
};
use web_time::Instant;
@@ -275,8 +275,16 @@ fn card(
};
let theme = cx.theme();
let colors = &theme.colors;
// Read aloud: alerts interrupt, other notes wait their turn.
let role = match toast.severity {
Some(Severity::Danger | Severity::Warning) => Role::Alert,
_ => Role::Status,
};
let card = div()
.id(key.clone())
.role(role)
.aria_label(toast.title.clone())
.when_some(toast.body.clone(), |card, body| card.aria_description(body))
.relative()
.flex()
.items_center()