feat(a11y): screen reader name and description support for button widgets

This commit is contained in:
Michael Aaron Murphy 2026-01-09 23:03:09 +01:00 committed by Michael Murphy
parent f6039597b7
commit b9c24d2421
6 changed files with 122 additions and 19 deletions

View file

@ -33,6 +33,10 @@ impl<'a, Message> Button<'a, Message> {
Self {
id: Id::unique(),
label: Cow::Borrowed(""),
#[cfg(feature = "a11y")]
name: Cow::Borrowed(""),
#[cfg(feature = "a11y")]
description: Cow::Borrowed(""),
tooltip: Cow::Borrowed(""),
on_press: None,
width: Length::Shrink,
@ -79,12 +83,18 @@ where
.width(builder.width)
.height(builder.height);
super::custom_image_button(content, builder.variant.on_remove)
let mut button = super::custom_image_button(content, builder.variant.on_remove)
.padding(0)
.selected(builder.variant.selected)
.id(builder.id)
.on_press_maybe(builder.on_press)
.class(builder.class)
.into()
.class(builder.class);
#[cfg(feature = "a11y")]
{
button = button.name(builder.name).description(builder.description);
}
button.into()
}
}