diff --git a/changelog.d/claude-project-thread-5mrv8h.md b/changelog.d/claude-project-thread-5mrv8h.md index 3f2c062b79..8d8afe1059 100644 --- a/changelog.d/claude-project-thread-5mrv8h.md +++ b/changelog.d/claude-project-thread-5mrv8h.md @@ -149,6 +149,10 @@ tooltip and accessible name of a button that deletes the item it sits in, "Delete" in `DefaultWidgetsLocalizations` (Flutter 3.50.1's `MaterialLocalizations.deleteButtonTooltip`). An implementor of the trait adds it. +- `WidgetsLocalizations::select_row_label(row)` (`flui-widgets`), a required method: the name of + the checkbox that selects data row `row` (1-based) of a table, "Select row 2" in + `DefaultWidgetsLocalizations`. Flutter 3.50.1 has no such string. An implementor of the trait + adds it. ### Changed @@ -247,3 +251,10 @@ `WidgetsLocalizations::delete_button_tooltip` of the ambient `Localizations` ("Delete" in English), as Flutter 3.50.1 names it by `MaterialLocalizations.deleteButtonTooltip`. Before, every `Chip` and `FilterChip` with `on_deleted` had an unnamed button no reader could announce. +- A material `BackButton` has a name: the ambient `WidgetsLocalizations::back_button_label` + ("Back" in English), the string Flutter 3.50.1's `BackButton` shows as its tooltip + (`MaterialLocalizations.backButtonTooltip`). Before, every app bar that implied a back button + showed a reader an unnamed button. +- A `DataTable`'s checkboxes have names, where Flutter 3.50.1 leaves them unnamed: the heading's + is the ambient `select_all_button_label` ("Select all"), each data row's is + `select_row_label` with its place below the heading ("Select row 1"). diff --git a/crates/flui-widgets/src/localization/global_widgets_localizations.rs b/crates/flui-widgets/src/localization/global_widgets_localizations.rs index dad15b3ab3..8d28340808 100644 --- a/crates/flui-widgets/src/localization/global_widgets_localizations.rs +++ b/crates/flui-widgets/src/localization/global_widgets_localizations.rs @@ -162,6 +162,9 @@ impl WidgetsLocalizations for GlobalWidgetsLocalizations { fn menu_dismiss_label(&self) -> &'static str { DefaultWidgetsLocalizations.menu_dismiss_label() } + fn select_row_label(&self, row: usize) -> String { + DefaultWidgetsLocalizations.select_row_label(row) + } } /// A [`LocalizationsDelegate`] that resolves a [`GlobalWidgetsLocalizations`] diff --git a/crates/flui-widgets/src/localization/widgets_localizations.rs b/crates/flui-widgets/src/localization/widgets_localizations.rs index 64a5129401..f5b7aaa3ef 100644 --- a/crates/flui-widgets/src/localization/widgets_localizations.rs +++ b/crates/flui-widgets/src/localization/widgets_localizations.rs @@ -51,7 +51,8 @@ pub trait WidgetsLocalizations: Any + fmt::Debug { fn cut_button_label(&self) -> &'static str; /// Label for "paste" edit buttons and menu items. fn paste_button_label(&self) -> &'static str; - /// Label for "select all" edit buttons and menu items. + /// Label for "select all" edit buttons and menu items, and of the + /// checkbox in a table's heading that selects every row. fn select_all_button_label(&self) -> &'static str; /// Label for "look up" edit buttons and menu items. fn look_up_button_label(&self) -> &'static str; @@ -62,8 +63,10 @@ pub trait WidgetsLocalizations: Any + fmt::Debug { /// Label of a toolbar's button that shows the commands its row has no /// room for. fn more_button_label(&self) -> &'static str; - /// Label of a toolbar's button that leaves the commands it showed and - /// returns to its row. + /// Label of a button that goes back: a toolbar's button that leaves the + /// commands it showed and returns to its row, and a page's back button + /// (Flutter 3.50.1's `MaterialLocalizations.backButtonTooltip`, which both + /// read, "Back" in English). fn back_button_label(&self) -> &'static str; /// Tooltip and accessible name of the button that deletes the item it sits /// in, such as a chip's delete button (Flutter 3.50.1's @@ -101,6 +104,11 @@ pub trait WidgetsLocalizations: Any + fmt::Debug { fn modal_barrier_dismiss_label(&self) -> &'static str; /// Semantics label of the barrier behind an open popup menu. fn menu_dismiss_label(&self) -> &'static str; + /// Semantics label of the checkbox that selects data row `row` (1-based, + /// below the heading) of a table. Flutter 3.50.1's `DataTable` leaves its + /// row checkboxes unnamed (`_buildCheckbox`); the heading's checkbox is + /// named by [`select_all_button_label`](Self::select_all_button_label). + fn select_row_label(&self, row: usize) -> String; /// What assistive technology hears after an item moved in a reorderable /// list: the item, when it is named, at `position` (1-based) of `count`. fn reorder_item_moved(&self, item: Option<&str>, position: usize, count: usize) -> String; @@ -235,4 +243,8 @@ impl WidgetsLocalizations for DefaultWidgetsLocalizations { fn menu_dismiss_label(&self) -> &'static str { "Dismiss menu" } + + fn select_row_label(&self, row: usize) -> String { + format!("Select row {row}") + } } diff --git a/crates/flui-widgets/tests/modal_barrier.rs b/crates/flui-widgets/tests/modal_barrier.rs index 5f89d40da6..19a0e45525 100644 --- a/crates/flui-widgets/tests/modal_barrier.rs +++ b/crates/flui-widgets/tests/modal_barrier.rs @@ -435,6 +435,9 @@ impl WidgetsLocalizations for German { fn menu_dismiss_label(&self) -> &'static str { "Menü schließen" } + fn select_row_label(&self, row: usize) -> String { + DefaultWidgetsLocalizations.select_row_label(row) + } fn reorder_item_moved(&self, item: Option<&str>, position: usize, count: usize) -> String { DefaultWidgetsLocalizations.reorder_item_moved(item, position, count) } diff --git a/crates/flui-widgets/tests/page_view.rs b/crates/flui-widgets/tests/page_view.rs index f055c17ff4..336477eb1c 100644 --- a/crates/flui-widgets/tests/page_view.rs +++ b/crates/flui-widgets/tests/page_view.rs @@ -672,6 +672,9 @@ fn the_page_label_comes_from_the_widgets_localizations() { fn menu_dismiss_label(&self) -> &'static str { DefaultWidgetsLocalizations.menu_dismiss_label() } + fn select_row_label(&self, row: usize) -> String { + DefaultWidgetsLocalizations.select_row_label(row) + } } #[derive(Debug)] struct GermanDelegate; diff --git a/docs/gaps.md b/docs/gaps.md index ef374aa5f6..f8facbefc1 100644 --- a/docs/gaps.md +++ b/docs/gaps.md @@ -549,13 +549,6 @@ its anchor: update the links and the `GapId` slug in the same pull request. - A list under a header sliver that scrolls away, or inside `SliverPadding`, has a rect smaller than the viewport's clip, so it does not. Nor does a `SingleChildScrollView`: the node holding its content sits above its viewport, outside the clip. AccessKit's filter reads only the nearest filtered parent. The content is still not `visible` to the agent and `Tester`: the actionability check narrows by every clipping ancestor, the scroll view included. A list under a pinned header does get the flag: the viewport shrinks that list's clip by the room the header takes, so a row wholly behind the header counts as past the edge, a translucent header included, as Flutter's viewport clips it. - It closes with a clip the viewport hands each sliver for its own extent, and with the scroll semantics node formed inside the viewport's clip. -### A back button and a data table's row checkboxes have no accessible name - -> **Environments:** all · **Who it hurts:** Screen-reader users: `BackButton` and the row checkboxes `DataTable` builds are announced as an unnamed button and unnamed checkboxes, and an application cannot name the checkboxes, which the table builds itself · **Parity:** [Accessibility](platform-parity.md#accessibility) - -- `flui-material`'s tests end with exactly these `Unnamed` audit findings (`icon_face::a_widget_draws_the_glyph_the_face_names_for_its_icon`, `app_bar`, `data_table`, through `tests/common`'s `finish_with_unnamed`), so naming them fails those tests until the tests drop the expected findings. -- It closes as ADR-0407 names a control the framework builds: `BackButton` from a localized back-button tooltip (Flutter 3.50.1's `MaterialLocalizations.backButtonTooltip`), and each row's checkbox from a localized string `DataTable` reads, as a chip's delete button reads `WidgetsLocalizations::delete_button_tooltip`. - ### Add-to-app: no FLUI view inside an existing native app > **Environments:** all · **Who it hurts:** Teams adding FLUI to an app they already ship · **Parity:** [Windows](platform-parity.md#windows) diff --git a/docs/plans/specs/testing-platform/tasks.md b/docs/plans/specs/testing-platform/tasks.md index 53448c3025..97307fd19d 100644 --- a/docs/plans/specs/testing-platform/tasks.md +++ b/docs/plans/specs/testing-platform/tasks.md @@ -834,11 +834,13 @@ убраны. Каждый тест кончается `t.finish()`; `finish_unchecked` — только там, где предмет теста — работа, идущая, пока виджет смонтирован: неопределённый индикатор, бегущая волна, обновление, которое не завершается. Аудит конца назвал два безымянных элемента управления, и - виджеты не правились (их имена — отдельное изменение по ADR-0407: - локализованная подсказка или метка `Semantics`): `BackButton` имени не берёт (Flutter 3.50.1 называет его - `MaterialLocalizations.backButtonTooltip`), чекбоксы строк `DataTable` безымянны (как - `_buildCheckbox` у Flutter); строка `BackButton` в `icon_face` и тесты чекбоксов `data_table` - кончаются `try_finish` ровно с находками `Unnamed` на эти узлы. Остальные элементы названы, + они названы из окружающих локализаций: `BackButton` — строкой + `WidgetsLocalizations::back_button_label` («Back», `MaterialLocalizations.backButtonTooltip` + у Flutter 3.50.1), чекбоксы `DataTable` — `select_all_button_label` у заголовка и + `select_row_label` у строк (у Flutter они безымянны, `_buildCheckbox`); строка `BackButton` в + `icon_face` и тесты `data_table` кончаются `t.finish()`, а имена на двух языках читают + `app_bar::a_back_button_is_named_in_the_ambient_language` и + `data_table::the_checkboxes_are_named_in_the_ambient_language`. Остальные элементы названы, как их называет приложение: колодцы и поля — подписью (`Text`, `InputDecoration::label_text`), элементы выбора — меткой `Semantics` вокруг них (ADR-0407). Переформулированные и ослабленные утверждения, каждое в документе теста: пустота и число записей реестра кадров (`Vsync::is_empty`, `len`) читаются @@ -909,7 +911,7 @@ конец пропустил проверки отравленного тестера. Аудит конца ни одного виджета не назвал: безымянные элементы названы, как их называет приложение (`TextButton` с `Text` в `AlertDialog`, `Semantics(label:)` у значка вкладки без текста и у панели ящика), а - безымянный `BackButton` в `app_bar` уходит со страницей до конца теста. Ящик открывается + `BackButton` в `app_bar` находится по имени «Back». Ящик открывается кнопкой, которая зовёт `DrawerHandle::open_drawer` (вызов ручки вне хода владельца не разрешает `GlobalKey`). Переформулированные и ослабленные утверждения, каждое в документе теста: у диалога `show_dialog` не читаются флаг modal и `labelled_by` (у `Node` их нет), читаются diff --git a/packages/flui-material/src/ambient_strings.rs b/packages/flui-material/src/ambient_strings.rs new file mode 100644 index 0000000000..0f788a98ed --- /dev/null +++ b/packages/flui-material/src/ambient_strings.rs @@ -0,0 +1,23 @@ +//! The strings a widget of this package builds into what it shows or names, read from the +//! ambient [`WidgetsLocalizations`]. +//! +//! A widget reads them where it builds the part that shows them, so a widget without that +//! part depends on no localizations. Without a `Localizations` above the widget, the strings +//! are [`DefaultWidgetsLocalizations`]' English ones. + +use flui_sdk::view::BuildContext; +use flui_sdk::widgets::{ + BoxedWidgetsLocalizations, DefaultWidgetsLocalizations, WidgetsLocalizations, +}; + +/// `read` applied to the [`WidgetsLocalizations`] above `ctx`, registering the dependency, +/// or to [`DefaultWidgetsLocalizations`] when none is above it. +pub(crate) fn localized( + ctx: &dyn BuildContext, + read: impl FnOnce(&dyn WidgetsLocalizations) -> T, +) -> T { + match BoxedWidgetsLocalizations::maybe_of(ctx) { + Some(localizations) => read(&**localizations), + None => read(&DefaultWidgetsLocalizations), + } +} diff --git a/packages/flui-material/src/back_button.rs b/packages/flui-material/src/back_button.rs index dc61ee0748..522b829861 100644 --- a/packages/flui-material/src/back_button.rs +++ b/packages/flui-material/src/back_button.rs @@ -26,8 +26,9 @@ //! reading start. use flui_sdk::view::prelude::*; -use flui_sdk::widgets::{Icon, IconData, PageHandle}; +use flui_sdk::widgets::{Icon, IconData, PageHandle, WidgetsLocalizations}; +use crate::ambient_strings::localized; use crate::button_style_button::PressCallback; use crate::icon_button::IconButton; @@ -47,6 +48,11 @@ pub(crate) fn back_arrow_icon_data() -> IconData { /// every route (and with no override), the button mounts disabled /// rather than panicking. /// +/// Assistive technology hears it as the ambient +/// [`WidgetsLocalizations::back_button_label`](flui_sdk::widgets::WidgetsLocalizations::back_button_label) +/// ("Back" in English), the string Flutter 3.50.1's `BackButton` shows as its tooltip +/// (`MaterialLocalizations.backButtonTooltip`); no tooltip shows here. +/// /// ```rust /// use flui_material::BackButton; /// @@ -88,7 +94,8 @@ impl BackButton { impl StatelessView for BackButton { fn build(&self, ctx: &dyn BuildContext) -> impl IntoView { - let icon = Icon::new(back_arrow_icon_data()); + let label = localized(ctx, WidgetsLocalizations::back_button_label); + let icon = Icon::new(back_arrow_icon_data()).semantic_label(label); let mut button = IconButton::new(icon); if let Some(on_pressed) = self.on_pressed.clone() { diff --git a/packages/flui-material/src/chip.rs b/packages/flui-material/src/chip.rs index 8abfce7825..839e7f23fc 100644 --- a/packages/flui-material/src/chip.rs +++ b/packages/flui-material/src/chip.rs @@ -34,15 +34,15 @@ use flui_sdk::view::prelude::*; use flui_sdk::widgets::__private::node::Description; use flui_sdk::widgets::IconData; use flui_sdk::widgets::{ - BoxedWidgetsLocalizations, ConstrainedBox, CustomPaint, DefaultTextStyle, - DefaultWidgetsLocalizations, Icon, IconTheme, IconThemeData, Opacity, Padding, Row, - WidgetState, WidgetStates, WidgetsLocalizations, + ConstrainedBox, CustomPaint, DefaultTextStyle, Icon, IconTheme, IconThemeData, Opacity, + Padding, Row, WidgetState, WidgetStates, WidgetsLocalizations, }; use flui_sdk::{ geometry::{EdgeInsets, Point, Size}, painting::styling::Color, }; +use crate::ambient_strings::localized; use crate::color_scheme::ColorScheme; use crate::ink_well::InkWell; use crate::material::Material; @@ -376,7 +376,7 @@ type FilterChipSelectCallback = Rc, /// - **Delete-button tooltip** — Flutter shows `deleteButtonTooltipMessage` /// as the tooltip and names the delete button's node with it, falling back /// to `MaterialLocalizations.deleteButtonTooltip`. Here the node is named by -/// the ambient [`WidgetsLocalizations::delete_button_tooltip`] and no +/// the ambient [`WidgetsLocalizations::delete_button_tooltip`](flui_sdk::widgets::WidgetsLocalizations::delete_button_tooltip) and no /// tooltip shows; there is no `delete_button_tooltip_message` override. /// - **`focus_node`/`autofocus`** — [`InkWell`] itself has no `autofocus` /// hook yet, matching every other selection-control's own deferred list. @@ -544,7 +544,7 @@ impl StatelessView for Chip { delete_icon_color, self.enabled, on_deleted, - delete_button_tooltip(ctx), + localized(ctx, WidgetsLocalizations::delete_button_tooltip), ) }); @@ -835,7 +835,7 @@ impl StatelessView for FilterChip { delete_icon_color, enabled, on_deleted, - delete_button_tooltip(ctx), + localized(ctx, WidgetsLocalizations::delete_button_tooltip), ) }); @@ -886,16 +886,6 @@ impl StatelessView for FilterChip { } } -/// The delete button's name: the ambient [`WidgetsLocalizations::delete_button_tooltip`], -/// or the English default when no `Localizations` above the chip supplies one. Read only -/// where a delete button is built, so a chip without one depends on no localizations. -fn delete_button_tooltip(ctx: &dyn BuildContext) -> &'static str { - match BoxedWidgetsLocalizations::maybe_of(ctx) { - Some(localizations) => localizations.delete_button_tooltip(), - None => DefaultWidgetsLocalizations.delete_button_tooltip(), - } -} - /// A chip's delete button: a well of its own over the delete glyph, a button /// node whether or not the chip has a handler of its own, so activating the /// chip never deletes it and the delete button's node does not come and go diff --git a/packages/flui-material/src/data_table.rs b/packages/flui-material/src/data_table.rs index ba299ff0a2..ad9fbc8c3a 100644 --- a/packages/flui-material/src/data_table.rs +++ b/packages/flui-material/src/data_table.rs @@ -26,9 +26,10 @@ use flui_sdk::semantics::SemanticsRole; use flui_sdk::view::prelude::*; use flui_sdk::widgets::{ Center, Container, DefaultTextStyle, Directionality, Padding, Semantics, SizedBox, Table, - TableCell, TableRow, WidgetState, WidgetStateProperty, WidgetStates, + TableCell, TableRow, WidgetState, WidgetStateProperty, WidgetStates, WidgetsLocalizations, }; +use crate::ambient_strings::localized; use crate::checkbox::{CHECKBOX_EDGE_SIZE, Checkbox}; use crate::color_scheme::ColorScheme; use crate::ink_well::InkWell; @@ -262,6 +263,13 @@ impl DataRow { /// [`DataTable::on_select_all`] overrides the fan-out; otherwise every /// selectable row whose `selected` differs from the new value is toggled. /// +/// Assistive technology hears the heading checkbox as the ambient +/// [`WidgetsLocalizations::select_all_button_label`](flui_sdk::widgets::WidgetsLocalizations::select_all_button_label) +/// ("Select all") and each row's as +/// [`WidgetsLocalizations::select_row_label`](flui_sdk::widgets::WidgetsLocalizations::select_row_label) +/// with the row's 1-based place below the heading ("Select row 1"). Flutter 3.50.1's +/// `DataTable` leaves both unnamed (`_buildCheckbox`), so a reader announced a bare checkbox. +/// /// # Deferred (named, not silently dropped) /// /// - **Sorting** — a sort column index and direction, per-column sort @@ -784,7 +792,7 @@ fn wrap_selectable( ink_well.boxed() } -/// The heading checkbox cell: a tristate [`Checkbox`] centered in its +/// The heading checkbox cell: a tristate [`Checkbox`] named `label`, centered in its /// margin, wrapped to fill the checkbox column's cell. fn header_checkbox_cell( checked: Option, @@ -792,16 +800,17 @@ fn header_checkbox_cell( margin_start: f64, margin_end: f64, direction: TextDirection, + label: String, ) -> BoxedView { let checkbox = Checkbox::tristate(checked).on_changed(on_change); let content = Semantics::new().container(true).child( Padding::new(horizontal_insets(margin_start, margin_end, direction)) - .child(Center::new().child(checkbox)), + .child(Center::new().child(Semantics::new().label(label).child(checkbox))), ); TableCell::new(TableCellVerticalAlignment::Fill, content).boxed() } -/// A data row's checkbox cell: a non-tristate [`Checkbox`], with the whole +/// A data row's checkbox cell: a non-tristate [`Checkbox`] named `label`, with the whole /// cell also tap-toggling the row when selectable. fn row_checkbox_cell( selected: bool, @@ -809,6 +818,7 @@ fn row_checkbox_cell( margin_start: f64, margin_end: f64, direction: TextDirection, + label: String, overlay: Option, ) -> BoxedView { let mut checkbox = Checkbox::new(selected); @@ -819,7 +829,7 @@ fn row_checkbox_cell( .container(true) .child( Padding::new(horizontal_insets(margin_start, margin_end, direction)) - .child(Center::new().child(checkbox)), + .child(Center::new().child(Semantics::new().label(label).child(checkbox))), ) .boxed(); @@ -981,6 +991,7 @@ impl StatelessView for DataTable { style.checkbox_margin_start, style.checkbox_margin_end, direction, + localized(ctx, WidgetsLocalizations::select_all_button_label).to_owned(), )); } for (index, column) in self.columns.iter().enumerate() { @@ -1029,6 +1040,7 @@ impl StatelessView for DataTable { style.checkbox_margin_start, style.checkbox_margin_end, direction, + localized(ctx, |strings| strings.select_row_label(row_index + 1)), overlay.clone(), )); } diff --git a/packages/flui-material/src/lib.rs b/packages/flui-material/src/lib.rs index dace68c59e..344b826b43 100644 --- a/packages/flui-material/src/lib.rs +++ b/packages/flui-material/src/lib.rs @@ -33,6 +33,7 @@ #![deny(missing_docs)] #![warn(clippy::disallowed_types)] +mod ambient_strings; mod animated_icons; mod app; mod app_bar; diff --git a/packages/flui-material/tests/app_bar.rs b/packages/flui-material/tests/app_bar.rs index d76b3f2532..fb29c8c26e 100644 --- a/packages/flui-material/tests/app_bar.rs +++ b/packages/flui-material/tests/app_bar.rs @@ -44,7 +44,7 @@ fn leading_icon_buttons(t: &mut Tester) -> usize { .count() } -/// The implied `BackButton` is found by its role: it takes no name (Flutter 3.50.1 names it +/// The implied `BackButton` is found by its name, the localized "Back" (Flutter 3.50.1's /// `MaterialLocalizations.backButtonTooltip`), and the tap pops it off the screen before the /// end's audit reads the window. pub fn tapping_the_implied_back_button_pops_the_route() { @@ -79,7 +79,7 @@ pub fn tapping_the_implied_back_button_pops_the_route() { "the top page's app bar implies one back button" ); - t.tap(&find::role(Role::Button)); + t.tap(&find::text("Back")); t.settle(); assert_eq!( @@ -96,6 +96,37 @@ pub fn tapping_the_implied_back_button_pops_the_route() { t.finish(); } +/// A `BackButton` is named in the ambient language by `WidgetsLocalizations::back_button_label`, +/// as Flutter 3.50.1 names it by `MaterialLocalizations.backButtonTooltip`: "Back" with no +/// `Localizations` above it, "Zurück" under a German one. The other language's name finds no +/// button. +pub fn a_back_button_is_named_in_the_ambient_language() { + use flui_material::BackButton; + + let button = || Theme::new(ThemeData::light(), BackButton::new().on_pressed(|_ctx| {})); + for (language, view, name, other) in [ + ("English", button().boxed(), "Back", "Zurück"), + ( + "German", + crate::common::in_german(button()), + "Zurück", + "Back", + ), + ] { + let mut t = Tester::mount_in(view, TestWindow::new(WindowSpec::new(100, 100))); + assert_eq!( + t.read(&find::role(Role::Button)).name.as_deref(), + Some(name), + "{language}: the button's name" + ); + assert!( + t.try_read(&find::button(other)).is_err(), + "{language}: no button is named {other:?}" + ); + t.finish(); + } +} + /// Under a right-to-left `Directionality` the toolbar runs from the right: the /// leading slot takes the right edge, the title starts against it, and the /// actions sit at the left edge. The action is a 40-wide box whose label fills it. diff --git a/packages/flui-material/tests/chip.rs b/packages/flui-material/tests/chip.rs index a20a2451d5..0e0a268ca2 100644 --- a/packages/flui-material/tests/chip.rs +++ b/packages/flui-material/tests/chip.rs @@ -489,129 +489,7 @@ pub fn a_chip_names_its_delete_button_from_the_localizations() { use flui_protocol::act::ActParams; use flui_protocol::client::Connection as _; use flui_protocol::method::SemanticsAct; - use flui_sdk::foundation::TextDirection; - use flui_sdk::platform::Locale; use flui_sdk::view::{BoxedView, ViewExt}; - use flui_sdk::widgets::{ - BoxedLocalizationsDelegate, BoxedWidgetsLocalizations, DefaultWidgetsLocalizations, - Localizations, LocalizationsDelegate, WidgetsLocalizations, - }; - - /// German widgets localizations: Flutter 3.50.1's German `deleteButtonTooltip`, "Löschen", and - /// the English default for every other string. - #[derive(Debug)] - struct German; - - impl WidgetsLocalizations for German { - fn text_direction(&self) -> TextDirection { - TextDirection::Ltr - } - fn reorder_item_to_start(&self) -> &'static str { - DefaultWidgetsLocalizations.reorder_item_to_start() - } - fn reorder_item_to_end(&self) -> &'static str { - DefaultWidgetsLocalizations.reorder_item_to_end() - } - fn reorder_item_up(&self) -> &'static str { - DefaultWidgetsLocalizations.reorder_item_up() - } - fn reorder_item_down(&self) -> &'static str { - DefaultWidgetsLocalizations.reorder_item_down() - } - fn reorder_item_left(&self) -> &'static str { - DefaultWidgetsLocalizations.reorder_item_left() - } - fn reorder_item_right(&self) -> &'static str { - DefaultWidgetsLocalizations.reorder_item_right() - } - fn copy_button_label(&self) -> &'static str { - DefaultWidgetsLocalizations.copy_button_label() - } - fn cut_button_label(&self) -> &'static str { - DefaultWidgetsLocalizations.cut_button_label() - } - fn paste_button_label(&self) -> &'static str { - DefaultWidgetsLocalizations.paste_button_label() - } - fn select_all_button_label(&self) -> &'static str { - DefaultWidgetsLocalizations.select_all_button_label() - } - fn look_up_button_label(&self) -> &'static str { - DefaultWidgetsLocalizations.look_up_button_label() - } - fn search_web_button_label(&self) -> &'static str { - DefaultWidgetsLocalizations.search_web_button_label() - } - fn share_button_label(&self) -> &'static str { - DefaultWidgetsLocalizations.share_button_label() - } - fn more_button_label(&self) -> &'static str { - DefaultWidgetsLocalizations.more_button_label() - } - fn back_button_label(&self) -> &'static str { - DefaultWidgetsLocalizations.back_button_label() - } - fn delete_button_tooltip(&self) -> &'static str { - "Löschen" - } - fn modal_barrier_dismiss_label(&self) -> &'static str { - DefaultWidgetsLocalizations.modal_barrier_dismiss_label() - } - fn menu_dismiss_label(&self) -> &'static str { - DefaultWidgetsLocalizations.menu_dismiss_label() - } - fn radio_button_unselected_label(&self) -> &'static str { - DefaultWidgetsLocalizations.radio_button_unselected_label() - } - fn search_results_found(&self) -> &'static str { - DefaultWidgetsLocalizations.search_results_found() - } - fn no_results_found(&self) -> &'static str { - DefaultWidgetsLocalizations.no_results_found() - } - fn context_menu_button_label(&self, target: Option<&str>) -> String { - DefaultWidgetsLocalizations.context_menu_button_label(target) - } - fn page_label(&self, page: usize, page_count: usize) -> String { - DefaultWidgetsLocalizations.page_label(page, page_count) - } - fn scroll_position_label(&self) -> &'static str { - DefaultWidgetsLocalizations.scroll_position_label() - } - fn autoplay_pause_label(&self) -> &'static str { - DefaultWidgetsLocalizations.autoplay_pause_label() - } - fn reorder_item_moved(&self, item: Option<&str>, position: usize, count: usize) -> String { - DefaultWidgetsLocalizations.reorder_item_moved(item, position, count) - } - fn autoplay_resume_label(&self) -> &'static str { - DefaultWidgetsLocalizations.autoplay_resume_label() - } - fn minimize_window_label(&self) -> &'static str { - DefaultWidgetsLocalizations.minimize_window_label() - } - fn maximize_window_label(&self) -> &'static str { - DefaultWidgetsLocalizations.maximize_window_label() - } - fn restore_window_label(&self) -> &'static str { - DefaultWidgetsLocalizations.restore_window_label() - } - fn close_window_label(&self) -> &'static str { - DefaultWidgetsLocalizations.close_window_label() - } - } - - #[derive(Debug)] - struct GermanDelegate; - impl LocalizationsDelegate for GermanDelegate { - type Resources = BoxedWidgetsLocalizations; - fn is_supported(&self, _locale: &Locale) -> bool { - true - } - fn load(&self, _locale: &Locale) -> Self::Resources { - BoxedWidgetsLocalizations::new(German) - } - } type Deletions = Rc>; type Build = fn(Deletions) -> BoxedView; @@ -637,12 +515,7 @@ pub fn a_chip_names_its_delete_button_from_the_localizations() { let deletions: Deletions = Rc::new(Cell::new(0)); let chip = chip(Rc::clone(&deletions)); let view = if language == "German" { - Localizations::new( - Locale::try_new("de", None::<&str>).expect("valid German locale"), - vec![BoxedLocalizationsDelegate::new(GermanDelegate)], - chip, - ) - .boxed() + crate::common::in_german(chip) } else { chip }; diff --git a/packages/flui-material/tests/common/mod.rs b/packages/flui-material/tests/common/mod.rs index 2805306138..a05e8636d3 100644 --- a/packages/flui-material/tests/common/mod.rs +++ b/packages/flui-material/tests/common/mod.rs @@ -13,6 +13,14 @@ pub use flui_testing::widgets::*; +use flui_sdk::foundation::TextDirection; +use flui_sdk::platform::Locale; +use flui_sdk::view::{BoxedView, IntoView, ViewExt}; +use flui_sdk::widgets::{ + BoxedLocalizationsDelegate, BoxedWidgetsLocalizations, DefaultWidgetsLocalizations, + Localizations, LocalizationsDelegate, WidgetsLocalizations, +}; + /// Runs every `(name, scenario)` row of a table-driven test. Every row runs, /// and the failure report names each row that failed. pub fn run_cases(cases: &[(&str, fn())]) { @@ -38,8 +46,6 @@ pub fn run_cases(cases: &[(&str, fn())]) { /// [`Unnamed`](flui_protocol::audit::AuditRule::Unnamed) findings on the nodes `unnamed`, one /// each in any order, and nothing else unpassed, soft or skipped. A test of a control the /// application cannot name ends here, so the control stays a finding until it can be named. -/// The controls that end here are listed in `docs/gaps.md`, "A back button and a data -/// table's row checkboxes have no accessible name". pub fn finish_with_unnamed( t: flui_testing::scenario::Tester, unnamed: &[flui_protocol::tree::ElementId], @@ -84,3 +90,134 @@ pub fn finish_with_unnamed( )) } } + +/// `view` under a German [`Localizations`], whose strings are [`German`]'s. +pub fn in_german(view: impl IntoView) -> BoxedView { + Localizations::new( + Locale::try_new("de", None::<&str>).expect("valid German locale"), + vec![BoxedLocalizationsDelegate::new(GermanDelegate)], + view, + ) + .boxed() +} + +/// German widgets localizations: Flutter 3.50.1's German strings for the ones this package +/// builds into its controls' names (`deleteButtonTooltip` "Löschen", `backButtonTooltip` +/// "Zurück", `selectAllButtonLabel` "Alle auswählen"), a row checkbox's "Zeile N auswählen", and +/// the English default for every other string. +#[derive(Debug)] +struct German; + +impl WidgetsLocalizations for German { + fn text_direction(&self) -> TextDirection { + TextDirection::Ltr + } + fn reorder_item_to_start(&self) -> &'static str { + DefaultWidgetsLocalizations.reorder_item_to_start() + } + fn reorder_item_to_end(&self) -> &'static str { + DefaultWidgetsLocalizations.reorder_item_to_end() + } + fn reorder_item_up(&self) -> &'static str { + DefaultWidgetsLocalizations.reorder_item_up() + } + fn reorder_item_down(&self) -> &'static str { + DefaultWidgetsLocalizations.reorder_item_down() + } + fn reorder_item_left(&self) -> &'static str { + DefaultWidgetsLocalizations.reorder_item_left() + } + fn reorder_item_right(&self) -> &'static str { + DefaultWidgetsLocalizations.reorder_item_right() + } + fn copy_button_label(&self) -> &'static str { + DefaultWidgetsLocalizations.copy_button_label() + } + fn cut_button_label(&self) -> &'static str { + DefaultWidgetsLocalizations.cut_button_label() + } + fn paste_button_label(&self) -> &'static str { + DefaultWidgetsLocalizations.paste_button_label() + } + fn select_all_button_label(&self) -> &'static str { + "Alle auswählen" + } + fn look_up_button_label(&self) -> &'static str { + DefaultWidgetsLocalizations.look_up_button_label() + } + fn search_web_button_label(&self) -> &'static str { + DefaultWidgetsLocalizations.search_web_button_label() + } + fn share_button_label(&self) -> &'static str { + DefaultWidgetsLocalizations.share_button_label() + } + fn more_button_label(&self) -> &'static str { + DefaultWidgetsLocalizations.more_button_label() + } + fn back_button_label(&self) -> &'static str { + "Zurück" + } + fn delete_button_tooltip(&self) -> &'static str { + "Löschen" + } + fn modal_barrier_dismiss_label(&self) -> &'static str { + DefaultWidgetsLocalizations.modal_barrier_dismiss_label() + } + fn menu_dismiss_label(&self) -> &'static str { + DefaultWidgetsLocalizations.menu_dismiss_label() + } + fn select_row_label(&self, row: usize) -> String { + format!("Zeile {row} auswählen") + } + fn radio_button_unselected_label(&self) -> &'static str { + DefaultWidgetsLocalizations.radio_button_unselected_label() + } + fn search_results_found(&self) -> &'static str { + DefaultWidgetsLocalizations.search_results_found() + } + fn no_results_found(&self) -> &'static str { + DefaultWidgetsLocalizations.no_results_found() + } + fn context_menu_button_label(&self, target: Option<&str>) -> String { + DefaultWidgetsLocalizations.context_menu_button_label(target) + } + fn page_label(&self, page: usize, page_count: usize) -> String { + DefaultWidgetsLocalizations.page_label(page, page_count) + } + fn scroll_position_label(&self) -> &'static str { + DefaultWidgetsLocalizations.scroll_position_label() + } + fn autoplay_pause_label(&self) -> &'static str { + DefaultWidgetsLocalizations.autoplay_pause_label() + } + fn reorder_item_moved(&self, item: Option<&str>, position: usize, count: usize) -> String { + DefaultWidgetsLocalizations.reorder_item_moved(item, position, count) + } + fn autoplay_resume_label(&self) -> &'static str { + DefaultWidgetsLocalizations.autoplay_resume_label() + } + fn minimize_window_label(&self) -> &'static str { + DefaultWidgetsLocalizations.minimize_window_label() + } + fn maximize_window_label(&self) -> &'static str { + DefaultWidgetsLocalizations.maximize_window_label() + } + fn restore_window_label(&self) -> &'static str { + DefaultWidgetsLocalizations.restore_window_label() + } + fn close_window_label(&self) -> &'static str { + DefaultWidgetsLocalizations.close_window_label() + } +} + +#[derive(Debug)] +struct GermanDelegate; +impl LocalizationsDelegate for GermanDelegate { + type Resources = BoxedWidgetsLocalizations; + fn is_supported(&self, _locale: &Locale) -> bool { + true + } + fn load(&self, _locale: &Locale) -> Self::Resources { + BoxedWidgetsLocalizations::new(German) + } +} diff --git a/packages/flui-material/tests/data_table.rs b/packages/flui-material/tests/data_table.rs index 8b28093898..f813d7c15b 100644 --- a/packages/flui-material/tests/data_table.rs +++ b/packages/flui-material/tests/data_table.rs @@ -7,9 +7,9 @@ //! around its centred checkbox (`RenderPadding`, the only padding a data table builds), the //! checkbox itself the `RenderCenter` in it. A label's glyphs are the paragraph under its node. //! -//! Flutter 3.50.1's `DataTable` gives its checkboxes no label (`_buildCheckbox`), and FLUI's -//! builds them the same way, so no application can name them: a test with checkboxes ends with -//! exactly the audit's finding on each of them. +//! Flutter 3.50.1's `DataTable` gives its checkboxes no label (`_buildCheckbox`). FLUI's names +//! them from the ambient localizations, and a test with checkboxes reads each name before its +//! end, whose audit finds no unnamed control. use std::cell::RefCell; use std::rc::Rc; @@ -18,7 +18,6 @@ use flui_material::{ DataCell, DataColumn, DataRow, DataTable, DataTableThemeData, Theme, ThemeData, }; use flui_objects::{RenderCenter, RenderPadding, RenderParagraph}; -use flui_protocol::tree::ElementId; use flui_protocol::wire::Role; use flui_sdk::geometry::{Rect, Size}; use flui_sdk::rendering::objects::TableColumnWidth; @@ -71,23 +70,23 @@ fn checkbox_cells(t: &mut Tester) -> Vec { cells } -/// The node of every checkbox in the window. -fn checkboxes(t: &mut Tester) -> Vec { - t.find_all(&find::role(Role::CheckBox).all()) +/// Ends `t` after reading that its table names each checkbox as the ambient localizations +/// do: the heading's "Select all", each data row's "Select row N" from the first row down. +/// The end's audit then finds no unnamed control. +fn finish_with_its_checkboxes_named(mut t: Tester) { + let names: Vec> = t + .find_all(&find::role(Role::CheckBox).all()) .into_iter() - .map(|found| found.node.id) - .collect() -} - -/// Ends `t`, whose only findings are its table's unnamed checkboxes. -fn finish_with_its_checkboxes_unnamed(mut t: Tester) { - let unnamed = checkboxes(&mut t); - assert!(!unnamed.is_empty(), "the table has checkboxes"); - if let Err(why) = common::finish_with_unnamed(t, &unnamed) { - panic!("{why}"); - } + .map(|found| found.node.name) + .collect(); + let expected: Vec> = std::iter::once("Select all".to_owned()) + .chain((1..names.len()).map(|row| format!("Select row {row}"))) + .map(Some) + .collect(); + assert!(!names.is_empty(), "the table has checkboxes"); + assert_eq!(names, expected, "each checkbox is named"); + t.finish(); } - // ============================================================================= // Mount + geometry // ============================================================================= @@ -136,7 +135,7 @@ fn table_cell_insets(theme_margin: Option, widget_margin: Option) -> [ label(&mut t, "Entry").left() - cell(&mut t, "Entry").left(), checkbox_cells(&mut t)[0].width(), ]; - finish_with_its_checkboxes_unnamed(t); + finish_with_its_checkboxes_named(t); insets } @@ -208,7 +207,7 @@ pub fn a_data_table_lays_out_from_the_reading_start_edge() { ] }); let checkbox_column_leads = checkbox_cells[0].left() < cell(&mut t, "Name").left(); - finish_with_its_checkboxes_unnamed(t); + finish_with_its_checkboxes_named(t); (checkbox_column_leads, rows) }; @@ -257,12 +256,77 @@ pub fn heading_checkbox_tap_selects_all_from_the_indeterminate_state() { ); let mut t = mount(ThemeData::light(), table); - t.tap(&find::role(Role::CheckBox).all().first()); + t.tap(&find::text("Select all")); let calls = log.borrow().clone(); assert!( !calls.is_empty() && calls.iter().all(|(_, next)| *next), "tapping the indeterminate heading checkbox must select every row, got {calls:?}" ); - finish_with_its_checkboxes_unnamed(t); + finish_with_its_checkboxes_named(t); +} + +/// A table names its checkboxes in the ambient language, where Flutter 3.50.1's `DataTable` +/// leaves them unnamed (`_buildCheckbox`): the heading's from +/// `WidgetsLocalizations::select_all_button_label`, each data row's from `select_row_label` +/// with its 1-based place below the heading. A row without `on_select_changed` shows a +/// checkbox it does not let the user change, named and counted like the others. The English +/// rows read the strings with no `Localizations` above the table and under the global +/// delegate an application installs. +pub fn the_checkboxes_are_named_in_the_ambient_language() { + use flui_sdk::platform::Locale; + use flui_sdk::view::ViewExt; + use flui_sdk::widgets::{ + BoxedLocalizationsDelegate, GlobalWidgetsLocalizationsDelegate, Localizations, + }; + + let table = || { + DataTable::new( + vec![text_column("Name")], + vec![ + DataRow::new(vec![text_cell("Ada")]).on_select_changed(|_ctx, _next| {}), + DataRow::new(vec![text_cell("Grace")]), + DataRow::new(vec![text_cell("Linus")]).on_select_changed(|_ctx, _next| {}), + ], + ) + }; + let english = ["Select all", "Select row 1", "Select row 2", "Select row 3"]; + for (language, view, expected) in [ + ("English without Localizations", table().boxed(), english), + ( + "English under the global delegate", + Localizations::new( + Locale::try_new("en", None::<&str>).expect("valid English locale"), + vec![BoxedLocalizationsDelegate::new( + GlobalWidgetsLocalizationsDelegate, + )], + table(), + ) + .boxed(), + english, + ), + ( + "German", + common::in_german(table()), + [ + "Alle auswählen", + "Zeile 1 auswählen", + "Zeile 2 auswählen", + "Zeile 3 auswählen", + ], + ), + ] { + let mut t = mount(ThemeData::light(), view); + let names: Vec> = t + .find_all(&find::role(Role::CheckBox).all()) + .into_iter() + .map(|found| found.node.name) + .collect(); + assert_eq!( + names, + expected.map(|name| Some(name.to_owned())), + "{language}: each checkbox is named" + ); + t.finish(); + } } diff --git a/packages/flui-material/tests/icon_face.rs b/packages/flui-material/tests/icon_face.rs index bfc80444c6..425a945f2f 100644 --- a/packages/flui-material/tests/icon_face.rs +++ b/packages/flui-material/tests/icon_face.rs @@ -9,10 +9,9 @@ use flui_sdk::foundation::TextDirection; use flui_sdk::view::{BoxedView, ViewExt}; use flui_sdk::widgets::Text; -use flui_protocol::wire::Role; use flui_sdk::geometry::Size; use flui_testing::fixture::Constrain; -use flui_testing::scenario::{TestWindow, Tester, WindowSpec, find}; +use flui_testing::scenario::{TestWindow, Tester, WindowSpec}; /// The glyph indexes `text` shapes to in Material Icons on a new collection. fn glyphs_of(text: &str) -> Vec { @@ -57,8 +56,7 @@ fn an_icon_of_the_family_shapes_to_a_glyph_of_the_embedded_face() { /// names so: the face's own ligature of the icon's name gives the expected /// glyph, so a codepoint taken from another numbering of the icon set (it /// then draws `.notdef` or another icon) fails its row. Each row ends with the -/// end's checks; the `BackButton` row, whose button no application can name -/// yet, ends with exactly the audit's finding on that button. +/// end's checks, whose audit finds every button named. #[test] fn a_widget_draws_the_glyph_the_face_names_for_its_icon() { let back_button = || -> BoxedView { BackButton::new().on_pressed(|_ctx| {}).boxed() }; @@ -112,16 +110,6 @@ fn a_widget_draws_the_glyph_the_face_names_for_its_icon() { [named[0]], "{widget} draws the face's `{icon_name}`" ); - if widget == "BackButton" { - // A `BackButton` takes no label, where Flutter 3.50.1 names it with - // `MaterialLocalizations.backButtonTooltip`: it stays the end's one finding until it - // can be named. - let button = t.read(&find::role(Role::Button)); - if let Err(why) = crate::common::finish_with_unnamed(t, &[button.id]) { - panic!("{widget}: {why}"); - } - } else { - t.finish(); - } + t.finish(); } } diff --git a/packages/flui-material/tests/main.rs b/packages/flui-material/tests/main.rs index fbb4730b64..066f5b277b 100644 --- a/packages/flui-material/tests/main.rs +++ b/packages/flui-material/tests/main.rs @@ -482,6 +482,10 @@ fn selection_control_contracts() { "data_table::heading checkbox tap selects all from the indeterminate state", data_table::heading_checkbox_tap_selects_all_from_the_indeterminate_state, ), + ( + "data_table::the checkboxes are named in the ambient language", + data_table::the_checkboxes_are_named_in_the_ambient_language, + ), ( "data_table::widget override beats theme beats default on a mounted tree", data_table::widget_override_beats_theme_beats_default_on_a_mounted_tree, @@ -677,6 +681,10 @@ fn navigation_and_layout_contracts() { "app_bar::tapping the implied back button pops the route", app_bar::tapping_the_implied_back_button_pops_the_route, ), + ( + "app_bar::a back button is named in the ambient language", + app_bar::a_back_button_is_named_in_the_ambient_language, + ), ( "app_bar::the title announces as a level one heading", app_bar::the_title_announces_as_a_level_one_heading, diff --git a/typos.toml b/typos.toml index 71090fabc2..f217e0afe5 100644 --- a/typos.toml +++ b/typos.toml @@ -50,6 +50,9 @@ extend-ignore-re = [ "\\bEIS\\b", "\\breis::eis\\b", "\\beis::[A-Za-z]", + # Flutter's German `selectAllButtonLabel`, which flui-material's tests install to check that + # a control's name follows the ambient locale. Not the word "Alle" anywhere else. + "Alle auswählen", ] [default.extend-words]