From 6875771a32039e5150c3cf2ebab5f2946dee0fbb Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 18:16:25 +0000 Subject: [PATCH 01/10] semantics: an absorbed configuration's identifier names the node that takes it, first wins Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EqfW4FAhVS5dwwxVx5vRGK --- .../flui-rendering/tests/contract_matrices.rs | 2 +- .../tests/semantics_assembly.rs | 23 +++++++++------- crates/flui-semantics/ARCHITECTURE.md | 26 +++++++++++-------- crates/flui-semantics/src/configuration.rs | 23 ++++++++-------- crates/flui-semantics/tests/identifier.rs | 22 +++++++++++----- docs/plans/specs/flui-driver/tasks.md | 8 +++--- 6 files changed, 61 insertions(+), 43 deletions(-) diff --git a/crates/flui-rendering/tests/contract_matrices.rs b/crates/flui-rendering/tests/contract_matrices.rs index 3cad84f0d3..d34f707927 100644 --- a/crates/flui-rendering/tests/contract_matrices.rs +++ b/crates/flui-rendering/tests/contract_matrices.rs @@ -79,7 +79,7 @@ fn lifecycle_matrix() { fn semantics_assembly_matrix() { let cases: &[(&str, fn())] = &[ ("semantics_assembly::a_semantics_clip_drops_a_child_that_falls_entirely_outside_it", crate::semantics_assembly::a_semantics_clip_drops_a_child_that_falls_entirely_outside_it), - ("semantics_assembly::an_identifier_names_only_the_node_its_configuration_forms", crate::semantics_assembly::an_identifier_names_only_the_node_its_configuration_forms), + ("semantics_assembly::an_identifier_names_the_node_its_configuration_forms_or_joins", crate::semantics_assembly::an_identifier_names_the_node_its_configuration_forms_or_joins), ("semantics_assembly::a_table_shape_the_role_drops_bounds_no_cell", crate::semantics_assembly::a_table_shape_the_role_drops_bounds_no_cell), ("semantics_assembly::nonfinite_reading_order_is_refused_before_publication", crate::semantics_assembly::nonfinite_reading_order_is_refused_before_publication), ("semantics_assembly::re_assembling_marked_subtrees_refuses_like_the_whole_tree", crate::semantics_assembly::re_assembling_marked_subtrees_refuses_like_the_whole_tree), diff --git a/crates/flui-rendering/tests/semantics_assembly.rs b/crates/flui-rendering/tests/semantics_assembly.rs index 550abe087a..282776be26 100644 --- a/crates/flui-rendering/tests/semantics_assembly.rs +++ b/crates/flui-rendering/tests/semantics_assembly.rs @@ -758,11 +758,12 @@ fn identified(identifier: &str, label: Option<&str>) -> SemanticsConfiguration { } config } -/// An identifier names only the node its own configuration forms -/// (ADR-0240): a boundary keeps it, a contributor absorbed into its -/// ancestor and a boundary under a merge lose it, and an identifier alone -/// forms no node. -pub(crate) fn an_identifier_names_only_the_node_its_configuration_forms() { +/// An identifier names the node its configuration forms or joins +/// (ADR-0407): a boundary keeps its own, a contributor absorbed into its +/// ancestor names that ancestor when it has none, a merged parent keeps its +/// own over its merged child's, and an identifier alone forms and joins no +/// node. +pub(crate) fn an_identifier_names_the_node_its_configuration_forms_or_joins() { // The walk root's own children always form nodes, so the cases sit under // a plain boundary, where contributors are absorbed. let run = RenderTester::mount( @@ -776,12 +777,13 @@ pub(crate) fn an_identifier_names_only_the_node_its_configuration_forms() { }) .label("save"), ) + // Before the note, so a bare identifier that joined would win. .child(box_node(SemanticsLeaf { - configuration: Some(identified("note-id", Some("Note"))), + configuration: Some(identified("bare-id", None)), ..SemanticsLeaf::new(20.0) })) .child(box_node(SemanticsLeaf { - configuration: Some(identified("bare-id", None)), + configuration: Some(identified("note-id", Some("Note"))), ..SemanticsLeaf::new(20.0) })) .child( @@ -822,13 +824,14 @@ pub(crate) fn an_identifier_names_only_the_node_its_configuration_forms() { assert_eq!(node_of(save).config().identifier(), Some("save-id")); assert_eq!( node_of(group).config().identifier(), - None, - "an absorbed contributor's identifier does not cross into its ancestor" + Some("note-id"), + "an absorbed contributor names the ancestor that has no identifier; \ + the bare identifier beside it is absorbed by nobody" ); assert_eq!( node_of(group).label(), Some("Note"), - "the absorbed label arrives without its identifier" + "the absorbed label arrives without its identifier as text" ); assert_eq!( node_of(card).config().identifier(), diff --git a/crates/flui-semantics/ARCHITECTURE.md b/crates/flui-semantics/ARCHITECTURE.md index ee6aa8c0a3..68ed0aaf78 100644 --- a/crates/flui-semantics/ARCHITECTURE.md +++ b/crates/flui-semantics/ARCHITECTURE.md @@ -851,17 +851,20 @@ cross-thread handoff is the AccessKit `TreeUpdate`. `SemanticsAttributes` is the consumers read and write a node through `SemanticsConfiguration`'s accessors. A selection-only annotation still reaches the platform (`a_selection_only_annotation_reaches_the_platform`). -### The identifier names only the node its own configuration forms +### The identifier names the node its configuration forms or joins **Rule.** [ADR-0240](../../docs/adr/ADR-0240-semantics-identifier.md)'s identifier is published as AccessKit `author_id` and as the wire `Node.identifier`, and never as text. Setting it neither marks -the configuration annotated nor makes it a boundary, and `absorb` never takes it: a configuration -with only an identifier contributes nothing, and one absorbed into an ancestor or a -`MergeSemantics` loses it while the receiver keeps its own. A widget names its node where the node -is formed: a container `Semantics`, `MergeSemantics::identifier`, or a control whose own -configuration is the outermost of its parts. A node AccessKit's filter lifts into its parent (no -role, label or text, or the `Generic` or `Presentation` role) takes its identifier with it, so no -agent or OS automation locator selects it (the web mirror still writes `data-flui-id`). +the configuration annotated nor makes it a boundary, so a configuration with only an identifier +contributes nothing and names no node. `absorb` carries it, first wins +([ADR-0407](../../docs/adr/ADR-0407-a-control-joins-the-semantics-annotation-above-it.md)): a +configuration absorbed into an ancestor or a `MergeSemantics` names that node when the node has no +identifier of its own, and the receiver keeps its own when it has one. So a control that joins the +`Semantics` above it keeps its identifier on the node it joined, as Flutter's +`SemanticsConfiguration.absorb` does (flutter/flutter@3.50.1 +`packages/flutter/lib/src/semantics/semantics.dart:6954`). A node AccessKit's filter lifts into its +parent (no role, label or text, or the `Generic` or `Presentation` role) takes its identifier with +it, so no agent or OS automation locator selects it (the web mirror still writes `data-flui-id`). `read_wire` lists a `TreeDiagnostic::UnpublishedIdentifier` for each identifier and node it is lifted into, at most 4 nodes per identifier (a row template names its first rows) and 256 in all, and the deprecated `flui_testing::tester::TestError::UnpublishedIdentifier` (the scenario @@ -872,10 +875,11 @@ a failure, so `to_be_gone` still passes on a lifted identifier. Past the cap a lookup falls back to `NotFound`. **Why.** An identifier that annotated or split nodes would change the tree, and so what a screen -reader says, by adding a test id; one carried upward would name a node with another node's id, and -a merged parent would collect its children's. +reader says, by adding a test id. One dropped on absorb would lose a control's id whenever the +control joins the annotation that names it; first wins keeps a node that names itself from taking +a descendant's id, and keeps a merged parent to one id. -**Test.** `the_identifier_is_exported_unannounced_unmerged_and_no_boundary` in +**Test.** `the_identifier_is_exported_unannounced_no_boundary_and_joins_first_wins` in `tests/identifier.rs`, `an_identifier_on_a_node_that_publishes_nothing_else_is_reported` and `unpublished_identifiers_are_reported_once_per_parent_and_bounded`, `an_identifier_lifted_under_many_parents_leaves_room_for_the_rest` there; the `identifier` row of diff --git a/crates/flui-semantics/src/configuration.rs b/crates/flui-semantics/src/configuration.rs index 23e48107d8..9912b18087 100644 --- a/crates/flui-semantics/src/configuration.rs +++ b/crates/flui-semantics/src/configuration.rs @@ -907,13 +907,13 @@ impl SemanticsConfiguration { /// /// It is never announced, and it is not semantic payload: setting it /// marks nothing annotated and makes no boundary, so adding one never - /// changes the tree's shape or what a screen reader says. It names only - /// the node this configuration forms itself, as a boundary or as an - /// explicit child. A configuration that forms none (absorbed into an - /// ancestor, merged by `MergeSemantics`, or contributing nothing) publishes - /// no identifier: [`absorb`](Self::absorb) never carries one upward, so a - /// merged parent keeps its own. Name a node by setting the identifier where - /// its boundary is declared. A node with no role, label or text, or with + /// changes the tree's shape or what a screen reader says. It names the + /// node this configuration forms or joins: [`absorb`](Self::absorb) + /// carries it into the node that takes this configuration, first wins, so + /// a control absorbed into the `Semantics` above it, or merged by + /// `MergeSemantics`, names that node unless the node names itself + /// (ADR-0407). A configuration that contributes nothing else is absorbed + /// by nobody, and its identifier names no node. A node with no role, label or text, or with /// the `Generic` or `Presentation` role, is lifted into its parent by the /// agent and the AccessKit adapters, its identifier with it, and a wire /// read reports that identifier as unpublished. @@ -1667,7 +1667,7 @@ impl SemanticsConfiguration { label: _, value, hint: _, - // Never crosses into another node, so two never compete. + // First wins on absorb, so two never compete. identifier: _, text_direction: _, text, @@ -1857,9 +1857,9 @@ impl SemanticsConfiguration { label, value, hint, - // Never carried upward (ADR-0240): the identifier names only the - // node its own configuration forms, and a merged parent keeps its own. - identifier: _, + // First wins below (ADR-0407): the node a control joins carries + // the control's identifier unless it names itself. + identifier, text_direction, text, heading_level, @@ -1896,6 +1896,7 @@ impl SemanticsConfiguration { mine.live = *live; mine.live_atomic = *live_atomic; } + keep(&mut mine.identifier, identifier.as_ref()); keep(&mut mine.value, value.as_ref()); keep(&mut mine.text_direction, text_direction.as_ref()); keep(&mut mine.text, text.as_ref()); diff --git a/crates/flui-semantics/tests/identifier.rs b/crates/flui-semantics/tests/identifier.rs index a1922c7963..a9844a7fbf 100644 --- a/crates/flui-semantics/tests/identifier.rs +++ b/crates/flui-semantics/tests/identifier.rs @@ -100,10 +100,10 @@ struct Claim { holds: fn() -> bool, } -/// Exported, never announced, never merged into another node, and no -/// boundary of its own: every claim holds. +/// Exported, never announced, carried into the node that absorbs it (first +/// wins, a parent keeps its own), and no boundary of its own: every claim holds. #[test] -fn the_identifier_is_exported_unannounced_unmerged_and_no_boundary() { +fn the_identifier_is_exported_unannounced_no_boundary_and_joins_first_wins() { let claims = [ Claim { claim: "exported to the adapter as author_id", @@ -137,19 +137,29 @@ fn the_identifier_is_exported_unannounced_unmerged_and_no_boundary() { }, }, Claim { - claim: "not merged: a parent absorbing the node takes its label, not its identifier", + claim: "joins: a parent with none takes the identifier, and not as text", holds: || { let mut parent = SemanticsConfiguration::new(); parent.set_label("Row 7"); parent.absorb(&named("Delete", IDENTIFIER)); - parent.identifier().is_none() + parent.identifier() == Some(IDENTIFIER) && parent .label() .is_some_and(|label| !label.contains(IDENTIFIER)) }, }, Claim { - claim: "not merged: a merged parent keeps its own identifier", + claim: "joins first wins: the first of two absorbed identifiers names the parent", + holds: || { + let mut parent = SemanticsConfiguration::new(); + parent.set_label("Row 7"); + parent.absorb(&named("Delete", IDENTIFIER)); + parent.absorb(&named("Edit", "edit")); + parent.identifier() == Some(IDENTIFIER) + }, + }, + Claim { + claim: "joins first wins: a parent keeps its own identifier", holds: || { let mut parent = named("Row 7", "row-7"); parent.absorb(&named("Delete", IDENTIFIER)); diff --git a/docs/plans/specs/flui-driver/tasks.md b/docs/plans/specs/flui-driver/tasks.md index ac2586ab5c..ac18998726 100644 --- a/docs/plans/specs/flui-driver/tasks.md +++ b/docs/plans/specs/flui-driver/tasks.md @@ -201,16 +201,16 @@ graph LR with the locator work (FD3) or the OS lanes. - Tests: - `flui-semantics`'s `semantics_it`: - `identifier::the_identifier_is_exported_unannounced_unmerged_and_no_boundary`, a table of - export (`author_id`, wire `identifier`), not announced (adapter and wire), not merged - (label without identifier, merged parent keeps its own) and no boundary; the `identifier` + `identifier::the_identifier_is_exported_unannounced_no_boundary_and_joins_first_wins`, a table of + export (`author_id`, wire `identifier`), not announced (adapter and wire), absorbed first + wins (a parent with none takes it, a parent keeps its own) and no boundary; the `identifier` row of `every_published_attribute_reads_through_the_consumer`; `identifier::siblings_sharing_an_identifier_are_reported_and_published_as_written` and `identifier::debug_builds_queue_a_published_clash_once_per_shape`; - `flui-protocol`: `diagnostics_are_tagged_and_an_unknown_kind_still_reads`, and the `0.6` schema golden; - `flui-rendering`'s `semantics_assembly_matrix`: - `an_identifier_names_only_the_node_its_configuration_forms`, through assembly; + `an_identifier_names_the_node_its_configuration_forms_or_joins`, through assembly; - `flui-widgets`' `semantics_translation_and_routing`: `controls_publish_their_identifier_on_the_node_they_form`, whose `Slider` row also requires the identified node to be the focusable one with the numeric actions; From b1803a5ddc0fdfa544695d0a63d0fd325dd20bc2 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 18:19:19 +0000 Subject: [PATCH 02/10] widgets: a control's description joins the annotation above it unless its Flutter counterpart is a container Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EqfW4FAhVS5dwwxVx5vRGK --- crates/flui-widgets/src/interaction/node.rs | 56 +++++++++++++++---- .../src/interaction/raw_button.rs | 1 + .../flui-material/src/button_style_button.rs | 4 +- packages/flui-material/src/checkbox.rs | 4 +- packages/flui-material/src/chip.rs | 25 ++++++--- .../src/floating_action_button.rs | 6 +- packages/flui-material/src/list_tile.rs | 14 +++-- packages/flui-material/src/radio.rs | 4 +- packages/flui-material/src/switch.rs | 4 +- 9 files changed, 88 insertions(+), 30 deletions(-) diff --git a/crates/flui-widgets/src/interaction/node.rs b/crates/flui-widgets/src/interaction/node.rs index da866d88ab..433e252193 100644 --- a/crates/flui-widgets/src/interaction/node.rs +++ b/crates/flui-widgets/src/interaction/node.rs @@ -83,26 +83,45 @@ pub struct InteractiveNode { child: BoxedView, } -/// What a control says of itself to assistive technology: one node of a -/// role. A view holds this in place of the [`Semantics`] it stands for, +/// What a control says of itself to assistive technology: a configuration of +/// a role. A view holds this in place of the [`Semantics`] it stands for, /// which the node builds only while its window collects semantics /// (ADR-0322 §8), so the view stays small in every copy the tree keeps. /// /// It holds only what the control declares about itself: its role, name, -/// toggle and selection state, anchor and whether it merges what is beneath -/// it. Labels, hints and actions come from its children and from the node's -/// own parts, never from here. +/// toggle and selection state, anchor and the node it forms. Labels, hints +/// and actions come from its children and from the node's own parts, never +/// from here. +/// +/// It is an annotation, as Flutter's `Semantics` is by default: it forms a +/// node only where its parent asks for explicit children, and otherwise joins +/// the annotation above it, so `Semantics::label` around the control names +/// the control's own node (ADR-0407). A control whose Flutter counterpart is +/// a container says [`container`](Self::container). #[derive(Clone, Debug)] pub struct Description { role: SemanticsRole, toggled: Option, selected: Option, - merges_descendants: bool, + form: NodeForm, /// What names the node, which few controls set: shared and absent /// otherwise, so the view of every other control stays small. names: Option>, } +/// The node a [`Description`] forms, as `Semantics` spells it. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum NodeForm { + /// Joins the annotation above it unless its parent asks for explicit + /// children: `Semantics` with `container` off. + Annotation, + /// A node of its own wherever it is: `Semantics::container(true)`. + Container, + /// A node of its own that folds every node beneath it into itself: + /// [`MergeSemantics`](crate::MergeSemantics). + Merge, +} + /// The names a [`Description`] gives its node. #[derive(Clone, Debug, Default)] struct Names { @@ -111,18 +130,30 @@ struct Names { } impl Description { - /// One container node of `role`, which says nothing more. + /// An annotation of `role`, which says nothing more. #[must_use] pub fn new(role: SemanticsRole) -> Self { Self { role, toggled: None, selected: None, - merges_descendants: false, + form: NodeForm::Annotation, names: None, } } + /// Form a node of its own wherever the control is, as + /// `Semantics::container(true)` does: a control whose Flutter counterpart + /// is a container (`ButtonStyleButton`, `RawMaterialButton`, `RawChip`). + /// A label around such a control is a node of its own above it. + #[must_use] + pub fn container(mut self) -> Self { + if self.form == NodeForm::Annotation { + self.form = NodeForm::Container; + } + self + } + /// The names to write, allocated on the first one a control sets. fn names_mut(&mut self) -> &mut Names { Rc::make_mut(self.names.get_or_insert_with(Rc::default)) @@ -162,17 +193,18 @@ impl Description { /// Fold every node beneath the control into its own, as a /// [`MergeSemantics`](crate::MergeSemantics) around it does: a tab or a - /// destination is one node with its icon's and label's text. + /// destination is one node with its icon's and label's text. A merge is + /// a node of its own, as `MergeSemantics` is. #[must_use] pub fn merges_descendants(mut self) -> Self { - self.merges_descendants = true; + self.form = NodeForm::Merge; self } fn build(&self) -> Semantics { let names = self.names.as_deref(); let mut semantics = Semantics::new() - .container(true) + .container(self.form != NodeForm::Annotation) .role(self.role) .identifier_if(names.and_then(|names| names.identifier.as_ref())); if let Some(state) = self.toggled { @@ -184,7 +216,7 @@ impl Description { if let Some(anchor) = names.and_then(|names| names.anchor.as_ref()) { semantics = semantics.anchor(anchor.clone()); } - if self.merges_descendants { + if self.form == NodeForm::Merge { semantics = semantics.merging_descendants(); } semantics diff --git a/crates/flui-widgets/src/interaction/raw_button.rs b/crates/flui-widgets/src/interaction/raw_button.rs index e6a85ab5a9..37d972d501 100644 --- a/crates/flui-widgets/src/interaction/raw_button.rs +++ b/crates/flui-widgets/src/interaction/raw_button.rs @@ -174,6 +174,7 @@ impl StatelessView for RawButton { let press = Rc::new(Press(self.on_pressed.clone())); // One node for assistive technology: the button. let description = Description::new(flui_semantics::SemanticsRole::Button) + .container() .identifier(self.identifier.clone()); // The bindings are the node's own, so its focus node records them // and the root bindings resolve the activation here (ADR-0079). diff --git a/packages/flui-material/src/button_style_button.rs b/packages/flui-material/src/button_style_button.rs index 725773a1ce..23b8854287 100644 --- a/packages/flui-material/src/button_style_button.rs +++ b/packages/flui-material/src/button_style_button.rs @@ -362,7 +362,9 @@ impl ViewState for ButtonStyleButtonCoreState { // of this description, `enabled` from the node's switch, and the tap // and focus the node adds (ADR-0322 §1). let mut description = - Description::new(SemanticsRole::Button).identifier(view.identifier.clone()); + Description::new(SemanticsRole::Button) + .container() + .identifier(view.identifier.clone()); if let Some(selected) = view.selected { description = description.toggled(Toggled::from_bool(selected)); } diff --git a/packages/flui-material/src/checkbox.rs b/packages/flui-material/src/checkbox.rs index 198598dcc3..9152ae3c10 100644 --- a/packages/flui-material/src/checkbox.rs +++ b/packages/flui-material/src/checkbox.rs @@ -451,7 +451,9 @@ impl ViewState for CheckboxState { .focus_indicator(FocusIndicator::Halo) // Flutter's `Semantics(checked: …, mixed: …, enabled: …)` around // the checkbox: the well's node is that one node, enabled while - // the well has its tap. + // the well has its tap. No container, so a `Semantics` label + // around the checkbox names it (flutter/flutter@3.50.1 + // `packages/flutter/lib/src/material/checkbox.dart:615`, ADR-0407). .description( Description::new(SemanticsRole::CheckBox) .identifier(view.identifier.clone()) diff --git a/packages/flui-material/src/chip.rs b/packages/flui-material/src/chip.rs index 585345fa62..0c5f2f5d0d 100644 --- a/packages/flui-material/src/chip.rs +++ b/packages/flui-material/src/chip.rs @@ -574,7 +574,11 @@ impl StatelessView for Chip { .child(padded_content) .shape(shape) .enabled(self.enabled) - .description(Description::new(role).identifier(self.identifier.clone())); + .description( + Description::new(role) + .container() + .identifier(self.identifier.clone()), + ); if let Some(on_pressed) = self.on_pressed.clone() { ink_well = ink_well.on_tap(move |ctx| on_pressed(ctx)); } @@ -845,13 +849,16 @@ impl StatelessView for FilterChip { // A filter chip is a toggle button: ARIA carries its selection as the // button's pressed state, which `aria-selected` on a button is not. - // Flutter's `Semantics(button: true, toggled: …, enabled: …)` around - // the chip is the well's node, enabled while the well has its tap. + // `RawChip`'s `Semantics(container: true, button: …, …)` around the + // chip (flutter/flutter@3.50.1 + // `packages/flutter/lib/src/material/chip.dart:1503`) is the well's + // node, enabled while the well has its tap. let mut ink_well = InkWell::new() .child(padded_content) .shape(shape) .description( Description::new(SemanticsRole::Button) + .container() .identifier(self.identifier.clone()) .toggled(Toggled::from_bool(selected)), ); @@ -878,10 +885,12 @@ impl StatelessView for FilterChip { /// 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 -/// with the chip's `on_pressed`. Flutter wraps it in `Semantics(container: -/// true, button: true, label: deleteButtonTooltipMessage)`; the label waits on -/// localization support (see [`Chip`]'s docs' deferrals). Off, it is a -/// disabled button that takes no tap. +/// with the chip's `on_pressed`. Flutter wraps it in a semantics boundary of +/// its own (`_RenderEnsureMinSemanticsSize`, flutter/flutter@3.50.1 +/// `packages/flutter/lib/src/material/chip.dart:2470`) over a `Tooltip` of +/// `deleteButtonTooltipMessage`; the label waits on localization support +/// (see [`Chip`]'s docs' deferrals). Off, it is a disabled button that takes +/// no tap. fn delete_button( glyph: IconData, color: Color, @@ -895,7 +904,7 @@ fn delete_button( )) .shape(MaterialShape::Stadium) .enabled(enabled) - .description(Description::new(SemanticsRole::Button)); + .description(Description::new(SemanticsRole::Button).container()); if enabled { button = button.on_tap(move |ctx| on_deleted(ctx)); } diff --git a/packages/flui-material/src/floating_action_button.rs b/packages/flui-material/src/floating_action_button.rs index 50ce9672b8..2466fce7c0 100644 --- a/packages/flui-material/src/floating_action_button.rs +++ b/packages/flui-material/src/floating_action_button.rs @@ -367,9 +367,11 @@ impl ViewState for FloatingActionButtonState { // The switch this button seeds `Disabled` from, given to the // well whose node writes it. .enabled(view.is_interactive()) - // Flutter's `RawMaterialButton` is `Semantics(button: true)`; the + // Flutter's `RawMaterialButton` is `Semantics(container: true, + // button: true)` (flutter/flutter@3.50.1 + // `packages/flutter/lib/src/material/button.dart:433`); the // well's switch says whether it is enabled. - .description(Description::new(SemanticsRole::Button)); + .description(Description::new(SemanticsRole::Button).container()); if let Some(on_pressed) = view.on_pressed.clone() { ink_well = ink_well.on_tap(move |ctx| on_pressed(ctx)); } diff --git a/packages/flui-material/src/list_tile.rs b/packages/flui-material/src/list_tile.rs index c8790f10fd..9f8d7354f6 100644 --- a/packages/flui-material/src/list_tile.rs +++ b/packages/flui-material/src/list_tile.rs @@ -790,10 +790,13 @@ impl StatelessView for ListTile { // the tile says, and the node stays put when the handler comes or goes. // // A plain tile (no handler, not selectable) declares nothing while - // enabled, so its text folds into the node above it as Flutter's - // non-container `Semantics` lets it. Disabled, it is a node of its own - // that says so: Flutter folds `enabled: false` upward too, which would - // say an enclosing list or row is disabled. + // enabled, so its text folds into the node above it, and an enabled + // tile that declares a role joins the annotation above it, as + // Flutter's non-container `Semantics(button:, selected:, enabled:)` + // around the tile does (flutter/flutter@3.50.1 + // `packages/flutter/lib/src/material/list_tile.dart:995`). Disabled, + // it is a node of its own that says so: Flutter folds `enabled: false` + // upward too, which would say an enclosing list or row is disabled. let role = if self.selectable { Some(SemanticsRole::ListBoxOption) } else if self.on_tap.is_some() { @@ -813,6 +816,9 @@ impl StatelessView for ListTile { if self.selectable { description = description.selected(self.selected); } + if !self.enabled { + description = description.container(); + } ink_well = ink_well.description(description); } if let Some(on_tap) = self.on_tap.clone() { diff --git a/packages/flui-material/src/radio.rs b/packages/flui-material/src/radio.rs index 5aff6e2d88..a0bac5ccca 100644 --- a/packages/flui-material/src/radio.rs +++ b/packages/flui-material/src/radio.rs @@ -343,7 +343,9 @@ impl ViewState> for RadioState { .focus_indicator(FocusIndicator::Halo) // Flutter's `Semantics(checked: …, inMutuallyExclusiveGroup: true, // enabled: …)` around the radio: the well's node is that one node, - // enabled while the well has its tap. + // enabled while the well has its tap. No container, so a + // `Semantics` label around the radio names it (flutter/flutter@3.50.1 + // `packages/flutter/lib/src/widgets/raw_radio.dart:224`, ADR-0407). .description( Description::new(SemanticsRole::RadioButton) .identifier(view.identifier.clone()) diff --git a/packages/flui-material/src/switch.rs b/packages/flui-material/src/switch.rs index daf3ce8420..04ceb41c65 100644 --- a/packages/flui-material/src/switch.rs +++ b/packages/flui-material/src/switch.rs @@ -405,7 +405,9 @@ impl ViewState for SwitchState { .focus_indicator(FocusIndicator::Halo) // Flutter's `Semantics(toggled: …, enabled: …)` around the switch: // the well's node is that one node, enabled while the well has its - // tap. + // tap. No container, so a `Semantics` label around the switch + // names it (flutter/flutter@3.50.1 + // `packages/flutter/lib/src/material/switch.dart:1075`, ADR-0407). .description( Description::new(SemanticsRole::Switch) .identifier(view.identifier.clone()) From 8f1523c77e165b6eb6532cd0f3073baaf80aa504 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 18:36:57 +0000 Subject: [PATCH 03/10] flui-material: a label around a toggle names the toggle's own node, and a container button keeps its own Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EqfW4FAhVS5dwwxVx5vRGK --- Cargo.lock | 1 + packages/flui-material/Cargo.toml | 3 + packages/flui-material/tests/main.rs | 11 ++ .../flui-material/tests/named_by_semantics.rs | 126 ++++++++++++++++++ 4 files changed, 141 insertions(+) create mode 100644 packages/flui-material/tests/named_by_semantics.rs diff --git a/Cargo.lock b/Cargo.lock index fc477c661f..abb5ab64c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2214,6 +2214,7 @@ dependencies = [ "flui-interaction", "flui-layer", "flui-painting", + "flui-protocol", "flui-sdk", "flui-testing", "flui-view", diff --git a/packages/flui-material/Cargo.toml b/packages/flui-material/Cargo.toml index 9204f1a4a4..1054ebaceb 100644 --- a/packages/flui-material/Cargo.toml +++ b/packages/flui-material/Cargo.toml @@ -40,6 +40,9 @@ flui-painting = { workspace = true } # (`flui_testing::widgets`), a dev edge only, so the normal build never links # the test driver. flui-testing = { workspace = true } +# The agent protocol's vocabulary the scenario tester's finders name (`Role`), +# which `flui_testing::scenario` takes without re-exporting. +flui-protocol = { workspace = true } # Committed scene inspection includes ancestor transform and opacity layers. flui-layer = { workspace = true } # The scaffold messenger's fault tests mount a probe on a bare build owner and diff --git a/packages/flui-material/tests/main.rs b/packages/flui-material/tests/main.rs index ad255504ff..fb103349ff 100644 --- a/packages/flui-material/tests/main.rs +++ b/packages/flui-material/tests/main.rs @@ -174,6 +174,9 @@ mod material; #[path = "material_app.rs"] mod material_app; +#[path = "named_by_semantics.rs"] +mod named_by_semantics; + #[path = "navigation_bar.rs"] mod navigation_bar; @@ -507,6 +510,14 @@ fn selection_control_contracts() { "checkbox::toggles and chips are one node with their state", checkbox::toggles_and_chips_are_one_node_with_their_state, ), + ( + "named_by_semantics::a label around a toggle names the toggles own node", + named_by_semantics::a_label_around_a_toggle_names_the_toggles_own_node, + ), + ( + "named_by_semantics::a label around a container control is a node above it", + named_by_semantics::a_label_around_a_container_control_is_a_node_above_it, + ), ( "radio::a mounted radio announces as a radio button", radio::a_mounted_radio_announces_as_a_radio_button, diff --git a/packages/flui-material/tests/named_by_semantics.rs b/packages/flui-material/tests/named_by_semantics.rs new file mode 100644 index 0000000000..dd4701b30e --- /dev/null +++ b/packages/flui-material/tests/named_by_semantics.rs @@ -0,0 +1,126 @@ +//! A `Semantics` label around a control names the control's own node, as in Flutter 3.50.1, where +//! a toggle's `Semantics` is no container and joins the annotation above it (ADR-0407). A control +//! whose Flutter counterpart is a container keeps a node of its own beneath the label. +//! +//! Each row mounts `Semantics::new().label(LABEL)` around a control that carries its own +//! identifier, then finds the node by that label alone: one node, of the control's role, with the +//! control's identifier, whose tap reaches the control's handler. + +use std::cell::Cell; +use std::rc::Rc; + +use flui_material::{Checkbox, ElevatedButton, Radio, Switch, Theme, ThemeData}; +use flui_protocol::wire::Role; +use flui_sdk::view::{BoxedView, ViewExt}; +use flui_sdk::widgets::{Semantics, Text}; +use flui_testing::scenario::{TestWindow, Tester, WindowSpec, find}; + +const LABEL: &str = "Wi-Fi"; +const IDENTIFIER: &str = "wifi"; + +/// One control, built to count its taps. +struct Row { + control: &'static str, + role: Role, + build: fn(Rc>) -> BoxedView, +} + +fn labelled(control: BoxedView) -> Theme { + Theme::new( + ThemeData::light(), + Semantics::new().label(LABEL).child(control), + ) +} + +fn window() -> TestWindow { + TestWindow::new(WindowSpec::new(120, 60)) +} + +pub fn a_label_around_a_toggle_names_the_toggles_own_node() { + let rows = [ + Row { + control: "Switch", + role: Role::Switch, + build: |taps| { + Switch::new(false) + .identifier(IDENTIFIER) + .on_changed(move |_ctx, _| taps.set(taps.get() + 1)) + .boxed() + }, + }, + Row { + control: "Checkbox", + role: Role::CheckBox, + build: |taps| { + Checkbox::new(false) + .identifier(IDENTIFIER) + .on_changed(move |_ctx, _| taps.set(taps.get() + 1)) + .boxed() + }, + }, + Row { + control: "Radio", + role: Role::RadioButton, + build: |taps| { + Radio::new("summer", Some("spring")) + .identifier(IDENTIFIER) + .on_changed(move |_ctx, _| taps.set(taps.get() + 1)) + .boxed() + }, + }, + ]; + + for row in rows { + let taps = Rc::new(Cell::new(0_u32)); + let mut t = Tester::mount_in(labelled((row.build)(Rc::clone(&taps))), window()); + + // Strict: a label that formed a node beside the control would match twice + // or name a node of another role. + let named = t.read(&find::text(LABEL)); + assert_eq!(named.role, row.role, "{}: the label names the control", row.control); + assert_eq!( + named.identifier.as_deref(), + Some(IDENTIFIER), + "{}: the node keeps the control's identifier", + row.control + ); + assert_eq!( + t.read(&find::id(IDENTIFIER)).id, + named.id, + "{}: the identifier and the label find one node", + row.control + ); + assert_eq!( + t.read(&find::role(row.role)).id, + named.id, + "{}: the control has no second node", + row.control + ); + + t.tap(&find::text(LABEL)); + assert_eq!(taps.get(), 1, "{}: the named node's tap is the control's", row.control); + t.finish(); + } +} + +/// `ButtonStyleButton` is `Semantics(container: true, button: …)` in Flutter 3.50.1 +/// (`packages/flutter/lib/src/material/button_style_button.dart:591`): a label around it is a +/// node of its own, and the button keeps the name its child gives it. +pub fn a_label_around_a_container_control_is_a_node_above_it() { + let mut t = Tester::mount_in( + labelled( + ElevatedButton::new(Text::new("Send")) + .identifier(IDENTIFIER) + .on_pressed(|_ctx| {}) + .boxed(), + ), + window(), + ); + + let button = t.read(&find::button("Send")); + assert_eq!(button.identifier.as_deref(), Some(IDENTIFIER)); + let label = t.read(&find::text(LABEL)); + assert_ne!(label.id, button.id, "the label is a node above the button"); + assert_ne!(label.role, Role::Button); + t.finish(); +} From a89bce89a92282e6fd0579702ebf572954768c7d Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 18:40:22 +0000 Subject: [PATCH 04/10] =?UTF-8?q?docs:=20ADR-0407,=20a=20control=20joins?= =?UTF-8?q?=20the=20semantics=20annotation=20above=20it;=20ADR-0322=20?= =?UTF-8?q?=C2=A76=20and=20ADR-0240=20=C2=A71=20state=20the=20new=20rule?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EqfW4FAhVS5dwwxVx5vRGK --- changelog.d/claude-project-thread-f2wym8.md | 10 + crates/flui-semantics/src/configuration.rs | 8 +- docs/adr/ADR-0240-semantics-identifier.md | 9 +- ...l-mounts-one-element-for-its-behaviours.md | 6 +- ...joins-the-semantics-annotation-above-it.md | 187 ++++++++++++++++++ .../flui-material/src/button_style_button.rs | 7 +- .../flui-material/tests/named_by_semantics.rs | 13 +- 7 files changed, 227 insertions(+), 13 deletions(-) create mode 100644 changelog.d/claude-project-thread-f2wym8.md create mode 100644 docs/adr/ADR-0407-a-control-joins-the-semantics-annotation-above-it.md diff --git a/changelog.d/claude-project-thread-f2wym8.md b/changelog.d/claude-project-thread-f2wym8.md new file mode 100644 index 0000000000..845ce0d1bb --- /dev/null +++ b/changelog.d/claude-project-thread-f2wym8.md @@ -0,0 +1,10 @@ +### Changed + +- `Semantics::label` around a `Switch`, `Checkbox`, `Radio`, `CupertinoButton`, a tappable + carousel item or an enabled `ListTile` names that control's own node, as in Flutter 3.50.1: + their semantics are no longer a container of their own and join the annotation above them. + Buttons, chips, a chip's delete button and a disabled `ListTile` stay nodes of their own + (ADR-0407). +- A semantics configuration absorbed into another node gives that node its identifier when the + node has none of its own, first wins, so a control's `identifier` survives joining the + `Semantics` that names it (ADR-0407). diff --git a/crates/flui-semantics/src/configuration.rs b/crates/flui-semantics/src/configuration.rs index 9912b18087..974448dbba 100644 --- a/crates/flui-semantics/src/configuration.rs +++ b/crates/flui-semantics/src/configuration.rs @@ -913,10 +913,10 @@ impl SemanticsConfiguration { /// a control absorbed into the `Semantics` above it, or merged by /// `MergeSemantics`, names that node unless the node names itself /// (ADR-0407). A configuration that contributes nothing else is absorbed - /// by nobody, and its identifier names no node. A node with no role, label or text, or with - /// the `Generic` or `Presentation` role, is lifted into its parent by the - /// agent and the AccessKit adapters, its identifier with it, and a wire - /// read reports that identifier as unpublished. + /// by nobody, and its identifier names no node. A node with no role, + /// label or text, or with the `Generic` or `Presentation` role, is lifted + /// into its parent by the agent and the AccessKit adapters, its identifier + /// with it, and a wire read reports that identifier as unpublished. pub fn set_identifier(&mut self, identifier: impl Into>) { self.attributes.identifier = Some(identifier.into()); } diff --git a/docs/adr/ADR-0240-semantics-identifier.md b/docs/adr/ADR-0240-semantics-identifier.md index f2ec3df0a3..65a2df50f9 100644 --- a/docs/adr/ADR-0240-semantics-identifier.md +++ b/docs/adr/ADR-0240-semantics-identifier.md @@ -4,6 +4,8 @@ - **Date:** 2026-10-17 - **Amended:** 2026-10-21 — §4: an identifier is unique among its siblings, as AccessKit's `author_id` requires; a clash is reported, not repaired. +- **Superseded-by:** [ADR-0407](ADR-0407-a-control-joins-the-semantics-annotation-above-it.md) + for an absorbed identifier (§1): it names the node that absorbs it, first wins. - **Related:** [ADR-0238](ADR-0238-flui-driver-protocol.md), [ADR-0203](ADR-0203-semantics-vocabulary.md), [ADR-0080](ADR-0080-agent-protocol-desktop-contract.md) (`automation_id`) @@ -23,7 +25,9 @@ its driver), Compose's `testTag`, Android `resource-id`, iOS `accessibilityIdent 1. `SemanticsConfiguration` gains an optional `identifier: Option>`. It is set by the widget author (`Semantics::identifier(..)` and an `identifier` builder on interactive widgets that already build semantics). It is never announced to assistive-technology users, never merged - into a parent's label, and does not by itself make a node a semantics boundary. + into a parent's label, and does not by itself make a node a semantics boundary. An identifier + absorbed with its configuration into another node names that node when the node has no + identifier of its own, first wins, as Flutter's `absorb` does (ADR-0407). 2. Translation exports it as AccessKit `author_id`, which the AccessKit adapters map to UIA `AutomationId`, macOS `AXIdentifier` and AT-SPI's accessible id. When Android, iOS and web adapters exist they map it to `viewIdResourceName`, `accessibilityIdentifier` and a @@ -63,7 +67,8 @@ its driver), Compose's `testTag`, Android `resource-id`, iOS `accessibilityIdent `cargo nextest run -p flui-semantics identifier`: - an identifier reaches the AccessKit node as `author_id`; -- it is absent from the label and from a merged parent; +- it is absent from the label, and a parent that absorbs it carries it unless the parent has its + own; - it does not create a boundary; - one on a node that publishes nothing else is reported beside a read (`an_identifier_on_a_node_that_publishes_nothing_else_is_reported`). diff --git a/docs/adr/ADR-0322-a-control-mounts-one-element-for-its-behaviours.md b/docs/adr/ADR-0322-a-control-mounts-one-element-for-its-behaviours.md index f83779d56c..e6344a4993 100644 --- a/docs/adr/ADR-0322-a-control-mounts-one-element-for-its-behaviours.md +++ b/docs/adr/ADR-0322-a-control-mounts-one-element-for-its-behaviours.md @@ -5,6 +5,9 @@ - **Superseded-by:** [ADR-0375](ADR-0375-before-the-first-release-a-pull-request-runs-a-fixed-gate-and-no-api-contract-gate.md) for the facade's public-API snapshot only (Confirmation): the module's absence from the facade is read in the code. +- **Superseded-by:** [ADR-0407](ADR-0407-a-control-joins-the-semantics-annotation-above-it.md) + for the node a control's description forms (§6, Accessibility): an annotation unless the + control's Flutter counterpart is a container. - **Related:** [ADR-0023](ADR-0023-actions-shortcuts-seam.md) (the action chain a focused node records, which the node keeps writing); [ADR-0079](ADR-0079-keyboard-activation-and-focus-for-assistive-technology.md) (keyboard @@ -319,7 +322,8 @@ their own elements, and their private inherited views, `FocusParentProvider` and - **Accessibility.** The node assembles one `SemanticsConfiguration` in a fixed order: the semantics properties; then the actions the enabled recognizers give (tap, long press, scroll) and the gesture alternatives; then `focusable`, `focused` and `on_focus` from the focus part. The - result is the node the container annotation produces today. + configuration forms the node the control's Flutter counterpart forms: an annotation that joins + the one above it, a container, or a merge (ADR-0407). - **Gestures.** The recognizers are the ones `GestureDetector` builds, mounted by the same factories against the same arena scope and settings, entered in the same order on a pointer down. A control inside a `Scrollable` and a control inside another control therefore contest as diff --git a/docs/adr/ADR-0407-a-control-joins-the-semantics-annotation-above-it.md b/docs/adr/ADR-0407-a-control-joins-the-semantics-annotation-above-it.md new file mode 100644 index 0000000000..f5e2f4f532 --- /dev/null +++ b/docs/adr/ADR-0407-a-control-joins-the-semantics-annotation-above-it.md @@ -0,0 +1,187 @@ +# ADR-0407: A control joins the semantics annotation above it + +- **Status:** Accepted (2026-11-30) +- **Date:** 2026-11-30 +- **Supersedes:** [ADR-0322](ADR-0322-a-control-mounts-one-element-for-its-behaviours.md), in part: + §6's rule that a control's node is the one a container annotation produces; + [ADR-0240](ADR-0240-semantics-identifier.md), in part: the rule that an absorbed configuration's + identifier is dropped (`flui-semantics` `ARCHITECTURE.md`, "The identifier names the node its + configuration forms or joins") +- **Related:** [ADR-0206](ADR-0206-typed-semantics-attributes.md) (when two configurations share a + node), [ADR-0332](ADR-0332-a-control-takes-the-content-roles-beneath-it.md) (the content roles a + control takes), [ADR-0322](ADR-0322-a-control-mounts-one-element-for-its-behaviours.md) §8 (a + control describes itself only while its window collects semantics) +- **Sources:** `flutter/flutter@3.50.1`, `packages/flutter/lib/src/`: + `widgets/toggleable.dart:398` (`Semantics(enabled:)` inside every toggle), + `material/switch.dart:1075` (`Semantics(toggled:)`), `material/checkbox.dart:615` + (`Semantics(label: semanticLabel, checked:, mixed:)`), `widgets/raw_radio.dart:224` + (`Semantics(inMutuallyExclusiveGroup:, checked:, selected:, hint:)`), + `cupertino/button.dart:572` (`Semantics(button: true)`), `material/ink_well.dart:1400` + (`Semantics(onTap:, onLongPress:)`), `material/list_tile.dart:995` (`Semantics(button:, selected:, + enabled:)`), and the containers `material/button_style_button.dart:591`, + `material/button.dart:433` (`RawMaterialButton`), `material/chip.dart:1503` (`RawChip`), + `material/chip.dart:2470` (the delete button's `_RenderEnsureMinSemanticsSize`); + `semantics/semantics.dart:6954` (`absorb` takes the child's identifier when its own is empty) + +## Context and problem statement + +In Flutter 3.50.1 an application names a switch by wrapping it: +`Semantics(label: 'Wi-Fi', child: Switch(...))`. Neither annotation is a container, so the +outer one forms the node (its parent asks for explicit children) and the switch's toggled state, +tap and focus join it: one node, a switch named "Wi-Fi". Only `Checkbox` has a `semanticLabel` +of its own, and it is the same `Semantics(label:)` written inside the control. + +FLUI's controls describe themselves through `InteractiveNode`'s `Description` (ADR-0322 §1), +which built every description as `Semantics::container(true)`. A container always forms its own +node, so the label around a switch formed a second node above it and the switch stayed nameless. +The end-of-test audit refuses a nameless control, so the testing platform's move of +`flui-material`'s tests (#3264) named `Switch` and `Radio` by adding `semantic_label` to each, +a builder Flutter does not have, and the next control would repeat it. The assembly already +follows Flutter's rule (a configuration that is no boundary is absorbed by the node above it, +and conflicting ones split, ADR-0206); the container flag is what kept a control out of it. + +A second rule stood in the way: `SemanticsConfiguration::absorb` dropped the identifier of what it +absorbed, so a switch that joined the label's node would lose `Switch::identifier`. + +Which node does a control's description form, and what does a node keep of what joins it? + +## Decision drivers + +- What an application writes is Flutter's: `Semantics::label` around a control names it where it + names it in Flutter, and no control grows a naming builder Flutter lacks. +- One rule for every control, held where the node is built, not a builder per widget. +- Nothing else a user observes moves: a button stays a node of its own, a chip and its delete + button stay apart, a disabled list tile does not make its list read as disabled. +- A control's cost does not rise: no element, render node or allocation, and `Description` stays + two words (its size assertion in `interaction/node.rs`); the idle frame allocates nothing. +- A locator that selected a control by its identifier still selects it. + +## Considered options + +1. A description is an annotation unless its Flutter counterpart is a container, and `absorb` + carries an identifier, first wins. +2. Keep every description a container and give each control a label builder (`semantic_label`, + or a `label` on `Description`). +3. Make every description an annotation, buttons and chips included. +4. Keep containers and let the assembly fold a label annotation into the container directly + beneath it. + +## Decision + +Chosen option: 1, because it is Flutter's rule applied once at the seam every control already +uses, and the only option under which an application's `Semantics` behaves as it does in Flutter. + +### §1 A description forms the node its Flutter counterpart forms + +```rust +// flui_widgets::__private::node +impl Description { + /// An annotation of `role`: it forms a node where its parent asks for explicit + /// children, and otherwise joins the annotation above it. + pub fn new(role: SemanticsRole) -> Self; + /// A node of its own wherever it is, as `Semantics::container(true)`. + pub fn container(self) -> Self; + /// A node of its own that folds every node beneath it, as `MergeSemantics`. + pub fn merges_descendants(self) -> Self; +} +``` + +The form is one private enum in the description (annotation, container, merge), so a merge is +always a container and nothing else can disagree with it. The catalogs choose by their Flutter +counterpart: + +| Control | Form | Flutter 3.50.1 | +|---|---|---| +| `Switch`, `Checkbox`, `Radio` | annotation | `material/switch.dart:1075`, `material/checkbox.dart:615`, `widgets/raw_radio.dart:224`, inside `widgets/toggleable.dart:398` | +| `CupertinoButton`, a cupertino tab item | annotation | `cupertino/button.dart:572`, `cupertino/bottom_tab_bar.dart:221` | +| A tappable carousel item | annotation | `InkWell`'s `Semantics(onTap:)`, `material/ink_well.dart:1400` | +| An enabled `ListTile` with a role | annotation | `material/list_tile.dart:995` | +| A disabled `ListTile` with a role | container | departs: Flutter folds `enabled: false` into the node above, which would read the enclosing list as disabled | +| `RawButton`, the `ButtonStyleButton` family, `FloatingActionButton` | container | `material/button_style_button.dart:591`, `material/button.dart:433` | +| `Chip`, `FilterChip`, a chip's delete button | container | `material/chip.dart:1503`, `material/chip.dart:2470` | +| A `TabBar` tab, a `NavigationBar` destination | merge | `MergeSemantics`, `material/tabs.dart:2108`, `material/navigation_bar.dart:303` | + +So `Semantics::new().label("Wi-Fi").child(Switch::new(on))` publishes one switch named "Wi-Fi", +and `Semantics::new().label("Send").child(ElevatedButton::new(Text::new("Go")))` a node "Send" +above a button "Go", as in Flutter. A control that names itself, as `Checkbox::semantic_label` +does, writes the same label inside the control. `Switch` and `Radio` take no label builder. + +Where two annotations cannot share a node (two roles, two handlers for one action, ADR-0206 +decision 4), they split as before: a switch inside a tappable `ListTile` is a node of its own. + +### §2 An absorbed identifier names the node that takes it, first wins + +`SemanticsConfiguration::absorb` keeps the receiver's identifier and takes the absorbed +configuration's when the receiver has none, as Flutter's `absorb` does +(`semantics/semantics.dart:6954`). A switch that joins its label's node keeps +`Switch::identifier` on that node, and a merged tab keeps its own over its children's. The rest +of ADR-0240 stands: an identifier is never text, never annotates a configuration and never makes a +boundary, so a configuration that carries only an identifier is absorbed by nobody and names no +node. + +### Flutter counterparts + +| Here | Flutter | Why it differs | +|---|---|---| +| `Description::new`, `container`, `merges_descendants` | `Semantics(container: false)`, `Semantics(container: true)`, `MergeSemantics` | the same three forms, chosen per control by its Flutter counterpart | +| A disabled `ListTile` is a container | `Semantics(enabled: false)` joins the node above | an enclosing list or row would read as disabled | +| An identifier alone annotates nothing | setting `identifier` sets `hasBeenAnnotated` | ADR-0240 §1: an id added for a test does not change the tree a screen reader reads | + +### Consequences + +- Good, because a control is named the way Flutter names it, and the testing platform names + `Switch` and `Radio` in its tests by `Semantics::label` with no builder of their own. +- Good, because the rule is the description's, so a control moved onto `InteractiveNode` later + states its form once and inherits the rest. +- Good, because nothing is added to a control's element, render node or view: the form replaces + a `bool` in `Description`, and the perf baselines of `flui-widgets`, `flui-material` and + `flui-cupertino` hold unchanged. +- Bad, because an annotation joins whatever annotation is above it: a toggle inside a + `Semantics` that is no container and holds other content folds into that node, as it does in + Flutter. An author who wants the toggle apart writes a container around it. +- Bad, because a node that absorbs two identified controls carries only the first identifier; + the second control's id selects nothing until it forms its own node. + +### Confirmation + +- `packages/flui-material/tests/named_by_semantics.rs`, + `a_label_around_a_toggle_names_the_toggles_own_node`: a `Semantics` label around a `Switch`, a + `Checkbox` and a `Radio` each carrying an identifier finds exactly one node by the label, of the + control's role, with the control's identifier, and its tap reaches the control; it fails with + the description a container and with `absorb` dropping the identifier. + `a_label_around_a_container_control_is_a_node_above_it`: an `ElevatedButton` keeps its own node + and name beneath the label. +- `flui-semantics`'s `the_identifier_is_exported_unannounced_no_boundary_and_joins_first_wins` + and `flui-rendering`'s `an_identifier_names_the_node_its_configuration_forms_or_joins`: the + identifier through `absorb` and through assembly, a bare identifier absorbed by nobody. +- `raw_button_a11y_tree_matches_wrappers` and `ink_well_a11y_tree_matches_wrappers` (ADR-0322) + still hold for the containers. +- `const _: () = assert!(size_of::() <= 16)` in `interaction/node.rs`, and the + `perf` targets of the three crates under `FLUI_PERF_BASELINE=check`. + +## Pros and cons of the options + +### 1. Annotation unless the counterpart is a container, identifier first wins + +- Good, because an application's `Semantics` means what it means in Flutter. +- Good, because the choice is one line per control, read against its Flutter counterpart. +- Bad, because the trees of the toggles under a non-container annotation change shape, as they + would have in Flutter. + +### 2. Containers and a label builder per control + +- Good, because no tree changes shape. +- Bad, because every control grows a builder Flutter does not have, and `Semantics::label` + around a control still leaves it nameless: the duplication this record removes. + +### 3. Every description an annotation + +- Good, because there is no per-control choice. +- Bad, because a label around a button would rename it and a chip would fold into the row that + holds it, where Flutter keeps both apart. + +### 4. Fold a label into the container beneath it + +- Good, because no description changes. +- Bad, because the assembly gains a rule Flutter does not have, and a container would no longer + mean a node of its own. diff --git a/packages/flui-material/src/button_style_button.rs b/packages/flui-material/src/button_style_button.rs index 23b8854287..3544c213fc 100644 --- a/packages/flui-material/src/button_style_button.rs +++ b/packages/flui-material/src/button_style_button.rs @@ -361,10 +361,9 @@ impl ViewState for ButtonStyleButtonCoreState { // semantics node, with the role, the identifier and the toggle state // of this description, `enabled` from the node's switch, and the tap // and focus the node adds (ADR-0322 §1). - let mut description = - Description::new(SemanticsRole::Button) - .container() - .identifier(view.identifier.clone()); + let mut description = Description::new(SemanticsRole::Button) + .container() + .identifier(view.identifier.clone()); if let Some(selected) = view.selected { description = description.toggled(Toggled::from_bool(selected)); } diff --git a/packages/flui-material/tests/named_by_semantics.rs b/packages/flui-material/tests/named_by_semantics.rs index dd4701b30e..d4238d4ee7 100644 --- a/packages/flui-material/tests/named_by_semantics.rs +++ b/packages/flui-material/tests/named_by_semantics.rs @@ -77,7 +77,11 @@ pub fn a_label_around_a_toggle_names_the_toggles_own_node() { // Strict: a label that formed a node beside the control would match twice // or name a node of another role. let named = t.read(&find::text(LABEL)); - assert_eq!(named.role, row.role, "{}: the label names the control", row.control); + assert_eq!( + named.role, row.role, + "{}: the label names the control", + row.control + ); assert_eq!( named.identifier.as_deref(), Some(IDENTIFIER), @@ -98,7 +102,12 @@ pub fn a_label_around_a_toggle_names_the_toggles_own_node() { ); t.tap(&find::text(LABEL)); - assert_eq!(taps.get(), 1, "{}: the named node's tap is the control's", row.control); + assert_eq!( + taps.get(), + 1, + "{}: the named node's tap is the control's", + row.control + ); t.finish(); } } From 5371fba495bd8f60bf7f4c3f156ee0acde9113bd Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 19:09:20 +0000 Subject: [PATCH 05/10] semantics, widgets: two identifiers are two nodes; a description's form is its constructor; the records state the joined identifier Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EqfW4FAhVS5dwwxVx5vRGK --- ...ude-project-thread-0t1td0-content-roles.md | 7 +- changelog.d/semantics-identifier.md | 7 +- crates/flui-objects/src/proxy/semantics.rs | 3 +- crates/flui-semantics/ARCHITECTURE.md | 6 +- crates/flui-semantics/src/configuration.rs | 28 ++- crates/flui-semantics/tests/identifier.rs | 12 + crates/flui-widgets/src/interaction/node.rs | 50 ++-- .../src/interaction/raw_button.rs | 3 +- .../flui-widgets/src/semantics/annotation.rs | 10 +- crates/flui-widgets/src/semantics/merge.rs | 5 +- ...trol-takes-the-content-roles-beneath-it.md | 7 +- docs/plans/specs/flui-driver/tasks.md | 10 +- .../flui-material/src/button_style_button.rs | 5 +- packages/flui-material/src/chip.rs | 11 +- .../src/floating_action_button.rs | 2 +- packages/flui-material/src/list_tile.rs | 9 +- packages/flui-material/src/navigation_bar.rs | 9 +- packages/flui-material/src/tabs.rs | 5 +- packages/flui-material/tests/main.rs | 8 +- .../flui-material/tests/named_by_semantics.rs | 216 +++++++++++++----- packages/flui-material/tests/tabs.rs | 2 +- 21 files changed, 278 insertions(+), 137 deletions(-) diff --git a/changelog.d/claude-project-thread-0t1td0-content-roles.md b/changelog.d/claude-project-thread-0t1td0-content-roles.md index dee8442901..13a7dd507f 100644 --- a/changelog.d/claude-project-thread-0t1td0-content-roles.md +++ b/changelog.d/claude-project-thread-0t1td0-content-roles.md @@ -5,9 +5,10 @@ that carries only a name (image, heading, text-level roles), keeps its own role and gains their names (ADR-0332). A button over a labelled image is announced "Add, button" and found by that name, where it was a nameless button with an image beneath it. A meter or a progress - bar inside a control stays a node. Content that must stay a stop of its own, or be found by - its `identifier`, is wrapped in `Semantics::container(true)`: an identifier on absorbed - content is not published. + bar inside a control stays a node. Content that must stay a stop of its own is wrapped in + `Semantics::container(true)`; an identifier on absorbed content names the control's node when + the control has none, and content named otherwise than its control stays a node of its own + (ADR-0407). ### Removed diff --git a/changelog.d/semantics-identifier.md b/changelog.d/semantics-identifier.md index a7f24a20c3..7ae3476234 100644 --- a/changelog.d/semantics-identifier.md +++ b/changelog.d/semantics-identifier.md @@ -4,9 +4,10 @@ `flui-cupertino`, ADR-0240): `SemanticsConfiguration::set_identifier`/`identifier` give a node a stable id for tests and automation. It is published as AccessKit `author_id` (UI Automation's `AutomationId`, macOS `AXIdentifier`, AT-SPI's accessible id) and as the wire `Node.identifier` - of an agent read, and it is never announced. It names only the node its own configuration - forms: it makes no boundary and annotates nothing, and a parent or `MergeSemantics` that absorbs - the configuration does not take it. + of an agent read, and it is never announced. It makes no boundary and annotates nothing; absorbed + into a parent or merged by `MergeSemantics`, it names that node when the node has none of its + own, and outside a merge a configuration named otherwise than the node above it forms a node of + its own (ADR-0407). - `Semantics::identifier`, `MergeSemantics::identifier` (with `RenderMergeSemantics::set_identifier`) and an `identifier` builder on `RawButton`, `Disclosure`, `EditableText` and `RawTextField`; in `flui-material` on `ElevatedButton`, `FilledButton`, `OutlinedButton`, diff --git a/crates/flui-objects/src/proxy/semantics.rs b/crates/flui-objects/src/proxy/semantics.rs index 1bcc7666c8..03ddf9ea26 100644 --- a/crates/flui-objects/src/proxy/semantics.rs +++ b/crates/flui-objects/src/proxy/semantics.rs @@ -612,7 +612,8 @@ impl RenderMergeSemantics { /// Names the merged node for tests and automation (ADR-0240). The merge is /// the boundary that forms the node, so the identifier of a control /// assembled from merged parts belongs here: a descendant's own identifier - /// is not carried into the merged node. + /// names the merged node only when this is unset, the first one merged + /// winning (ADR-0407). pub fn set_identifier( &mut self, identifier: Option>, diff --git a/crates/flui-semantics/ARCHITECTURE.md b/crates/flui-semantics/ARCHITECTURE.md index 68ed0aaf78..5e920c8c64 100644 --- a/crates/flui-semantics/ARCHITECTURE.md +++ b/crates/flui-semantics/ARCHITECTURE.md @@ -862,7 +862,11 @@ configuration absorbed into an ancestor or a `MergeSemantics` names that node wh identifier of its own, and the receiver keeps its own when it has one. So a control that joins the `Semantics` above it keeps its identifier on the node it joined, as Flutter's `SemanticsConfiguration.absorb` does (flutter/flutter@3.50.1 -`packages/flutter/lib/src/semantics/semantics.dart:6954`). A node AccessKit's filter lifts into its +`packages/flutter/lib/src/semantics/semantics.dart:6954`). A node publishes one identifier, so +outside a merge two different ones are two nodes: `can_absorb` and `can_join` refuse a +configuration whose identifier differs from the node's or a sibling's, and it forms a node of its +own that keeps its id (Flutter keeps the first and drops the other). A `MergeSemantics` takes +everything, its own identifier or the first merged one. A node AccessKit's filter lifts into its parent (no role, label or text, or the `Generic` or `Presentation` role) takes its identifier with it, so no agent or OS automation locator selects it (the web mirror still writes `data-flui-id`). `read_wire` lists a `TreeDiagnostic::UnpublishedIdentifier` for each identifier and node it is diff --git a/crates/flui-semantics/src/configuration.rs b/crates/flui-semantics/src/configuration.rs index 974448dbba..9ec4db373d 100644 --- a/crates/flui-semantics/src/configuration.rs +++ b/crates/flui-semantics/src/configuration.rs @@ -1606,7 +1606,8 @@ impl SemanticsConfiguration { /// one named button, not a nameless button with an image beneath it. #[must_use] pub fn can_absorb(&self, descendant: &SemanticsConfiguration, names_a_control: bool) -> bool { - self.shares_a_node_with(descendant, names_a_control && descendant.has_naming_role()) + !self.names_another_node(descendant) + && self.shares_a_node_with(descendant, names_a_control && descendant.has_naming_role()) } /// Returns whether this configuration and `sibling`, both absorbed by @@ -1620,7 +1621,21 @@ impl SemanticsConfiguration { #[must_use] pub fn can_join(&self, sibling: &SemanticsConfiguration, names_a_control: bool) -> bool { let folds = names_a_control && self.has_naming_role() && sibling.has_naming_role(); - self.shares_a_node_with(sibling, folds) + !self.names_another_node(sibling) && self.shares_a_node_with(sibling, folds) + } + + /// Whether this configuration and `other` name different nodes: both carry + /// an identifier and the two differ. A node publishes one identifier, so a + /// control that would join a node named otherwise forms its own and keeps + /// the id its author gave it (ADR-0407 §2). It is read whether or not + /// either is annotated, since an identifier annotates nothing and a + /// container that only names itself still refuses a control named + /// otherwise. + fn names_another_node(&self, other: &SemanticsConfiguration) -> bool { + matches!( + (self.identifier(), other.identifier()), + (Some(mine), Some(theirs)) if mine != theirs + ) } /// Returns whether this configuration, absorbed by the configuration @@ -1633,6 +1648,7 @@ impl SemanticsConfiguration { /// not share, so a check box beside an icon does not keep the icon from /// naming the button around both. Every other row is compared: a sibling /// that repeats the node's action or state still forms its own node. + /// Identifiers are not compared: the two are in different nodes already. #[must_use] pub fn can_stay_beside(&self, node: &SemanticsConfiguration, names_a_control: bool) -> bool { self.shares_a_node_with(node, names_a_control && self.has_naming_role()) @@ -1667,7 +1683,8 @@ impl SemanticsConfiguration { label: _, value, hint: _, - // First wins on absorb, so two never compete. + // Compared by `names_another_node`, which `can_absorb` and + // `can_join` read and `can_stay_beside` does not. identifier: _, text_direction: _, text, @@ -1757,7 +1774,10 @@ impl SemanticsConfiguration { /// - **Assistive-focus handlers** — the contributor's follow the receiver's. /// - **Anchors, relations** — union. /// - **Label / hint** — joined with a space. - /// - **Identifier** — never absorbed: the receiver keeps its own (ADR-0240). + /// - **Identifier** — first wins: the receiver keeps its own and takes the + /// contributor's when it has none (ADR-0407 §2). Two different ones never + /// reach one fold of an ordinary merge, since `can_absorb` and `can_join` + /// refuse them; a forced merge keeps the first. /// - **Everything else** — first wins: the receiver keeps what it has. /// /// `blocks_user_actions` on the *parent* is unchanged by absorb — diff --git a/crates/flui-semantics/tests/identifier.rs b/crates/flui-semantics/tests/identifier.rs index a9844a7fbf..30d5eed40d 100644 --- a/crates/flui-semantics/tests/identifier.rs +++ b/crates/flui-semantics/tests/identifier.rs @@ -158,6 +158,18 @@ fn the_identifier_is_exported_unannounced_no_boundary_and_joins_first_wins() { parent.identifier() == Some(IDENTIFIER) }, }, + Claim { + claim: "two identifiers are two nodes: a parent named otherwise refuses the node, \ + even a parent that names itself and says nothing else", + holds: || { + let mut bare_parent = SemanticsConfiguration::new(); + bare_parent.set_identifier("row-7"); + named("Row 7", "row-7").can_absorb(&named("Delete", "row-7"), false) + && !named("Row 7", "row-7").can_absorb(&named("Delete", IDENTIFIER), false) + && !bare_parent.can_absorb(&named("Delete", IDENTIFIER), false) + && !named("Edit", "edit").can_join(&named("Delete", IDENTIFIER), false) + }, + }, Claim { claim: "joins first wins: a parent keeps its own identifier", holds: || { diff --git a/crates/flui-widgets/src/interaction/node.rs b/crates/flui-widgets/src/interaction/node.rs index 433e252193..5fc5608670 100644 --- a/crates/flui-widgets/src/interaction/node.rs +++ b/crates/flui-widgets/src/interaction/node.rs @@ -130,28 +130,40 @@ struct Names { } impl Description { - /// An annotation of `role`, which says nothing more. + /// An annotation of `role`, which says nothing more: it forms a node where + /// its parent asks for explicit children and otherwise joins the + /// annotation above it, as `Semantics` with `container` off does. #[must_use] pub fn new(role: SemanticsRole) -> Self { - Self { - role, - toggled: None, - selected: None, - form: NodeForm::Annotation, - names: None, - } + Self::of(role, NodeForm::Annotation) } - /// Form a node of its own wherever the control is, as - /// `Semantics::container(true)` does: a control whose Flutter counterpart + /// A node of `role` of its own wherever the control is, as + /// `Semantics::container(true)` is: a control whose Flutter counterpart /// is a container (`ButtonStyleButton`, `RawMaterialButton`, `RawChip`). /// A label around such a control is a node of its own above it. #[must_use] - pub fn container(mut self) -> Self { - if self.form == NodeForm::Annotation { - self.form = NodeForm::Container; + pub fn container(role: SemanticsRole) -> Self { + Self::of(role, NodeForm::Container) + } + + /// A node of `role` of its own that folds every node beneath it into + /// itself, as a [`MergeSemantics`](crate::MergeSemantics) around the + /// control does: a tab or a destination is one node with its icon's and + /// label's text. + #[must_use] + pub fn merging(role: SemanticsRole) -> Self { + Self::of(role, NodeForm::Merge) + } + + fn of(role: SemanticsRole, form: NodeForm) -> Self { + Self { + role, + toggled: None, + selected: None, + form, + names: None, } - self } /// The names to write, allocated on the first one a control sets. @@ -191,16 +203,6 @@ impl Description { self } - /// Fold every node beneath the control into its own, as a - /// [`MergeSemantics`](crate::MergeSemantics) around it does: a tab or a - /// destination is one node with its icon's and label's text. A merge is - /// a node of its own, as `MergeSemantics` is. - #[must_use] - pub fn merges_descendants(mut self) -> Self { - self.form = NodeForm::Merge; - self - } - fn build(&self) -> Semantics { let names = self.names.as_deref(); let mut semantics = Semantics::new() diff --git a/crates/flui-widgets/src/interaction/raw_button.rs b/crates/flui-widgets/src/interaction/raw_button.rs index 37d972d501..723c1b9d89 100644 --- a/crates/flui-widgets/src/interaction/raw_button.rs +++ b/crates/flui-widgets/src/interaction/raw_button.rs @@ -173,8 +173,7 @@ impl StatelessView for RawButton { let enabled = self.on_pressed.is_some(); let press = Rc::new(Press(self.on_pressed.clone())); // One node for assistive technology: the button. - let description = Description::new(flui_semantics::SemanticsRole::Button) - .container() + let description = Description::container(flui_semantics::SemanticsRole::Button) .identifier(self.identifier.clone()); // The bindings are the node's own, so its focus node records them // and the root bindings resolve the activation here (ADR-0079). diff --git a/crates/flui-widgets/src/semantics/annotation.rs b/crates/flui-widgets/src/semantics/annotation.rs index 260c092629..c0407b3df0 100644 --- a/crates/flui-widgets/src/semantics/annotation.rs +++ b/crates/flui-widgets/src/semantics/annotation.rs @@ -174,10 +174,12 @@ impl Semantics { /// Set the stable identifier tests and automation select this node by /// (ADR-0240), exported as UI Automation's `AutomationId`, macOS /// `AXIdentifier` and AT-SPI's accessible id. It is never announced, and - /// it does not make a node: it names this widget's node only when the - /// widget forms one ([`container`](Self::container), or under a parent - /// that requires explicit child nodes). Absorbed into an ancestor or - /// merged by `MergeSemantics`, it is dropped, not carried up. A node with + /// it does not make a node: it names the node this widget forms + /// ([`container`](Self::container), or under a parent that requires + /// explicit child nodes) or joins. Absorbed into an ancestor or merged by + /// `MergeSemantics`, it names that node when the node has none of its own; + /// outside a merge, an ancestor named otherwise leaves this widget a node + /// of its own (ADR-0407). A node with /// no role, label or text, or with the `Generic` or `Presentation` role, /// is lifted into its parent by the agent and the AccessKit adapters, its /// identifier with it: to select a widget with no semantics of its own, diff --git a/crates/flui-widgets/src/semantics/merge.rs b/crates/flui-widgets/src/semantics/merge.rs index 1c7e5b558b..f6e04f6166 100644 --- a/crates/flui-widgets/src/semantics/merge.rs +++ b/crates/flui-widgets/src/semantics/merge.rs @@ -50,8 +50,9 @@ impl MergeSemantics { /// Set the merged node's stable identifier for tests and automation /// (ADR-0240). The merge forms the node, so this, not a descendant's - /// [`Semantics::identifier`], names it: a descendant's identifier is - /// dropped by the merge. A merged node that publishes nothing (no role, + /// [`Semantics::identifier`], names it: a descendant's identifier names + /// the merged node only when this is unset, the first one merged winning + /// (ADR-0407). A merged node that publishes nothing (no role, /// label or text) is lifted into its parent with its identifier, as /// [`Semantics::identifier`] describes. #[must_use] diff --git a/docs/adr/ADR-0332-a-control-takes-the-content-roles-beneath-it.md b/docs/adr/ADR-0332-a-control-takes-the-content-roles-beneath-it.md index 27d46b23d7..8c1635c249 100644 --- a/docs/adr/ADR-0332-a-control-takes-the-content-roles-beneath-it.md +++ b/docs/adr/ADR-0332-a-control-takes-the-content-roles-beneath-it.md @@ -128,9 +128,10 @@ symmetric predicate (`is_compatible_with`) is removed. The absorbed configuration merges by the table of ADR-0206 decision 4. The role is settled by its precedence, in which a control outranks content, so the node keeps the control's role. The content's label and hint concatenate onto the control's in traversal order, which is what -names the control. An identifier never crosses into another node (ADR-0240), so the -identifier of absorbed content is not published; content a test must find by identifier forms -its own node with `Semantics::container(true)`. +names the control. The identifier of absorbed content names the control's node when the control +has none, and content named otherwise than its control is refused and forms a node of its own +(ADR-0407 §2); content that must stay a stop of its own forms one with +`Semantics::container(true)`. ## Consequences diff --git a/docs/plans/specs/flui-driver/tasks.md b/docs/plans/specs/flui-driver/tasks.md index ac18998726..4d54a1d604 100644 --- a/docs/plans/specs/flui-driver/tasks.md +++ b/docs/plans/specs/flui-driver/tasks.md @@ -172,15 +172,15 @@ graph LR builder on the interactive widgets that build semantics; `flui-material` and `flui-cupertino` widgets forward it. - **Done when:** - - a table test covers export, not-announced, not-merged and no-boundary; + - a table test covers export, not-announced, absorbed first wins and no-boundary; - on W, UIA reads the value as `AutomationId` (a row added to the existing `windows-a11y` check until FD11 replaces it). - **Evidence (2026-10-20):** - The identifier is an `Option>` attribute. Setting it marks nothing annotated and makes - no boundary, and `absorb` never takes it, so it names only the node its own configuration - forms; an identifier alone contributes nothing, and a merged parent keeps its own - (`flui-semantics` ARCHITECTURE.md, "The identifier names only the node its own configuration - forms"). Translation sets AccessKit `author_id`; the agent read fills `Node.identifier` from it + no boundary, and `absorb` takes it first wins, so it names the node its configuration forms + or joins; an identifier alone contributes nothing, a merged parent keeps its own, and a node + named otherwise refuses it (`flui-semantics` ARCHITECTURE.md, "The identifier names the node + its configuration forms or joins", ADR-0407). Translation sets AccessKit `author_id`; the agent read fills `Node.identifier` from it and leaves `automation_id` to OS backends. - Widgets name the node where it forms: `Semantics::identifier` (on a container), `MergeSemantics::identifier` (new `RenderMergeSemantics::set_identifier`), `RawButton`, diff --git a/packages/flui-material/src/button_style_button.rs b/packages/flui-material/src/button_style_button.rs index 3544c213fc..937fbb1e3a 100644 --- a/packages/flui-material/src/button_style_button.rs +++ b/packages/flui-material/src/button_style_button.rs @@ -361,9 +361,8 @@ impl ViewState for ButtonStyleButtonCoreState { // semantics node, with the role, the identifier and the toggle state // of this description, `enabled` from the node's switch, and the tap // and focus the node adds (ADR-0322 §1). - let mut description = Description::new(SemanticsRole::Button) - .container() - .identifier(view.identifier.clone()); + let mut description = + Description::container(SemanticsRole::Button).identifier(view.identifier.clone()); if let Some(selected) = view.selected { description = description.toggled(Toggled::from_bool(selected)); } diff --git a/packages/flui-material/src/chip.rs b/packages/flui-material/src/chip.rs index 0c5f2f5d0d..1a04376be4 100644 --- a/packages/flui-material/src/chip.rs +++ b/packages/flui-material/src/chip.rs @@ -574,11 +574,7 @@ impl StatelessView for Chip { .child(padded_content) .shape(shape) .enabled(self.enabled) - .description( - Description::new(role) - .container() - .identifier(self.identifier.clone()), - ); + .description(Description::container(role).identifier(self.identifier.clone())); if let Some(on_pressed) = self.on_pressed.clone() { ink_well = ink_well.on_tap(move |ctx| on_pressed(ctx)); } @@ -857,8 +853,7 @@ impl StatelessView for FilterChip { .child(padded_content) .shape(shape) .description( - Description::new(SemanticsRole::Button) - .container() + Description::container(SemanticsRole::Button) .identifier(self.identifier.clone()) .toggled(Toggled::from_bool(selected)), ); @@ -904,7 +899,7 @@ fn delete_button( )) .shape(MaterialShape::Stadium) .enabled(enabled) - .description(Description::new(SemanticsRole::Button).container()); + .description(Description::container(SemanticsRole::Button)); if enabled { button = button.on_tap(move |ctx| on_deleted(ctx)); } diff --git a/packages/flui-material/src/floating_action_button.rs b/packages/flui-material/src/floating_action_button.rs index 2466fce7c0..0fa50f0c97 100644 --- a/packages/flui-material/src/floating_action_button.rs +++ b/packages/flui-material/src/floating_action_button.rs @@ -371,7 +371,7 @@ impl ViewState for FloatingActionButtonState { // button: true)` (flutter/flutter@3.50.1 // `packages/flutter/lib/src/material/button.dart:433`); the // well's switch says whether it is enabled. - .description(Description::new(SemanticsRole::Button).container()); + .description(Description::container(SemanticsRole::Button)); if let Some(on_pressed) = view.on_pressed.clone() { ink_well = ink_well.on_tap(move |ctx| on_pressed(ctx)); } diff --git a/packages/flui-material/src/list_tile.rs b/packages/flui-material/src/list_tile.rs index 9f8d7354f6..64fde4395e 100644 --- a/packages/flui-material/src/list_tile.rs +++ b/packages/flui-material/src/list_tile.rs @@ -812,13 +812,14 @@ impl StatelessView for ListTile { .shape(resolved.shape) .enabled(self.enabled); if let Some(role) = role { - let mut description = Description::new(role); + let mut description = if self.enabled { + Description::new(role) + } else { + Description::container(role) + }; if self.selectable { description = description.selected(self.selected); } - if !self.enabled { - description = description.container(); - } ink_well = ink_well.description(description); } if let Some(on_tap) = self.on_tap.clone() { diff --git a/packages/flui-material/src/navigation_bar.rs b/packages/flui-material/src/navigation_bar.rs index b2f029cdf5..2ec5dba396 100644 --- a/packages/flui-material/src/navigation_bar.rs +++ b/packages/flui-material/src/navigation_bar.rs @@ -243,7 +243,7 @@ impl std::fmt::Debug for NavigationDestination { /// Each destination is one node, its `InkWell`'s: the well's description /// carries the role and the selected state, the well's own parts the /// enabled state and the click, and the description folds the icon and -/// label beneath it into that node (`Description::merges_descendants`), as +/// label beneath it into that node (`Description::merging`), as /// Flutter's `MergeSemantics` around the destination does. /// /// **Named deferral**: the extra "Tab N of M" accessibility label @@ -585,11 +585,8 @@ fn build_destination( // `Semantics(selected:, enabled:)` around the destination's `InkWell` are // the well's own node here (ADR-0322 §1). Its switch is `enabled`, as the // well is interactive exactly when the destination is. - let ink_well = ink_well.description( - Description::new(SemanticsRole::Tab) - .selected(selected) - .merges_descendants(), - ); + let ink_well = + ink_well.description(Description::merging(SemanticsRole::Tab).selected(selected)); Expanded::new(ink_well) } diff --git a/packages/flui-material/src/tabs.rs b/packages/flui-material/src/tabs.rs index bf90d60259..5f312426ed 100644 --- a/packages/flui-material/src/tabs.rs +++ b/packages/flui-material/src/tabs.rs @@ -881,10 +881,9 @@ fn build_tab_cell( // `MergeSemantics` and `Semantics(selected:)` around the tab's `InkWell` // are the well's own node here (ADR-0322 §1). let ink_well = ink_well.description( - Description::new(SemanticsRole::Tab) + Description::merging(SemanticsRole::Tab) .selected(selected) - .anchor(anchor.clone()) - .merges_descendants(), + .anchor(anchor.clone()), ); Expanded::new(ink_well).boxed() } diff --git a/packages/flui-material/tests/main.rs b/packages/flui-material/tests/main.rs index fb103349ff..0cbe2fe2cc 100644 --- a/packages/flui-material/tests/main.rs +++ b/packages/flui-material/tests/main.rs @@ -511,8 +511,12 @@ fn selection_control_contracts() { checkbox::toggles_and_chips_are_one_node_with_their_state, ), ( - "named_by_semantics::a label around a toggle names the toggles own node", - named_by_semantics::a_label_around_a_toggle_names_the_toggles_own_node, + "named_by_semantics::a label around a toggle or a tile names the controls own node", + named_by_semantics::a_label_around_a_toggle_or_a_tile_names_the_controls_own_node, + ), + ( + "named_by_semantics::a toggle keeps its identifier whatever names the node above it", + named_by_semantics::a_toggle_keeps_its_identifier_whatever_names_the_node_above_it, ), ( "named_by_semantics::a label around a container control is a node above it", diff --git a/packages/flui-material/tests/named_by_semantics.rs b/packages/flui-material/tests/named_by_semantics.rs index d4238d4ee7..56db5f1ca2 100644 --- a/packages/flui-material/tests/named_by_semantics.rs +++ b/packages/flui-material/tests/named_by_semantics.rs @@ -1,15 +1,15 @@ //! A `Semantics` label around a control names the control's own node, as in Flutter 3.50.1, where -//! a toggle's `Semantics` is no container and joins the annotation above it (ADR-0407). A control -//! whose Flutter counterpart is a container keeps a node of its own beneath the label. -//! -//! Each row mounts `Semantics::new().label(LABEL)` around a control that carries its own -//! identifier, then finds the node by that label alone: one node, of the control's role, with the -//! control's identifier, whose tap reaches the control's handler. +//! a toggle's or a list tile's `Semantics` is no container and joins the annotation above it +//! (ADR-0407). A control whose Flutter counterpart is a container keeps a node of its own beneath +//! the label. A control keeps the identifier its author gave it either way. use std::cell::Cell; use std::rc::Rc; -use flui_material::{Checkbox, ElevatedButton, Radio, Switch, Theme, ThemeData}; +use flui_material::{ + Checkbox, ElevatedButton, FilterChip, FloatingActionButton, ListTile, Radio, Switch, Theme, + ThemeData, +}; use flui_protocol::wire::Role; use flui_sdk::view::{BoxedView, ViewExt}; use flui_sdk::widgets::{Semantics, Text}; @@ -18,29 +18,32 @@ use flui_testing::scenario::{TestWindow, Tester, WindowSpec, find}; const LABEL: &str = "Wi-Fi"; const IDENTIFIER: &str = "wifi"; -/// One control, built to count its taps. -struct Row { - control: &'static str, - role: Role, - build: fn(Rc>) -> BoxedView, +fn labelled(label: Semantics, control: BoxedView) -> Theme { + Theme::new(ThemeData::light(), label.child(control)) } -fn labelled(control: BoxedView) -> Theme { - Theme::new( - ThemeData::light(), - Semantics::new().label(LABEL).child(control), - ) +fn window() -> TestWindow { + TestWindow::new(WindowSpec::new(200, 60)) } -fn window() -> TestWindow { - TestWindow::new(WindowSpec::new(120, 60)) +/// A control that joins the label around it, built to count its taps. +struct Joins { + control: &'static str, + role: Role, + /// Whether the control has a handler: a disabled one is found, not tapped. + enabled: bool, + build: fn(Rc>) -> BoxedView, } -pub fn a_label_around_a_toggle_names_the_toggles_own_node() { +/// Each row finds the node by the label alone: one node, of the control's role, with the +/// identifier, whose tap reaches the control's handler. A disabled toggle joins too, as in +/// Flutter, and the label's node reads as that disabled toggle. +pub fn a_label_around_a_toggle_or_a_tile_names_the_controls_own_node() { let rows = [ - Row { + Joins { control: "Switch", role: Role::Switch, + enabled: true, build: |taps| { Switch::new(false) .identifier(IDENTIFIER) @@ -48,9 +51,16 @@ pub fn a_label_around_a_toggle_names_the_toggles_own_node() { .boxed() }, }, - Row { + Joins { + control: "a disabled Switch", + role: Role::Switch, + enabled: false, + build: |_| Switch::new(false).identifier(IDENTIFIER).boxed(), + }, + Joins { control: "Checkbox", role: Role::CheckBox, + enabled: true, build: |taps| { Checkbox::new(false) .identifier(IDENTIFIER) @@ -58,9 +68,10 @@ pub fn a_label_around_a_toggle_names_the_toggles_own_node() { .boxed() }, }, - Row { + Joins { control: "Radio", role: Role::RadioButton, + enabled: true, build: |taps| { Radio::new("summer", Some("spring")) .identifier(IDENTIFIER) @@ -68,30 +79,43 @@ pub fn a_label_around_a_toggle_names_the_toggles_own_node() { .boxed() }, }, + // Flutter 3.50.1 `packages/flutter/lib/src/material/list_tile.dart:995`. The tile has no + // identifier builder, so the label's own identifier names the joined node. + Joins { + control: "an enabled ListTile", + role: Role::Button, + enabled: true, + build: |taps| { + ListTile::new() + .title(Text::new("Network")) + .on_tap(move |_ctx| taps.set(taps.get() + 1)) + .boxed() + }, + }, ]; for row in rows { let taps = Rc::new(Cell::new(0_u32)); - let mut t = Tester::mount_in(labelled((row.build)(Rc::clone(&taps))), window()); + let label = Semantics::new().label(LABEL).identifier(IDENTIFIER); + let mut t = Tester::mount_in(labelled(label, (row.build)(Rc::clone(&taps))), window()); // Strict: a label that formed a node beside the control would match twice // or name a node of another role. - let named = t.read(&find::text(LABEL)); + let named = t.read(&find::text_containing(LABEL)); assert_eq!( named.role, row.role, "{}: the label names the control", row.control ); assert_eq!( - named.identifier.as_deref(), - Some(IDENTIFIER), - "{}: the node keeps the control's identifier", + named.disabled, !row.enabled, + "{}: enabled as the control is", row.control ); assert_eq!( - t.read(&find::id(IDENTIFIER)).id, - named.id, - "{}: the identifier and the label find one node", + named.identifier.as_deref(), + Some(IDENTIFIER), + "{}: the node carries the identifier", row.control ); assert_eq!( @@ -100,36 +124,114 @@ pub fn a_label_around_a_toggle_names_the_toggles_own_node() { "{}: the control has no second node", row.control ); - - t.tap(&find::text(LABEL)); - assert_eq!( - taps.get(), - 1, - "{}: the named node's tap is the control's", - row.control - ); + if row.enabled { + t.tap(&find::text_containing(LABEL)); + assert_eq!( + taps.get(), + 1, + "{}: the named node's tap is the control's", + row.control + ); + } t.finish(); } } -/// `ButtonStyleButton` is `Semantics(container: true, button: …)` in Flutter 3.50.1 -/// (`packages/flutter/lib/src/material/button_style_button.dart:591`): a label around it is a -/// node of its own, and the button keeps the name its child gives it. -pub fn a_label_around_a_container_control_is_a_node_above_it() { - let mut t = Tester::mount_in( - labelled( - ElevatedButton::new(Text::new("Send")) - .identifier(IDENTIFIER) - .on_pressed(|_ctx| {}) - .boxed(), - ), - window(), - ); +/// A control named by its identifier keeps it when it joins the label's node, which has none of +/// its own; under a node named otherwise it forms its own node and keeps its id (ADR-0407 §2). +pub fn a_toggle_keeps_its_identifier_whatever_names_the_node_above_it() { + let toggle = || { + Switch::new(false) + .identifier(IDENTIFIER) + .on_changed(|_ctx, _| {}) + .boxed() + }; - let button = t.read(&find::button("Send")); - assert_eq!(button.identifier.as_deref(), Some(IDENTIFIER)); - let label = t.read(&find::text(LABEL)); - assert_ne!(label.id, button.id, "the label is a node above the button"); - assert_ne!(label.role, Role::Button); + let mut t = Tester::mount_in(labelled(Semantics::new().label(LABEL), toggle()), window()); + let joined = t.read(&find::id(IDENTIFIER)); + assert_eq!(joined.role, Role::Switch); + assert_eq!( + joined.name.as_deref(), + Some(LABEL), + "the toggle joined the label's node" + ); t.finish(); + + let row = Semantics::new().label(LABEL).identifier("settings-row"); + let mut t = Tester::mount_in(labelled(row, toggle()), window()); + let switch = t.read(&find::id(IDENTIFIER)); + assert_eq!(switch.role, Role::Switch, "the toggle formed its own node"); + let row = t.read(&find::id("settings-row")); + assert_ne!(row.id, switch.id, "two identifiers are two nodes"); + assert_eq!(row.name.as_deref(), Some(LABEL)); + // Apart from the row, nothing names the switch, and the audit says so. + let report = t + .try_finish() + .expect_err("a switch outside the label's node has no name"); + assert!( + report + .to_string() + .contains("this switch has no accessible name"), + "{report}" + ); +} + +/// A control whose Flutter counterpart is a container, found by the name its child gives it. +struct Stays { + control: &'static str, + name: &'static str, + build: fn() -> BoxedView, +} + +/// `ButtonStyleButton` (`packages/flutter/lib/src/material/button_style_button.dart:591`), +/// `RawMaterialButton` under the FAB (`material/button.dart:433`) and `RawChip` +/// (`material/chip.dart:1503`) are containers in Flutter 3.50.1: a label around one is a node of +/// its own, and the control keeps the name its child gives it. +pub fn a_label_around_a_container_control_is_a_node_above_it() { + let rows = [ + Stays { + control: "ElevatedButton", + name: "Send", + build: || { + ElevatedButton::new(Text::new("Send")) + .on_pressed(|_ctx| {}) + .boxed() + }, + }, + Stays { + control: "FloatingActionButton", + name: "Add", + build: || { + FloatingActionButton::new() + .child(Text::new("Add")) + .on_pressed(|_ctx| {}) + .boxed() + }, + }, + Stays { + control: "FilterChip", + name: "Spicy", + build: || { + FilterChip::new(Text::new("Spicy")) + .on_selected(|_ctx, _| {}) + .boxed() + }, + }, + ]; + + for row in rows { + let mut t = Tester::mount_in( + labelled(Semantics::new().label(LABEL), (row.build)()), + window(), + ); + let control = t.read(&find::button(row.name)); + let label = t.read(&find::text(LABEL)); + assert_ne!( + label.id, control.id, + "{}: the label is a node above it", + row.control + ); + assert_ne!(label.role, Role::Button, "{}", row.control); + t.finish(); + } } diff --git a/packages/flui-material/tests/tabs.rs b/packages/flui-material/tests/tabs.rs index ee994a3754..6f295293ed 100644 --- a/packages/flui-material/tests/tabs.rs +++ b/packages/flui-material/tests/tabs.rs @@ -833,7 +833,7 @@ pub(crate) fn tab_controller_listener_writes_from_an_event_callback() { /// into it, nothing beneath it keeps a node of its own, and assistive /// technology's click and focus on that node reach the tab's well. /// -/// Red-check: drop `merges_descendants` from the tab's description (the +/// Red-check: make the tab's description `Description::new` in place of `Description::merging` (the /// label and the inner node stay nodes of their own, and the tab node /// carries no label). pub fn a_tab_is_one_node_that_takes_its_contents_and_their_actions() { From e58f4d73ea10a2a426e476b0f04422d3cf6a7682 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 19:39:36 +0000 Subject: [PATCH 06/10] widgets, material, cupertino: a test pins each control's form; ADR-0407 states the identifier refusal, the disabled toggle and the row template Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EqfW4FAhVS5dwwxVx5vRGK --- changelog.d/claude-project-thread-f2wym8.md | 16 ++-- crates/flui-semantics/src/configuration.rs | 9 +- crates/flui-widgets/tests/raw_button.rs | 18 ++++ docs/adr/ADR-0240-semantics-identifier.md | 4 +- ...joins-the-semantics-annotation-above-it.md | 91 ++++++++++++------- packages/flui-cupertino/tests/button.rs | 25 +++++ packages/flui-cupertino/tests/main.rs | 4 + 7 files changed, 122 insertions(+), 45 deletions(-) diff --git a/changelog.d/claude-project-thread-f2wym8.md b/changelog.d/claude-project-thread-f2wym8.md index 845ce0d1bb..806b367683 100644 --- a/changelog.d/claude-project-thread-f2wym8.md +++ b/changelog.d/claude-project-thread-f2wym8.md @@ -1,10 +1,12 @@ ### Changed -- `Semantics::label` around a `Switch`, `Checkbox`, `Radio`, `CupertinoButton`, a tappable - carousel item or an enabled `ListTile` names that control's own node, as in Flutter 3.50.1: - their semantics are no longer a container of their own and join the annotation above them. - Buttons, chips, a chip's delete button and a disabled `ListTile` stay nodes of their own - (ADR-0407). +- `Semantics::label` around a `Switch`, `Checkbox`, `Radio`, `CupertinoButton` or an enabled + `ListTile` names that control's own node, as in Flutter 3.50.1: their semantics are no longer a + container of their own and join the annotation above them, a disabled toggle included. Buttons, + chips, a chip's delete button and a disabled `ListTile` stay nodes of their own (ADR-0407). - A semantics configuration absorbed into another node gives that node its identifier when the - node has none of its own, first wins, so a control's `identifier` survives joining the - `Semantics` that names it (ADR-0407). + node has none of its own, so a control's `identifier` survives joining the `Semantics` that + names it. Outside a `MergeSemantics`, a configuration whose identifier differs from the node + above it forms a node of its own and keeps it. A control that joins its row now names the row, + so a row template that repeats the control's identifier in every row reports a sibling clash: + name each row instead (ADR-0407). diff --git a/crates/flui-semantics/src/configuration.rs b/crates/flui-semantics/src/configuration.rs index 9ec4db373d..2f6bb70fcb 100644 --- a/crates/flui-semantics/src/configuration.rs +++ b/crates/flui-semantics/src/configuration.rs @@ -1606,7 +1606,7 @@ impl SemanticsConfiguration { /// one named button, not a nameless button with an image beneath it. #[must_use] pub fn can_absorb(&self, descendant: &SemanticsConfiguration, names_a_control: bool) -> bool { - !self.names_another_node(descendant) + !(descendant.has_been_annotated && self.names_another_node(descendant)) && self.shares_a_node_with(descendant, names_a_control && descendant.has_naming_role()) } @@ -1627,10 +1627,11 @@ impl SemanticsConfiguration { /// Whether this configuration and `other` name different nodes: both carry /// an identifier and the two differ. A node publishes one identifier, so a /// control that would join a node named otherwise forms its own and keeps - /// the id its author gave it (ADR-0407 §2). It is read whether or not - /// either is annotated, since an identifier annotates nothing and a + /// the id its author gave it (ADR-0407 §2). The receiver is read whether + /// or not it is annotated, since an identifier annotates nothing and a /// container that only names itself still refuses a control named - /// otherwise. + /// otherwise; an absorbed configuration that says nothing but its + /// identifier contributes nothing, so `can_absorb` takes it as before. fn names_another_node(&self, other: &SemanticsConfiguration) -> bool { matches!( (self.identifier(), other.identifier()), diff --git a/crates/flui-widgets/tests/raw_button.rs b/crates/flui-widgets/tests/raw_button.rs index 5708efdb80..b1a0444faa 100644 --- a/crates/flui-widgets/tests/raw_button.rs +++ b/crates/flui-widgets/tests/raw_button.rs @@ -1357,3 +1357,21 @@ pub(crate) fn a_listener_panic_under_a_new_hold_leaves_no_hold_behind() { drop(hold); assert!(!pressed(&states), "and its drop releases"); } + +/// `RawButton` is a container, as `RawMaterialButton` is in Flutter 3.50.1 +/// (`packages/flutter/lib/src/material/button.dart:433`): a `Semantics` label +/// around it is a node of its own, and the button keeps the name its child +/// gives it (ADR-0407). +#[test] +fn a_label_around_a_raw_button_is_a_node_above_it() { + use flui_testing::scenario::{Tester, find}; + use flui_widgets::{Column, Semantics}; + + let mut t = Tester::mount(Column::new((Semantics::new() + .label("Send") + .child(RawButton::new(Text::new("Go")).on_pressed(|_ctx| {})),))); + let button = t.read(&find::button("Go")); + let label = t.read(&find::text("Send")); + assert_ne!(label.id, button.id, "the label is a node above the button"); + t.finish(); +} diff --git a/docs/adr/ADR-0240-semantics-identifier.md b/docs/adr/ADR-0240-semantics-identifier.md index 65a2df50f9..87fd9adfda 100644 --- a/docs/adr/ADR-0240-semantics-identifier.md +++ b/docs/adr/ADR-0240-semantics-identifier.md @@ -43,7 +43,9 @@ its driver), Compose's `testTag`, Android `resource-id`, iOS `accessibilityIdent the form that is found, a role on the node (as `Group`) or the identifier on the control. 4. An identifier is unique among its siblings by contract, as AccessKit requires of `author_id`: an OS automation client matching it on two siblings finds only one. It need not be unique - anywhere else, so a row template can name its "delete" button in every row. A clash is the + anywhere else, so a row template can name its "delete" button in every row while the button is + a node of its own. A control that joins its row's node names the row (ADR-0407 §2), so a + template whose control joins names each row instead, or keeps the control apart. A clash is the author's defect and is reported, never repaired: translation publishes the identifiers as written, debug builds report the clash to the log naming the parent, and a wire read lists a `duplicate_identifier` diagnostic naming the parent and the siblings (schema `0.6`), so a test diff --git a/docs/adr/ADR-0407-a-control-joins-the-semantics-annotation-above-it.md b/docs/adr/ADR-0407-a-control-joins-the-semantics-annotation-above-it.md index f5e2f4f532..c4249977c3 100644 --- a/docs/adr/ADR-0407-a-control-joins-the-semantics-annotation-above-it.md +++ b/docs/adr/ADR-0407-a-control-joins-the-semantics-annotation-above-it.md @@ -59,7 +59,7 @@ Which node does a control's description form, and what does a node keep of what ## Considered options 1. A description is an annotation unless its Flutter counterpart is a container, and `absorb` - carries an identifier, first wins. + carries an identifier, first wins, while two different identifiers are two nodes. 2. Keep every description a container and give each control a label builder (`semantic_label`, or a `label` on `Description`). 3. Make every description an annotation, buttons and chips included. @@ -79,16 +79,16 @@ impl Description { /// An annotation of `role`: it forms a node where its parent asks for explicit /// children, and otherwise joins the annotation above it. pub fn new(role: SemanticsRole) -> Self; - /// A node of its own wherever it is, as `Semantics::container(true)`. - pub fn container(self) -> Self; - /// A node of its own that folds every node beneath it, as `MergeSemantics`. - pub fn merges_descendants(self) -> Self; + /// A node of `role` of its own wherever it is, as `Semantics::container(true)`. + pub fn container(role: SemanticsRole) -> Self; + /// A node of `role` of its own that folds every node beneath it, as `MergeSemantics`. + pub fn merging(role: SemanticsRole) -> Self; } ``` -The form is one private enum in the description (annotation, container, merge), so a merge is -always a container and nothing else can disagree with it. The catalogs choose by their Flutter -counterpart: +The form is chosen once, by the constructor, and held in one private enum (annotation, container, +merge), so no later call turns a merge into a plain container. The catalogs choose by their +Flutter counterpart: | Control | Form | Flutter 3.50.1 | |---|---|---| @@ -96,7 +96,7 @@ counterpart: | `CupertinoButton`, a cupertino tab item | annotation | `cupertino/button.dart:572`, `cupertino/bottom_tab_bar.dart:221` | | A tappable carousel item | annotation | `InkWell`'s `Semantics(onTap:)`, `material/ink_well.dart:1400` | | An enabled `ListTile` with a role | annotation | `material/list_tile.dart:995` | -| A disabled `ListTile` with a role | container | departs: Flutter folds `enabled: false` into the node above, which would read the enclosing list as disabled | +| A disabled `ListTile` with a role | container | departs: a tile carries content, and Flutter folds its `enabled: false` into the node above, which would read the enclosing list as disabled | | `RawButton`, the `ButtonStyleButton` family, `FloatingActionButton` | container | `material/button_style_button.dart:591`, `material/button.dart:433` | | `Chip`, `FilterChip`, a chip's delete button | container | `material/chip.dart:1503`, `material/chip.dart:2470` | | A `TabBar` tab, a `NavigationBar` destination | merge | `MergeSemantics`, `material/tabs.dart:2108`, `material/navigation_bar.dart:303` | @@ -106,25 +106,43 @@ and `Semantics::new().label("Send").child(ElevatedButton::new(Text::new("Go")))` above a button "Go", as in Flutter. A control that names itself, as `Checkbox::semantic_label` does, writes the same label inside the control. `Switch` and `Radio` take no label builder. +A disabled toggle joins too: the label's node reads as that disabled switch, which is what the +label names. The departure is the tile's alone, because a tile is a row of content whose +`enabled: false` would otherwise be read as the state of the list holding it; a toggle's node is +the toggle. The carousel item and the cupertino tab item sit where their parent asks for explicit +children (another item's tap, the tab list's `explicit_child_nodes`), so their two forms publish +the same tree; they follow Flutter for the next parent that does not. + Where two annotations cannot share a node (two roles, two handlers for one action, ADR-0206 -decision 4), they split as before: a switch inside a tappable `ListTile` is a node of its own. +decision 4, or two identifiers, §2), they split as before: a switch inside a tappable `ListTile` +is a node of its own. -### §2 An absorbed identifier names the node that takes it, first wins +### §2 A node carries one identifier, and the one a control joins with is kept `SemanticsConfiguration::absorb` keeps the receiver's identifier and takes the absorbed configuration's when the receiver has none, as Flutter's `absorb` does -(`semantics/semantics.dart:6954`). A switch that joins its label's node keeps -`Switch::identifier` on that node, and a merged tab keeps its own over its children's. The rest -of ADR-0240 stands: an identifier is never text, never annotates a configuration and never makes a -boundary, so a configuration that carries only an identifier is absorbed by nobody and names no -node. +(`semantics/semantics.dart:6954`): a switch that joins its label's node keeps +`Switch::identifier` on that node. A node publishes one identifier, so two different ones are two +nodes: `can_absorb` and `can_join` refuse a configuration whose identifier differs from the node's +or a sibling's, and it forms a node of its own that keeps its id. Flutter keeps the first and +drops the other; here a locator that selected a control by its identifier still selects it. A +`MergeSemantics` takes everything it merges, so a merge keeps its own identifier, or the first one +merged. The rest of ADR-0240 stands: an identifier is never text, never annotates a configuration +and never makes a boundary, so a configuration that carries only an identifier is absorbed by +nobody and names no node. + +A control that joins its row's node names the row. A row template that repeats a control's +identifier in every row therefore repeats it among the rows, which are siblings, and ADR-0240 §4 +reports the clash. The template names each row (the control, named otherwise, then keeps a node +of its own), or puts the control under a container of its own. ### Flutter counterparts | Here | Flutter | Why it differs | |---|---|---| -| `Description::new`, `container`, `merges_descendants` | `Semantics(container: false)`, `Semantics(container: true)`, `MergeSemantics` | the same three forms, chosen per control by its Flutter counterpart | +| `Description::new`, `container`, `merging` | `Semantics(container: false)`, `Semantics(container: true)`, `MergeSemantics` | the same three forms, chosen per control by its Flutter counterpart | | A disabled `ListTile` is a container | `Semantics(enabled: false)` joins the node above | an enclosing list or row would read as disabled | +| Two identifiers are two nodes | `absorb` keeps the first, the other is dropped | a control's id is a test's handle on it, and dropping it silently loses the control | | An identifier alone annotates nothing | setting `identifier` sets `hasBeenAnnotated` | ADR-0240 §1: an id added for a test does not change the tree a screen reader reads | ### Consequences @@ -136,32 +154,39 @@ node. - Good, because nothing is added to a control's element, render node or view: the form replaces a `bool` in `Description`, and the perf baselines of `flui-widgets`, `flui-material` and `flui-cupertino` hold unchanged. -- Bad, because an annotation joins whatever annotation is above it: a toggle inside a - `Semantics` that is no container and holds other content folds into that node, as it does in - Flutter. An author who wants the toggle apart writes a container around it. -- Bad, because a node that absorbs two identified controls carries only the first identifier; - the second control's id selects nothing until it forms its own node. +- Bad, because an annotation joins whatever annotation is above it: a toggle, disabled or not, + inside a `Semantics` that is no container and holds other content folds into that node, as it + does in Flutter. An author who wants the toggle apart writes a container around it. +- Bad, because a row template whose control joins its row moves the control's identifier to the + row, where siblings share it (§2). ### Confirmation -- `packages/flui-material/tests/named_by_semantics.rs`, - `a_label_around_a_toggle_names_the_toggles_own_node`: a `Semantics` label around a `Switch`, a - `Checkbox` and a `Radio` each carrying an identifier finds exactly one node by the label, of the - control's role, with the control's identifier, and its tap reaches the control; it fails with - the description a container and with `absorb` dropping the identifier. - `a_label_around_a_container_control_is_a_node_above_it`: an `ElevatedButton` keeps its own node - and name beneath the label. +- `packages/flui-material/tests/named_by_semantics.rs`: + `a_label_around_a_toggle_or_a_tile_names_the_controls_own_node` finds one node by the label + around a `Switch` (enabled and disabled), a `Checkbox`, a `Radio` and an enabled `ListTile`, of + the control's role and enablement, with the identifier, and its tap reaches the control; it fails + with any of them a container. `a_toggle_keeps_its_identifier_whatever_names_the_node_above_it`: + the switch's identifier on the label's node, and its own node under a node named otherwise; it + fails with `absorb` dropping the identifier and with the refusal removed. + `a_label_around_a_container_control_is_a_node_above_it`: `ElevatedButton`, the FAB and a + `FilterChip` keep their own node and name beneath the label; it fails with the FAB an + annotation. +- `flui-cupertino`'s `button::a_label_around_a_button_names_the_buttons_own_node` and + `flui-widgets`' `raw_button::a_label_around_a_raw_button_is_a_node_above_it`, each failing with + the other form. - `flui-semantics`'s `the_identifier_is_exported_unannounced_no_boundary_and_joins_first_wins` - and `flui-rendering`'s `an_identifier_names_the_node_its_configuration_forms_or_joins`: the - identifier through `absorb` and through assembly, a bare identifier absorbed by nobody. + (first wins, and two identifiers refused by `can_absorb` and `can_join`) and `flui-rendering`'s + `an_identifier_names_the_node_its_configuration_forms_or_joins` (through assembly, a bare + identifier absorbed by nobody). - `raw_button_a11y_tree_matches_wrappers` and `ink_well_a11y_tree_matches_wrappers` (ADR-0322) - still hold for the containers. + still hold. - `const _: () = assert!(size_of::() <= 16)` in `interaction/node.rs`, and the `perf` targets of the three crates under `FLUI_PERF_BASELINE=check`. ## Pros and cons of the options -### 1. Annotation unless the counterpart is a container, identifier first wins +### 1. Annotation unless the counterpart is a container, one identifier per node - Good, because an application's `Semantics` means what it means in Flutter. - Good, because the choice is one line per control, read against its Flutter counterpart. diff --git a/packages/flui-cupertino/tests/button.rs b/packages/flui-cupertino/tests/button.rs index 934ec808a9..7b970f420d 100644 --- a/packages/flui-cupertino/tests/button.rs +++ b/packages/flui-cupertino/tests/button.rs @@ -261,6 +261,31 @@ pub fn button_publishes_its_identifier() { t.finish(); } +/// `CupertinoButton` is `Semantics(button: true)` in Flutter 3.50.1, no container +/// (`packages/flutter/lib/src/cupertino/button.dart:572`): a label around it names the button's +/// own node, which keeps the button's identifier and its tap (ADR-0407). +pub fn a_label_around_a_button_names_the_buttons_own_node() { + let taps = std::rc::Rc::new(std::cell::Cell::new(0_u32)); + let counter = std::rc::Rc::clone(&taps); + let mut t = Tester::mount_in( + Constrain::loose(Size::new(200.0, 200.0)).child( + flui_sdk::widgets::Semantics::new().label("Send").child( + CupertinoButton::new(Text::new("Go")) + .on_pressed(move |_ctx| counter.set(counter.get() + 1)) + .identifier("send"), + ), + ), + TestWindow::default(), + ); + let named = t.read(&find::text_containing("Send")); + assert_eq!(named.role, Role::Button, "{named:?}"); + assert_eq!(named.identifier.as_deref(), Some("send"), "{named:?}"); + assert_eq!(t.read(&find::role(Role::Button)).id, named.id, "one node"); + t.tap(&find::text_containing("Send")); + assert_eq!(taps.get(), 1); + t.finish(); +} + /// A button with both callbacks answers a held contact with its long press /// alone, and a quick one with its tap alone: the two compete in one press /// group, as Flutter's `GestureDetector` with both slots does. diff --git a/packages/flui-cupertino/tests/main.rs b/packages/flui-cupertino/tests/main.rs index a8326556de..1e34d5496b 100644 --- a/packages/flui-cupertino/tests/main.rs +++ b/packages/flui-cupertino/tests/main.rs @@ -109,6 +109,10 @@ fn component_contracts() { "button::button publishes its identifier", button::button_publishes_its_identifier, ), + ( + "button::a label around a button names the buttons own node", + button::a_label_around_a_button_names_the_buttons_own_node, + ), ( "button::an active press fade migrates and retires", button::an_active_button_press_fade_migrates_and_retires, From 7cfa77ea29e6849f7f5e712c6bd96608e757f878 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 20:01:16 +0000 Subject: [PATCH 07/10] semantics: a disabled control and a node with a user action are two nodes; the identifier docs of the controls state the joined node Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EqfW4FAhVS5dwwxVx5vRGK --- crates/flui-semantics/src/configuration.rs | 56 +++++++++++++------ crates/flui-semantics/tests/identifier.rs | 26 ++++++++- crates/flui-widgets/src/text/editable_text.rs | 5 +- ...joins-the-semantics-annotation-above-it.md | 27 +++++---- packages/flui-cupertino/src/button.rs | 2 +- packages/flui-material/src/checkbox.rs | 2 +- packages/flui-material/src/radio.rs | 2 +- packages/flui-material/src/switch.rs | 2 +- packages/flui-material/tests/main.rs | 4 ++ .../flui-material/tests/named_by_semantics.rs | 40 ++++++++++++- 10 files changed, 128 insertions(+), 38 deletions(-) diff --git a/crates/flui-semantics/src/configuration.rs b/crates/flui-semantics/src/configuration.rs index 2f6bb70fcb..afafdc3424 100644 --- a/crates/flui-semantics/src/configuration.rs +++ b/crates/flui-semantics/src/configuration.rs @@ -1606,7 +1606,7 @@ impl SemanticsConfiguration { /// one named button, not a nameless button with an image beneath it. #[must_use] pub fn can_absorb(&self, descendant: &SemanticsConfiguration, names_a_control: bool) -> bool { - !(descendant.has_been_annotated && self.names_another_node(descendant)) + !self.keeps_apart(descendant) && self.shares_a_node_with(descendant, names_a_control && descendant.has_naming_role()) } @@ -1621,22 +1621,44 @@ impl SemanticsConfiguration { #[must_use] pub fn can_join(&self, sibling: &SemanticsConfiguration, names_a_control: bool) -> bool { let folds = names_a_control && self.has_naming_role() && sibling.has_naming_role(); - !self.names_another_node(sibling) && self.shares_a_node_with(sibling, folds) - } - - /// Whether this configuration and `other` name different nodes: both carry - /// an identifier and the two differ. A node publishes one identifier, so a - /// control that would join a node named otherwise forms its own and keeps - /// the id its author gave it (ADR-0407 §2). The receiver is read whether - /// or not it is annotated, since an identifier annotates nothing and a - /// container that only names itself still refuses a control named - /// otherwise; an absorbed configuration that says nothing but its - /// identifier contributes nothing, so `can_absorb` takes it as before. - fn names_another_node(&self, other: &SemanticsConfiguration) -> bool { - matches!( - (self.identifier(), other.identifier()), + !self.keeps_apart(sibling) + && !sibling.keeps_apart(self) + && self.shares_a_node_with(sibling, folds) + } + + /// Whether `joining`, a configuration that would be folded into this one's + /// node (as a descendant or a sibling), must form a node of its own + /// instead (ADR-0407 §2). Read only for an annotated `joining`: one that + /// says nothing but its identifier contributes nothing and is never + /// folded. This configuration is read whether or not it is annotated, + /// since an identifier annotates nothing and a container that only names + /// itself still keeps a control named otherwise apart. + /// + /// - **Two identifiers.** A node publishes one, so a control named + /// otherwise than the node keeps its own node and the id its author + /// gave it. + /// - **A disabled control beside actions.** One side says it is disabled + /// and the other offers a user action: folded, the node would read as + /// disabled and refuse the other's action (`SemanticsOwner` refuses + /// every action but focus, blur and reveal on a disabled node). + fn keeps_apart(&self, joining: &SemanticsConfiguration) -> bool { + if !joining.has_been_annotated { + return false; + } + let names_another = matches!( + (self.identifier(), joining.identifier()), (Some(mine), Some(theirs)) if mine != theirs - ) + ); + names_another || self.disables_actions_of(joining) || joining.disables_actions_of(self) + } + + /// Whether this configuration says it is disabled while `other` offers a + /// user action, one that a disabled node refuses. + fn disables_actions_of(&self, other: &SemanticsConfiguration) -> bool { + const STAY_AVAILABLE: u64 = SemanticsAction::Focus.value() + | SemanticsAction::Blur.value() + | SemanticsAction::ScrollIntoView.value(); + self.is_enabled() == Some(false) && other.actions_as_bits() & !STAY_AVAILABLE != 0 } /// Returns whether this configuration, absorbed by the configuration @@ -1684,7 +1706,7 @@ impl SemanticsConfiguration { label: _, value, hint: _, - // Compared by `names_another_node`, which `can_absorb` and + // Compared by `keeps_apart`, which `can_absorb` and // `can_join` read and `can_stay_beside` does not. identifier: _, text_direction: _, diff --git a/crates/flui-semantics/tests/identifier.rs b/crates/flui-semantics/tests/identifier.rs index 30d5eed40d..fbb46f4dc1 100644 --- a/crates/flui-semantics/tests/identifier.rs +++ b/crates/flui-semantics/tests/identifier.rs @@ -191,16 +191,38 @@ fn the_identifier_is_exported_unannounced_no_boundary_and_joins_first_wins() { Claim { claim: "no boundary: an identifier alone contributes nothing to a parent", holds: || { - let mut parent = named("Row 7", "row-7"); + // A parent with no identifier, so a carried one would show. + let mut parent = SemanticsConfiguration::new(); + parent.set_label("Row 7"); let before = parent.clone(); let mut child = SemanticsConfiguration::new(); child.set_identifier(IDENTIFIER); parent.can_absorb(&child, false) && { parent.absorb(&child); - parent == before + parent == before && parent.identifier().is_none() } }, }, + Claim { + claim: "a disabled control and a node with a user action are two nodes, either way", + holds: || { + let mut row = SemanticsConfiguration::new(); + row.set_label("Row 7"); + row.add_action( + flui_semantics::SemanticsAction::Click, + std::rc::Rc::new(|_| {}), + ); + let mut toggle = SemanticsConfiguration::new(); + toggle.set_label("Wi-Fi"); + toggle.set_enabled(Some(false)); + let mut label = SemanticsConfiguration::new(); + label.set_label("Network"); + !row.can_absorb(&toggle, false) + && !toggle.can_absorb(&row, false) + && !row.can_join(&toggle, false) + && label.can_absorb(&toggle, false) + }, + }, ]; let failed: Vec<&str> = claims .iter() diff --git a/crates/flui-widgets/src/text/editable_text.rs b/crates/flui-widgets/src/text/editable_text.rs index c6660313be..b38ad1a36b 100644 --- a/crates/flui-widgets/src/text/editable_text.rs +++ b/crates/flui-widgets/src/text/editable_text.rs @@ -379,8 +379,9 @@ impl EditableText { /// Names the field's node for tests and automation (ADR-0240): exported /// as UI Automation's `AutomationId`, never announced. A `Semantics` that /// annotates the field from above, a label naming it for instance, takes - /// the field into its own node and keeps only its own identifier: name the - /// field on that `Semantics` then. + /// the field into its own node, which this identifier then names unless + /// the `Semantics` has one of its own; one named otherwise leaves the + /// field a node of its own, apart from the label (ADR-0407). #[must_use] pub fn identifier(mut self, identifier: impl Into>) -> Self { self.field_semantics.identifier = Some(identifier.into()); diff --git a/docs/adr/ADR-0407-a-control-joins-the-semantics-annotation-above-it.md b/docs/adr/ADR-0407-a-control-joins-the-semantics-annotation-above-it.md index c4249977c3..2340118e46 100644 --- a/docs/adr/ADR-0407-a-control-joins-the-semantics-annotation-above-it.md +++ b/docs/adr/ADR-0407-a-control-joins-the-semantics-annotation-above-it.md @@ -34,10 +34,9 @@ of its own, and it is the same `Semantics(label:)` written inside the control. FLUI's controls describe themselves through `InteractiveNode`'s `Description` (ADR-0322 §1), which built every description as `Semantics::container(true)`. A container always forms its own node, so the label around a switch formed a second node above it and the switch stayed nameless. -The end-of-test audit refuses a nameless control, so the testing platform's move of -`flui-material`'s tests (#3264) named `Switch` and `Radio` by adding `semantic_label` to each, -a builder Flutter does not have, and the next control would repeat it. The assembly already -follows Flutter's rule (a configuration that is no boundary is absorbed by the node above it, +The end-of-test audit refuses a nameless control, so each control would need a label builder of +its own, which Flutter has only on `Checkbox`, and every new control would repeat it. The assembly +already follows Flutter's rule (a configuration that is no boundary is absorbed by the node above it, and conflicting ones split, ADR-0206); the container flag is what kept a control out of it. A second rule stood in the way: `SemanticsConfiguration::absorb` dropped the identifier of what it @@ -106,18 +105,20 @@ and `Semantics::new().label("Send").child(ElevatedButton::new(Text::new("Go")))` above a button "Go", as in Flutter. A control that names itself, as `Checkbox::semantic_label` does, writes the same label inside the control. `Switch` and `Radio` take no label builder. -A disabled toggle joins too: the label's node reads as that disabled switch, which is what the -label names. The departure is the tile's alone, because a tile is a row of content whose +A disabled toggle joins a label too: the label's node reads as that disabled switch, which is what +the label names. It does not join a node that offers a user action of its own (a tappable row, an +`InkWell`): folded, that node would read as disabled and refuse its own action, so the two stay +apart (§2). The tile's departure is its own, because a tile is a row of content whose `enabled: false` would otherwise be read as the state of the list holding it; a toggle's node is the toggle. The carousel item and the cupertino tab item sit where their parent asks for explicit children (another item's tap, the tab list's `explicit_child_nodes`), so their two forms publish the same tree; they follow Flutter for the next parent that does not. Where two annotations cannot share a node (two roles, two handlers for one action, ADR-0206 -decision 4, or two identifiers, §2), they split as before: a switch inside a tappable `ListTile` -is a node of its own. +decision 4, or two identifiers or a disabled control beside an action, §2), they split as +before: a switch inside a tappable `ListTile` is a node of its own. -### §2 A node carries one identifier, and the one a control joins with is kept +### §2 A node carries one identifier and one enablement for its actions `SemanticsConfiguration::absorb` keeps the receiver's identifier and takes the absorbed configuration's when the receiver has none, as Flutter's `absorb` does @@ -136,6 +137,11 @@ identifier in every row therefore repeats it among the rows, which are siblings, reports the clash. The template names each row (the control, named otherwise, then keeps a node of its own), or puts the control under a container of its own. +A disabled control and a node that offers a user action of its own stay apart the same way +(`keeps_apart`, read by `can_absorb` and `can_join`): folded, the node would read as disabled and +`SemanticsOwner` would refuse every action on it but focus, blur and reveal, the row's tap +included. Flutter merges the two; its merged node is disabled with the row's tap on it. + ### Flutter counterparts | Here | Flutter | Why it differs | @@ -144,6 +150,7 @@ of its own), or puts the control under a container of its own. | A disabled `ListTile` is a container | `Semantics(enabled: false)` joins the node above | an enclosing list or row would read as disabled | | Two identifiers are two nodes | `absorb` keeps the first, the other is dropped | a control's id is a test's handle on it, and dropping it silently loses the control | | An identifier alone annotates nothing | setting `identifier` sets `hasBeenAnnotated` | ADR-0240 §1: an id added for a test does not change the tree a screen reader reads | +| A disabled control and a node with a user action are two nodes | they merge, and the node reads as disabled | the merged node would refuse the action it offers | ### Consequences @@ -154,7 +161,7 @@ of its own), or puts the control under a container of its own. - Good, because nothing is added to a control's element, render node or view: the form replaces a `bool` in `Description`, and the perf baselines of `flui-widgets`, `flui-material` and `flui-cupertino` hold unchanged. -- Bad, because an annotation joins whatever annotation is above it: a toggle, disabled or not, +- Bad, because an annotation joins whatever annotation above it can take it: a toggle inside a `Semantics` that is no container and holds other content folds into that node, as it does in Flutter. An author who wants the toggle apart writes a container around it. - Bad, because a row template whose control joins its row moves the control's identifier to the diff --git a/packages/flui-cupertino/src/button.rs b/packages/flui-cupertino/src/button.rs index 87e7301f7d..f363cfee51 100644 --- a/packages/flui-cupertino/src/button.rs +++ b/packages/flui-cupertino/src/button.rs @@ -301,7 +301,7 @@ impl CupertinoButton { /// Names the button's node for tests and automation (ADR-0240): exported /// as UI Automation's `AutomationId`, never announced. It names the node - /// the button's semantics form; see `Semantics::identifier`. + /// the button's semantics form or join (ADR-0407); see `Semantics::identifier`. #[must_use] pub fn identifier(mut self, identifier: impl Into>) -> Self { self.identifier = Some(identifier.into()); diff --git a/packages/flui-material/src/checkbox.rs b/packages/flui-material/src/checkbox.rs index 9152ae3c10..6286c48709 100644 --- a/packages/flui-material/src/checkbox.rs +++ b/packages/flui-material/src/checkbox.rs @@ -276,7 +276,7 @@ impl Checkbox { /// Names the checkbox's node for tests and automation (ADR-0240): exported /// as UI Automation's `AutomationId`, never announced. It names the node - /// the checkbox's semantics form; see `Semantics::identifier`. + /// the checkbox's semantics form or join (ADR-0407); see `Semantics::identifier`. #[must_use] pub fn identifier(mut self, identifier: impl Into>) -> Self { self.identifier = Some(identifier.into()); diff --git a/packages/flui-material/src/radio.rs b/packages/flui-material/src/radio.rs index a0bac5ccca..00870eb6ed 100644 --- a/packages/flui-material/src/radio.rs +++ b/packages/flui-material/src/radio.rs @@ -215,7 +215,7 @@ impl Radio { /// Names the radio's node for tests and automation (ADR-0240): exported /// as UI Automation's `AutomationId`, never announced. It names the node - /// the radio's semantics form; see `Semantics::identifier`. + /// the radio's semantics form or join (ADR-0407); see `Semantics::identifier`. #[must_use] pub fn identifier(mut self, identifier: impl Into>) -> Self { self.identifier = Some(identifier.into()); diff --git a/packages/flui-material/src/switch.rs b/packages/flui-material/src/switch.rs index 04ceb41c65..29dba6993f 100644 --- a/packages/flui-material/src/switch.rs +++ b/packages/flui-material/src/switch.rs @@ -229,7 +229,7 @@ impl Switch { /// Names the switch's node for tests and automation (ADR-0240): exported /// as UI Automation's `AutomationId`, never announced. It names the node - /// the switch's semantics form; see `Semantics::identifier`. + /// the switch's semantics form or join (ADR-0407); see `Semantics::identifier`. #[must_use] pub fn identifier(mut self, identifier: impl Into>) -> Self { self.identifier = Some(identifier.into()); diff --git a/packages/flui-material/tests/main.rs b/packages/flui-material/tests/main.rs index 0cbe2fe2cc..9ac73cb0eb 100644 --- a/packages/flui-material/tests/main.rs +++ b/packages/flui-material/tests/main.rs @@ -522,6 +522,10 @@ fn selection_control_contracts() { "named_by_semantics::a label around a container control is a node above it", named_by_semantics::a_label_around_a_container_control_is_a_node_above_it, ), + ( + "named_by_semantics::a disabled toggle does not join a row that taps", + named_by_semantics::a_disabled_toggle_does_not_join_a_row_that_taps, + ), ( "radio::a mounted radio announces as a radio button", radio::a_mounted_radio_announces_as_a_radio_button, diff --git a/packages/flui-material/tests/named_by_semantics.rs b/packages/flui-material/tests/named_by_semantics.rs index 56db5f1ca2..f0842d4fcf 100644 --- a/packages/flui-material/tests/named_by_semantics.rs +++ b/packages/flui-material/tests/named_by_semantics.rs @@ -7,12 +7,12 @@ use std::cell::Cell; use std::rc::Rc; use flui_material::{ - Checkbox, ElevatedButton, FilterChip, FloatingActionButton, ListTile, Radio, Switch, Theme, - ThemeData, + Checkbox, ElevatedButton, FilterChip, FloatingActionButton, InkWell, ListTile, Radio, Switch, + Theme, ThemeData, }; use flui_protocol::wire::Role; use flui_sdk::view::{BoxedView, ViewExt}; -use flui_sdk::widgets::{Semantics, Text}; +use flui_sdk::widgets::{Row, Semantics, Text}; use flui_testing::scenario::{TestWindow, Tester, WindowSpec, find}; const LABEL: &str = "Wi-Fi"; @@ -235,3 +235,37 @@ pub fn a_label_around_a_container_control_is_a_node_above_it() { t.finish(); } } + +/// A disabled toggle inside a tappable row does not join the row's node: folded, the node would +/// read as disabled and refuse the row's own tap (ADR-0407 §2). The row keeps its tap, and the +/// toggle is a disabled node of its own. +pub fn a_disabled_toggle_does_not_join_a_row_that_taps() { + let taps = Rc::new(Cell::new(0_u32)); + let counter = Rc::clone(&taps); + let row = InkWell::new() + .on_tap(move |_ctx| counter.set(counter.get() + 1)) + .child(Row::new((Text::new(LABEL), Switch::new(false)))); + let mut t = Tester::mount_in(Theme::new(ThemeData::light(), row), window()); + + let named = t.read(&find::text(LABEL)); + assert!(!named.disabled, "the row reads as enabled"); + let switch = t.read(&find::role(Role::Switch)); + assert_ne!( + switch.id, named.id, + "the disabled toggle is a node of its own" + ); + assert!(switch.disabled); + t.tap(&find::text(LABEL)); + assert_eq!(taps.get(), 1, "the row's tap is not refused"); + + // The toggle apart has no name of its own, and the audit says so. + let report = t + .try_finish() + .expect_err("a switch outside the row's node has no name"); + assert!( + report + .to_string() + .contains("this switch has no accessible name"), + "{report}" + ); +} From 29ff2a8edfd7b454c54220812da4988293844eb3 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 20:18:49 +0000 Subject: [PATCH 08/10] semantics: only a disabled joiner is kept from a node with actions; a disabled node above still absorbs them Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EqfW4FAhVS5dwwxVx5vRGK --- crates/flui-semantics/src/configuration.rs | 11 +++++++---- crates/flui-semantics/tests/identifier.rs | 5 +++-- ...l-joins-the-semantics-annotation-above-it.md | 17 +++++++++++------ 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/crates/flui-semantics/src/configuration.rs b/crates/flui-semantics/src/configuration.rs index afafdc3424..90cdf6a33c 100644 --- a/crates/flui-semantics/src/configuration.rs +++ b/crates/flui-semantics/src/configuration.rs @@ -1637,10 +1637,13 @@ impl SemanticsConfiguration { /// - **Two identifiers.** A node publishes one, so a control named /// otherwise than the node keeps its own node and the id its author /// gave it. - /// - **A disabled control beside actions.** One side says it is disabled - /// and the other offers a user action: folded, the node would read as - /// disabled and refuse the other's action (`SemanticsOwner` refuses + /// - **A disabled control joining actions.** `joining` says it is disabled + /// and this configuration offers a user action: folded, the node would + /// read as disabled and refuse that action (`SemanticsOwner` refuses /// every action but focus, blur and reveal on a disabled node). + /// A disabled configuration that absorbs one with actions is the + /// author declaring the subtree disabled, and still absorbs it; + /// [`can_join`](Self::can_join) reads both directions, as siblings. fn keeps_apart(&self, joining: &SemanticsConfiguration) -> bool { if !joining.has_been_annotated { return false; @@ -1649,7 +1652,7 @@ impl SemanticsConfiguration { (self.identifier(), joining.identifier()), (Some(mine), Some(theirs)) if mine != theirs ); - names_another || self.disables_actions_of(joining) || joining.disables_actions_of(self) + names_another || joining.disables_actions_of(self) } /// Whether this configuration says it is disabled while `other` offers a diff --git a/crates/flui-semantics/tests/identifier.rs b/crates/flui-semantics/tests/identifier.rs index fbb46f4dc1..22fe6b147d 100644 --- a/crates/flui-semantics/tests/identifier.rs +++ b/crates/flui-semantics/tests/identifier.rs @@ -204,7 +204,7 @@ fn the_identifier_is_exported_unannounced_no_boundary_and_joins_first_wins() { }, }, Claim { - claim: "a disabled control and a node with a user action are two nodes, either way", + claim: "a disabled control joins no node with a user action; a disabled node above still absorbs one", holds: || { let mut row = SemanticsConfiguration::new(); row.set_label("Row 7"); @@ -218,7 +218,8 @@ fn the_identifier_is_exported_unannounced_no_boundary_and_joins_first_wins() { let mut label = SemanticsConfiguration::new(); label.set_label("Network"); !row.can_absorb(&toggle, false) - && !toggle.can_absorb(&row, false) + && toggle.can_absorb(&row, false) + && !toggle.can_join(&row, false) && !row.can_join(&toggle, false) && label.can_absorb(&toggle, false) }, diff --git a/docs/adr/ADR-0407-a-control-joins-the-semantics-annotation-above-it.md b/docs/adr/ADR-0407-a-control-joins-the-semantics-annotation-above-it.md index 2340118e46..9fbe82a646 100644 --- a/docs/adr/ADR-0407-a-control-joins-the-semantics-annotation-above-it.md +++ b/docs/adr/ADR-0407-a-control-joins-the-semantics-annotation-above-it.md @@ -137,10 +137,12 @@ identifier in every row therefore repeats it among the rows, which are siblings, reports the clash. The template names each row (the control, named otherwise, then keeps a node of its own), or puts the control under a container of its own. -A disabled control and a node that offers a user action of its own stay apart the same way -(`keeps_apart`, read by `can_absorb` and `can_join`): folded, the node would read as disabled and -`SemanticsOwner` would refuse every action on it but focus, blur and reveal, the row's tap -included. Flutter merges the two; its merged node is disabled with the row's tap on it. +A disabled control does not join a node that offers a user action of its own, as a descendant or +a sibling (`keeps_apart`, read by `can_absorb` and `can_join`): folded, the node would read as +disabled and `SemanticsOwner` would refuse every action on it but focus, blur and reveal, the +row's tap included. Flutter merges the two; its merged node is disabled with the row's tap on it. +A node that is itself disabled still absorbs the actions below it: that is its author declaring +the subtree disabled. ### Flutter counterparts @@ -150,7 +152,7 @@ included. Flutter merges the two; its merged node is disabled with the row's tap | A disabled `ListTile` is a container | `Semantics(enabled: false)` joins the node above | an enclosing list or row would read as disabled | | Two identifiers are two nodes | `absorb` keeps the first, the other is dropped | a control's id is a test's handle on it, and dropping it silently loses the control | | An identifier alone annotates nothing | setting `identifier` sets `hasBeenAnnotated` | ADR-0240 §1: an id added for a test does not change the tree a screen reader reads | -| A disabled control and a node with a user action are two nodes | they merge, and the node reads as disabled | the merged node would refuse the action it offers | +| A disabled control does not join a node with a user action | they merge, and the node reads as disabled | the merged node would refuse the action it offers | ### Consequences @@ -176,6 +178,8 @@ included. Flutter merges the two; its merged node is disabled with the row's tap with any of them a container. `a_toggle_keeps_its_identifier_whatever_names_the_node_above_it`: the switch's identifier on the label's node, and its own node under a node named otherwise; it fails with `absorb` dropping the identifier and with the refusal removed. + `a_disabled_toggle_does_not_join_a_row_that_taps`: a disabled `Switch` in an `InkWell` row + keeps its own disabled node and the row its tap; it fails with the refusal removed. `a_label_around_a_container_control_is_a_node_above_it`: `ElevatedButton`, the FAB and a `FilterChip` keep their own node and name beneath the label; it fails with the FAB an annotation. @@ -183,7 +187,8 @@ included. Flutter merges the two; its merged node is disabled with the row's tap `flui-widgets`' `raw_button::a_label_around_a_raw_button_is_a_node_above_it`, each failing with the other form. - `flui-semantics`'s `the_identifier_is_exported_unannounced_no_boundary_and_joins_first_wins` - (first wins, and two identifiers refused by `can_absorb` and `can_join`) and `flui-rendering`'s + (first wins, two identifiers refused by `can_absorb` and `can_join`, and a disabled control + refused by a node with an action while a disabled node still absorbs one) and `flui-rendering`'s `an_identifier_names_the_node_its_configuration_forms_or_joins` (through assembly, a bare identifier absorbed by nobody). - `raw_button_a11y_tree_matches_wrappers` and `ink_well_a11y_tree_matches_wrappers` (ADR-0322) From bf3608290a96fc48e831eed84dec287b4c4593b1 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 20:59:01 +0000 Subject: [PATCH 09/10] WIP: an annotation around a control alone names the control's node --- .../src/pipeline/owner/semantics.rs | 59 +++++++++ .../flui-rendering/tests/contract_matrices.rs | 1 + .../tests/semantics_assembly.rs | 79 ++++++++++++ crates/flui-semantics/src/configuration.rs | 27 ++++ crates/flui-widgets/tests/raw_button.rs | 27 +++- packages/flui-material/tests/main.rs | 8 +- .../flui-material/tests/named_by_semantics.rs | 117 ++++++++---------- 7 files changed, 238 insertions(+), 80 deletions(-) diff --git a/crates/flui-rendering/src/pipeline/owner/semantics.rs b/crates/flui-rendering/src/pipeline/owner/semantics.rs index 32cfc95054..11e19caa35 100644 --- a/crates/flui-rendering/src/pipeline/owner/semantics.rs +++ b/crates/flui-rendering/src/pipeline/owner/semantics.rs @@ -896,6 +896,28 @@ fn build_semantics_fragments_impl<'f>( }); } + if let Some(mut control) = sole_control_it_names( + &config, + &decisions, + clipped.hidden, + &mut child_fragments, + ) { + // The annotation was the item's root: the position stamped on it is + // the control's now. + apply_lazy_child_semantic_index( + node, + tree.parent(id), + &mut control.config, + &control.children, + ); + let mut nodes = Vec::with_capacity_in(1, arena); + nodes.push(SemanticsFragment::Formed(control)); + return Some(SemanticsFragments { + nodes, + blocks_previous_siblings, + }); + } + let (children, absorbed_inside) = merge_child_fragments( &mut config, &rect, @@ -934,6 +956,43 @@ fn build_semantics_fragments_impl<'f>( }) } +/// The control node an annotation names when the control is all it holds: a +/// `Semantics` around a button, a chip or a FAB names the control's own node +/// instead of forming one above it, as one around a switch does by joining it +/// (ADR-0407 §1). Flutter forms the node above, so a screen reader stops +/// twice, once on a name with no action and once on the nameless button. +/// +/// The annotation is none of a boundary, a merge or a part of one, its only +/// child fragment is a formed node whose role its content names, and the two +/// can share a node (`can_absorb`). Anything else is assembled as before. +fn sole_control_it_names<'f>( + config: &SemanticsConfiguration, + decisions: &NodeAssemblyDecisions, + hidden_by_clip: bool, + fragments: &mut FrameVec<'f, SemanticsFragment<'f>>, +) -> Option> { + let annotation = config.has_been_annotated() + && !config.is_semantics_boundary() + && !config.is_merge_boundary() + && !config.explicit_child_nodes() + && !decisions.children_merge_into_ancestor + && !hidden_by_clip; + if !annotation { + return None; + } + let [SemanticsFragment::Formed(control)] = fragments.as_mut_slice() else { + return None; + }; + if !control.config.names_a_control(true, false) || !config.can_absorb(&control.config, true) { + return None; + } + control.config.absorb_enclosing(config); + match fragments.pop() { + Some(SemanticsFragment::Formed(control)) => Some(control), + _ => None, + } +} + /// Checks that the regions holding a text's runs (ADR-0214 §2 as amended) /// hold each of its runs once, in run order: their ranges, in region order, /// are consecutive and cover every run. Regions hold runs only of the text diff --git a/crates/flui-rendering/tests/contract_matrices.rs b/crates/flui-rendering/tests/contract_matrices.rs index b6e10a0d7e..69cc3519a0 100644 --- a/crates/flui-rendering/tests/contract_matrices.rs +++ b/crates/flui-rendering/tests/contract_matrices.rs @@ -82,6 +82,7 @@ fn semantics_assembly_matrix() { let cases: &[(&str, fn())] = &[ ("semantics_assembly::a_semantics_clip_drops_a_child_that_falls_entirely_outside_it", crate::semantics_assembly::a_semantics_clip_drops_a_child_that_falls_entirely_outside_it), ("semantics_assembly::an_identifier_names_the_node_its_configuration_forms_or_joins", crate::semantics_assembly::an_identifier_names_the_node_its_configuration_forms_or_joins), + ("semantics_assembly::an_annotation_around_a_control_alone_names_the_controls_node", crate::semantics_assembly::an_annotation_around_a_control_alone_names_the_controls_node), ("semantics_assembly::a_table_shape_the_role_drops_bounds_no_cell", crate::semantics_assembly::a_table_shape_the_role_drops_bounds_no_cell), ("semantics_assembly::nonfinite_reading_order_is_refused_before_publication", crate::semantics_assembly::nonfinite_reading_order_is_refused_before_publication), ("semantics_assembly::re_assembling_marked_subtrees_refuses_like_the_whole_tree", crate::semantics_assembly::re_assembling_marked_subtrees_refuses_like_the_whole_tree), diff --git a/crates/flui-rendering/tests/semantics_assembly.rs b/crates/flui-rendering/tests/semantics_assembly.rs index 282776be26..88a1227f0b 100644 --- a/crates/flui-rendering/tests/semantics_assembly.rs +++ b/crates/flui-rendering/tests/semantics_assembly.rs @@ -1325,3 +1325,82 @@ pub(crate) fn a_handler_that_panics_in_a_graft_leaves_containment_to_a_rebuild() "every child of the holder is contained now, so it clips them" ); } + +/// A configuration with `label` and nothing else. +fn labelled(label: &str) -> SemanticsConfiguration { + let mut config = SemanticsConfiguration::new(); + config.set_label(label); + config +} + +/// An annotation whose only content is a control's node names that node +/// (ADR-0407 §1): the control's node takes the annotation's label before its +/// own, and no node forms above it. An annotation over the control and other +/// content still forms the node above both. +pub(crate) fn an_annotation_around_a_control_alone_names_the_controls_node() { + let run = RenderTester::mount( + box_node(SemanticsContainer::default()).label("root").child( + box_node(SemanticsContainer::default().with_boundary()) + .label("group") + .child( + box_node(SemanticsContainer::default().with_configuration(labelled("Send"))) + .label("label") + .child( + box_node(SemanticsLeaf { + configuration: Some(labelled("Go")), + ..SemanticsLeaf::new(20.0).with_boundary().with_button() + }) + .label("button"), + ), + ) + .child( + box_node(SemanticsContainer::default().with_configuration(labelled("Row"))) + .label("row") + .child(box_node(SemanticsLeaf { + configuration: Some(labelled("Draft")), + ..SemanticsLeaf::new(20.0) + })) + .child( + box_node(SemanticsLeaf { + configuration: Some(labelled("Open")), + ..SemanticsLeaf::new(20.0).with_boundary().with_button() + }) + .label("open"), + ), + ), + ), + ) + .with_constraints(constraints()) + .with_semantics_enabled() + .run_frame(); + + let root = accessibility_id(run.id("root")); + let group = accessibility_id(run.id("group")); + let button = accessibility_id(run.id("button")); + let open = accessibility_id(run.id("open")); + assert_snapshot_preorder(&snapshot(&run), &[root, group, button, open]); + + let owner = run + .owner() + .semantics_owner() + .expect("semantics must remain enabled"); + let node_of = |id: AccessibilityNodeId| { + owner + .tree() + .iter() + .find(|(_, node)| node.accessibility_id() == Some(id)) + .map(|(_, node)| node) + .expect("every expected accessibility identity resolves") + }; + assert_eq!( + node_of(button).label(), + Some("Send Go"), + "the annotation's label reads first, on the control's node" + ); + assert_eq!( + node_of(group).label(), + Some("Row Draft"), + "an annotation over more than the control is absorbed above it" + ); + assert_eq!(node_of(open).label(), Some("Open")); +} diff --git a/crates/flui-semantics/src/configuration.rs b/crates/flui-semantics/src/configuration.rs index 90cdf6a33c..0bcacdf384 100644 --- a/crates/flui-semantics/src/configuration.rs +++ b/crates/flui-semantics/src/configuration.rs @@ -1813,6 +1813,33 @@ impl SemanticsConfiguration { self.absorb_with(other, None); } + /// Absorbs `enclosing`, an annotation whose only content is the control + /// this configuration forms, so that a `Semantics` around a button names + /// the button's node instead of forming one above it (ADR-0407 §1). + /// + /// The rules are [`absorb`](Self::absorb)'s with `enclosing` read first, + /// as it reads above the control: its label and hint come before this + /// node's own, and its identifier wins. The caller has asked + /// whether `enclosing` [`can_absorb`](Self::can_absorb) this one first. + pub fn absorb_enclosing(&mut self, enclosing: &SemanticsConfiguration) { + let label = self.attributes.label.take(); + let hint = self.attributes.hint.take(); + let identifier = self.attributes.identifier.take(); + self.attributes.identifier.clone_from(&enclosing.attributes.identifier); + self.absorb(enclosing); + let append = |target: &mut Option, own: Option| { + *target = match (target.take(), own) { + (Some(outer), Some(own)) => Some(join_strings(&outer, &own)), + (outer, own) => outer.or(own), + }; + }; + append(&mut self.attributes.label, label); + append(&mut self.attributes.hint, hint); + if self.attributes.identifier.is_none() { + self.attributes.identifier = identifier; + } + } + /// Starts a forced merge (`MergeSemantics`) of `parts` into this /// configuration, the receiver: `parts` are every configuration the /// merge will absorb, in fold order (ADR-0392 §2). diff --git a/crates/flui-widgets/tests/raw_button.rs b/crates/flui-widgets/tests/raw_button.rs index b1a0444faa..02ec15603f 100644 --- a/crates/flui-widgets/tests/raw_button.rs +++ b/crates/flui-widgets/tests/raw_button.rs @@ -1359,19 +1359,34 @@ pub(crate) fn a_listener_panic_under_a_new_hold_leaves_no_hold_behind() { } /// `RawButton` is a container, as `RawMaterialButton` is in Flutter 3.50.1 -/// (`packages/flutter/lib/src/material/button.dart:433`): a `Semantics` label -/// around it is a node of its own, and the button keeps the name its child -/// gives it (ADR-0407). +/// (`packages/flutter/lib/src/material/button.dart:433`), so a `Semantics` +/// label around it does not join it: the button's node takes the label whose +/// only content it is, read before the name its child gives (ADR-0407 §1). +/// A label around the button and something else stays a node above them. #[test] -fn a_label_around_a_raw_button_is_a_node_above_it() { +fn a_label_around_a_raw_button_names_the_buttons_node() { use flui_testing::scenario::{Tester, find}; use flui_widgets::{Column, Semantics}; let mut t = Tester::mount(Column::new((Semantics::new() .label("Send") .child(RawButton::new(Text::new("Go")).on_pressed(|_ctx| {})),))); + let button = t.read(&find::button("Send Go")); + assert_eq!( + t.read(&find::text_containing("Send")).id, + button.id, + "no node above the button" + ); + t.finish(); + + let mut t = Tester::mount(Column::new((Semantics::new().label("Send").child( + Column::new(( + Text::new("Draft"), + RawButton::new(Text::new("Go")).on_pressed(|_ctx| {}), + )), + ),))); let button = t.read(&find::button("Go")); - let label = t.read(&find::text("Send")); - assert_ne!(label.id, button.id, "the label is a node above the button"); + let label = t.read(&find::text_containing("Send")); + assert_ne!(label.id, button.id, "a label over more than the button stays above it"); t.finish(); } diff --git a/packages/flui-material/tests/main.rs b/packages/flui-material/tests/main.rs index 9ac73cb0eb..d84840694f 100644 --- a/packages/flui-material/tests/main.rs +++ b/packages/flui-material/tests/main.rs @@ -511,17 +511,13 @@ fn selection_control_contracts() { checkbox::toggles_and_chips_are_one_node_with_their_state, ), ( - "named_by_semantics::a label around a toggle or a tile names the controls own node", - named_by_semantics::a_label_around_a_toggle_or_a_tile_names_the_controls_own_node, + "named_by_semantics::a label around a control names the controls own node", + named_by_semantics::a_label_around_a_control_names_the_controls_own_node, ), ( "named_by_semantics::a toggle keeps its identifier whatever names the node above it", named_by_semantics::a_toggle_keeps_its_identifier_whatever_names_the_node_above_it, ), - ( - "named_by_semantics::a label around a container control is a node above it", - named_by_semantics::a_label_around_a_container_control_is_a_node_above_it, - ), ( "named_by_semantics::a disabled toggle does not join a row that taps", named_by_semantics::a_disabled_toggle_does_not_join_a_row_that_taps, diff --git a/packages/flui-material/tests/named_by_semantics.rs b/packages/flui-material/tests/named_by_semantics.rs index f0842d4fcf..cf4b38826a 100644 --- a/packages/flui-material/tests/named_by_semantics.rs +++ b/packages/flui-material/tests/named_by_semantics.rs @@ -1,7 +1,8 @@ -//! A `Semantics` label around a control names the control's own node, as in Flutter 3.50.1, where -//! a toggle's or a list tile's `Semantics` is no container and joins the annotation above it -//! (ADR-0407). A control whose Flutter counterpart is a container keeps a node of its own beneath -//! the label. A control keeps the identifier its author gave it either way. +//! A `Semantics` label around a control names the control's own node, whatever the control's +//! form (ADR-0407). A toggle's or a list tile's semantics join the annotation above them, as in +//! Flutter 3.50.1; a button's or a chip's node takes the annotation whose only content it is, +//! where Flutter forms the label's node above the button's, with no action on it. A control +//! keeps the identifier its author gave it either way. use std::cell::Cell; use std::rc::Rc; @@ -35,10 +36,10 @@ struct Joins { build: fn(Rc>) -> BoxedView, } -/// Each row finds the node by the label alone: one node, of the control's role, with the -/// identifier, whose tap reaches the control's handler. A disabled toggle joins too, as in -/// Flutter, and the label's node reads as that disabled toggle. -pub fn a_label_around_a_toggle_or_a_tile_names_the_controls_own_node() { +/// Each row finds the node by the label alone: one node, of the control's role, its name read +/// from the label first, with the identifier, whose tap reaches the control's handler. A disabled +/// toggle joins too, as in Flutter, and the label's node reads as that disabled toggle. +pub fn a_label_around_a_control_names_the_controls_own_node() { let rows = [ Joins { control: "Switch", @@ -92,6 +93,40 @@ pub fn a_label_around_a_toggle_or_a_tile_names_the_controls_own_node() { .boxed() }, }, + // Containers in Flutter 3.50.1 (`material/button_style_button.dart:591`, + // `material/button.dart:433`, `material/chip.dart:1503`), where the label would be a node + // above the control. Here it names the control's node, before the name its child gives. + Joins { + control: "ElevatedButton", + role: Role::Button, + enabled: true, + build: |taps| { + ElevatedButton::new(Text::new("Send")) + .on_pressed(move |_ctx| taps.set(taps.get() + 1)) + .boxed() + }, + }, + Joins { + control: "FloatingActionButton", + role: Role::Button, + enabled: true, + build: |taps| { + FloatingActionButton::new() + .child(Text::new("Add")) + .on_pressed(move |_ctx| taps.set(taps.get() + 1)) + .boxed() + }, + }, + Joins { + control: "FilterChip", + role: Role::Button, + enabled: true, + build: |taps| { + FilterChip::new(Text::new("Spicy")) + .on_selected(move |_ctx, _| taps.set(taps.get() + 1)) + .boxed() + }, + }, ]; for row in rows { @@ -107,6 +142,12 @@ pub fn a_label_around_a_toggle_or_a_tile_names_the_controls_own_node() { "{}: the label names the control", row.control ); + assert!( + named.name.as_deref().is_some_and(|name| name.starts_with(LABEL)), + "{}: the label reads first, got {:?}", + row.control, + named.name + ); assert_eq!( named.disabled, !row.enabled, "{}: enabled as the control is", @@ -176,66 +217,6 @@ pub fn a_toggle_keeps_its_identifier_whatever_names_the_node_above_it() { ); } -/// A control whose Flutter counterpart is a container, found by the name its child gives it. -struct Stays { - control: &'static str, - name: &'static str, - build: fn() -> BoxedView, -} - -/// `ButtonStyleButton` (`packages/flutter/lib/src/material/button_style_button.dart:591`), -/// `RawMaterialButton` under the FAB (`material/button.dart:433`) and `RawChip` -/// (`material/chip.dart:1503`) are containers in Flutter 3.50.1: a label around one is a node of -/// its own, and the control keeps the name its child gives it. -pub fn a_label_around_a_container_control_is_a_node_above_it() { - let rows = [ - Stays { - control: "ElevatedButton", - name: "Send", - build: || { - ElevatedButton::new(Text::new("Send")) - .on_pressed(|_ctx| {}) - .boxed() - }, - }, - Stays { - control: "FloatingActionButton", - name: "Add", - build: || { - FloatingActionButton::new() - .child(Text::new("Add")) - .on_pressed(|_ctx| {}) - .boxed() - }, - }, - Stays { - control: "FilterChip", - name: "Spicy", - build: || { - FilterChip::new(Text::new("Spicy")) - .on_selected(|_ctx, _| {}) - .boxed() - }, - }, - ]; - - for row in rows { - let mut t = Tester::mount_in( - labelled(Semantics::new().label(LABEL), (row.build)()), - window(), - ); - let control = t.read(&find::button(row.name)); - let label = t.read(&find::text(LABEL)); - assert_ne!( - label.id, control.id, - "{}: the label is a node above it", - row.control - ); - assert_ne!(label.role, Role::Button, "{}", row.control); - t.finish(); - } -} - /// A disabled toggle inside a tappable row does not join the row's node: folded, the node would /// read as disabled and refuse the row's own tap (ADR-0407 §2). The row keeps its tap, and the /// toggle is a disabled node of its own. From fe7753d493606c1bfb3aaf69eb34f663176d7abc Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 21:19:46 +0000 Subject: [PATCH 10/10] semantics: a Semantics that holds only a control names the control's node, a button's or a chip's too; ADR-0407 lists where it departs from Flutter Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EqfW4FAhVS5dwwxVx5vRGK --- changelog.d/claude-project-thread-f2wym8.md | 13 +- .../src/pipeline/owner/semantics.rs | 11 +- .../tests/semantics_assembly.rs | 2 +- crates/flui-semantics/ARCHITECTURE.md | 6 +- crates/flui-semantics/src/configuration.rs | 10 +- crates/flui-widgets/src/interaction/node.rs | 7 +- crates/flui-widgets/tests/raw_button.rs | 7 +- docs/adr/ADR-0240-semantics-identifier.md | 4 +- ...l-mounts-one-element-for-its-behaviours.md | 5 +- ...trol-takes-the-content-roles-beneath-it.md | 2 +- ...-annotation-names-the-control-it-holds.md} | 176 +++++++++++------- docs/gaps.md | 1 + .../flui-material/tests/named_by_semantics.rs | 9 +- 13 files changed, 152 insertions(+), 101 deletions(-) rename docs/adr/{ADR-0407-a-control-joins-the-semantics-annotation-above-it.md => ADR-0407-an-annotation-names-the-control-it-holds.md} (55%) diff --git a/changelog.d/claude-project-thread-f2wym8.md b/changelog.d/claude-project-thread-f2wym8.md index 806b367683..eebeb81ef8 100644 --- a/changelog.d/claude-project-thread-f2wym8.md +++ b/changelog.d/claude-project-thread-f2wym8.md @@ -1,9 +1,14 @@ ### Changed -- `Semantics::label` around a `Switch`, `Checkbox`, `Radio`, `CupertinoButton` or an enabled - `ListTile` names that control's own node, as in Flutter 3.50.1: their semantics are no longer a - container of their own and join the annotation above them, a disabled toggle included. Buttons, - chips, a chip's delete button and a disabled `ListTile` stay nodes of their own (ADR-0407). +- `Semantics::label` around a control names that control's own node, whatever the control: a + `Switch`, `Checkbox`, `Radio`, `CupertinoButton` or `ListTile` joins the annotation, as in + Flutter 3.50.1, and a button, a chip or a `FloatingActionButton` takes a `Semantics` that holds + nothing else, where Flutter would publish the label as a second node with no action above the + button. The label reads before the control's own text ("Send Go"). A `Semantics` over a control + and other content stays a node above them, and a button or chip stays apart from the content + beside it (ADR-0407). +- A disabled control no longer joins a node that offers a user action of its own: in a tappable + row it keeps its own disabled node, and the row keeps its tap (ADR-0407). - A semantics configuration absorbed into another node gives that node its identifier when the node has none of its own, so a control's `identifier` survives joining the `Semantics` that names it. Outside a `MergeSemantics`, a configuration whose identifier differs from the node diff --git a/crates/flui-rendering/src/pipeline/owner/semantics.rs b/crates/flui-rendering/src/pipeline/owner/semantics.rs index 11e19caa35..8d271579ba 100644 --- a/crates/flui-rendering/src/pipeline/owner/semantics.rs +++ b/crates/flui-rendering/src/pipeline/owner/semantics.rs @@ -896,12 +896,9 @@ fn build_semantics_fragments_impl<'f>( }); } - if let Some(mut control) = sole_control_it_names( - &config, - &decisions, - clipped.hidden, - &mut child_fragments, - ) { + if let Some(mut control) = + sole_control_it_names(&config, &decisions, clipped.hidden, &mut child_fragments) + { // The annotation was the item's root: the position stamped on it is // the control's now. apply_lazy_child_semantic_index( @@ -959,7 +956,7 @@ fn build_semantics_fragments_impl<'f>( /// The control node an annotation names when the control is all it holds: a /// `Semantics` around a button, a chip or a FAB names the control's own node /// instead of forming one above it, as one around a switch does by joining it -/// (ADR-0407 §1). Flutter forms the node above, so a screen reader stops +/// (ADR-0407 §2). Flutter forms the node above, so a screen reader stops /// twice, once on a name with no action and once on the nameless button. /// /// The annotation is none of a boundary, a merge or a part of one, its only diff --git a/crates/flui-rendering/tests/semantics_assembly.rs b/crates/flui-rendering/tests/semantics_assembly.rs index 88a1227f0b..2d20d8bc60 100644 --- a/crates/flui-rendering/tests/semantics_assembly.rs +++ b/crates/flui-rendering/tests/semantics_assembly.rs @@ -1334,7 +1334,7 @@ fn labelled(label: &str) -> SemanticsConfiguration { } /// An annotation whose only content is a control's node names that node -/// (ADR-0407 §1): the control's node takes the annotation's label before its +/// (ADR-0407 §2): the control's node takes the annotation's label before its /// own, and no node forms above it. An annotation over the control and other /// content still forms the node above both. pub(crate) fn an_annotation_around_a_control_alone_names_the_controls_node() { diff --git a/crates/flui-semantics/ARCHITECTURE.md b/crates/flui-semantics/ARCHITECTURE.md index 5e920c8c64..5f77b22c29 100644 --- a/crates/flui-semantics/ARCHITECTURE.md +++ b/crates/flui-semantics/ARCHITECTURE.md @@ -857,7 +857,7 @@ platform (`a_selection_only_annotation_reaches_the_platform`). AccessKit `author_id` and as the wire `Node.identifier`, and never as text. Setting it neither marks the configuration annotated nor makes it a boundary, so a configuration with only an identifier contributes nothing and names no node. `absorb` carries it, first wins -([ADR-0407](../../docs/adr/ADR-0407-a-control-joins-the-semantics-annotation-above-it.md)): a +([ADR-0407](../../docs/adr/ADR-0407-an-annotation-names-the-control-it-holds.md)): a configuration absorbed into an ancestor or a `MergeSemantics` names that node when the node has no identifier of its own, and the receiver keeps its own when it has one. So a control that joins the `Semantics` above it keeps its identifier on the node it joined, as Flutter's @@ -866,7 +866,9 @@ identifier of its own, and the receiver keeps its own when it has one. So a cont outside a merge two different ones are two nodes: `can_absorb` and `can_join` refuse a configuration whose identifier differs from the node's or a sibling's, and it forms a node of its own that keeps its id (Flutter keeps the first and drops the other). A `MergeSemantics` takes -everything, its own identifier or the first merged one. A node AccessKit's filter lifts into its +everything, its own identifier or the first merged one. A control's node that takes the `Semantics` +holding only it (`absorb_enclosing`) reads that annotation first, so its identifier wins there as +its label reads first. A node AccessKit's filter lifts into its parent (no role, label or text, or the `Generic` or `Presentation` role) takes its identifier with it, so no agent or OS automation locator selects it (the web mirror still writes `data-flui-id`). `read_wire` lists a `TreeDiagnostic::UnpublishedIdentifier` for each identifier and node it is diff --git a/crates/flui-semantics/src/configuration.rs b/crates/flui-semantics/src/configuration.rs index 0bcacdf384..43c04b228c 100644 --- a/crates/flui-semantics/src/configuration.rs +++ b/crates/flui-semantics/src/configuration.rs @@ -1628,7 +1628,7 @@ impl SemanticsConfiguration { /// Whether `joining`, a configuration that would be folded into this one's /// node (as a descendant or a sibling), must form a node of its own - /// instead (ADR-0407 §2). Read only for an annotated `joining`: one that + /// instead (ADR-0407 §3). Read only for an annotated `joining`: one that /// says nothing but its identifier contributes nothing and is never /// folded. This configuration is read whether or not it is annotated, /// since an identifier annotates nothing and a container that only names @@ -1801,7 +1801,7 @@ impl SemanticsConfiguration { /// - **Anchors, relations** — union. /// - **Label / hint** — joined with a space. /// - **Identifier** — first wins: the receiver keeps its own and takes the - /// contributor's when it has none (ADR-0407 §2). Two different ones never + /// contributor's when it has none (ADR-0407 §3). Two different ones never /// reach one fold of an ordinary merge, since `can_absorb` and `can_join` /// refuse them; a forced merge keeps the first. /// - **Everything else** — first wins: the receiver keeps what it has. @@ -1815,7 +1815,7 @@ impl SemanticsConfiguration { /// Absorbs `enclosing`, an annotation whose only content is the control /// this configuration forms, so that a `Semantics` around a button names - /// the button's node instead of forming one above it (ADR-0407 §1). + /// the button's node instead of forming one above it (ADR-0407 §2). /// /// The rules are [`absorb`](Self::absorb)'s with `enclosing` read first, /// as it reads above the control: its label and hint come before this @@ -1825,7 +1825,9 @@ impl SemanticsConfiguration { let label = self.attributes.label.take(); let hint = self.attributes.hint.take(); let identifier = self.attributes.identifier.take(); - self.attributes.identifier.clone_from(&enclosing.attributes.identifier); + self.attributes + .identifier + .clone_from(&enclosing.attributes.identifier); self.absorb(enclosing); let append = |target: &mut Option, own: Option| { *target = match (target.take(), own) { diff --git a/crates/flui-widgets/src/interaction/node.rs b/crates/flui-widgets/src/interaction/node.rs index 5fc5608670..9c966fd276 100644 --- a/crates/flui-widgets/src/interaction/node.rs +++ b/crates/flui-widgets/src/interaction/node.rs @@ -115,7 +115,7 @@ enum NodeForm { /// Joins the annotation above it unless its parent asks for explicit /// children: `Semantics` with `container` off. Annotation, - /// A node of its own wherever it is: `Semantics::container(true)`. + /// A node of its own beside other content: `Semantics::container(true)`. Container, /// A node of its own that folds every node beneath it into itself: /// [`MergeSemantics`](crate::MergeSemantics). @@ -138,10 +138,11 @@ impl Description { Self::of(role, NodeForm::Annotation) } - /// A node of `role` of its own wherever the control is, as + /// A node of `role` of its own beside the content around it, as /// `Semantics::container(true)` is: a control whose Flutter counterpart /// is a container (`ButtonStyleButton`, `RawMaterialButton`, `RawChip`). - /// A label around such a control is a node of its own above it. + /// It stays apart from the content beside it, and a `Semantics` that + /// holds only the control still names its node (ADR-0407 §2). #[must_use] pub fn container(role: SemanticsRole) -> Self { Self::of(role, NodeForm::Container) diff --git a/crates/flui-widgets/tests/raw_button.rs b/crates/flui-widgets/tests/raw_button.rs index 02ec15603f..9d9ac35a17 100644 --- a/crates/flui-widgets/tests/raw_button.rs +++ b/crates/flui-widgets/tests/raw_button.rs @@ -1361,7 +1361,7 @@ pub(crate) fn a_listener_panic_under_a_new_hold_leaves_no_hold_behind() { /// `RawButton` is a container, as `RawMaterialButton` is in Flutter 3.50.1 /// (`packages/flutter/lib/src/material/button.dart:433`), so a `Semantics` /// label around it does not join it: the button's node takes the label whose -/// only content it is, read before the name its child gives (ADR-0407 §1). +/// only content it is, read before the name its child gives (ADR-0407 §2). /// A label around the button and something else stays a node above them. #[test] fn a_label_around_a_raw_button_names_the_buttons_node() { @@ -1387,6 +1387,9 @@ fn a_label_around_a_raw_button_names_the_buttons_node() { ),))); let button = t.read(&find::button("Go")); let label = t.read(&find::text_containing("Send")); - assert_ne!(label.id, button.id, "a label over more than the button stays above it"); + assert_ne!( + label.id, button.id, + "a label over more than the button stays above it" + ); t.finish(); } diff --git a/docs/adr/ADR-0240-semantics-identifier.md b/docs/adr/ADR-0240-semantics-identifier.md index 87fd9adfda..71717818f3 100644 --- a/docs/adr/ADR-0240-semantics-identifier.md +++ b/docs/adr/ADR-0240-semantics-identifier.md @@ -4,7 +4,7 @@ - **Date:** 2026-10-17 - **Amended:** 2026-10-21 — §4: an identifier is unique among its siblings, as AccessKit's `author_id` requires; a clash is reported, not repaired. -- **Superseded-by:** [ADR-0407](ADR-0407-a-control-joins-the-semantics-annotation-above-it.md) +- **Superseded-by:** [ADR-0407](ADR-0407-an-annotation-names-the-control-it-holds.md) for an absorbed identifier (§1): it names the node that absorbs it, first wins. - **Related:** [ADR-0238](ADR-0238-flui-driver-protocol.md), [ADR-0203](ADR-0203-semantics-vocabulary.md), @@ -44,7 +44,7 @@ its driver), Compose's `testTag`, Android `resource-id`, iOS `accessibilityIdent 4. An identifier is unique among its siblings by contract, as AccessKit requires of `author_id`: an OS automation client matching it on two siblings finds only one. It need not be unique anywhere else, so a row template can name its "delete" button in every row while the button is - a node of its own. A control that joins its row's node names the row (ADR-0407 §2), so a + a node of its own. A control that joins its row's node names the row (ADR-0407 §3), so a template whose control joins names each row instead, or keeps the control apart. A clash is the author's defect and is reported, never repaired: translation publishes the identifiers as written, debug builds report the clash to the log naming the parent, and a wire read lists a diff --git a/docs/adr/ADR-0322-a-control-mounts-one-element-for-its-behaviours.md b/docs/adr/ADR-0322-a-control-mounts-one-element-for-its-behaviours.md index e6344a4993..d35ea5d251 100644 --- a/docs/adr/ADR-0322-a-control-mounts-one-element-for-its-behaviours.md +++ b/docs/adr/ADR-0322-a-control-mounts-one-element-for-its-behaviours.md @@ -5,7 +5,7 @@ - **Superseded-by:** [ADR-0375](ADR-0375-before-the-first-release-a-pull-request-runs-a-fixed-gate-and-no-api-contract-gate.md) for the facade's public-API snapshot only (Confirmation): the module's absence from the facade is read in the code. -- **Superseded-by:** [ADR-0407](ADR-0407-a-control-joins-the-semantics-annotation-above-it.md) +- **Superseded-by:** [ADR-0407](ADR-0407-an-annotation-names-the-control-it-holds.md) for the node a control's description forms (§6, Accessibility): an annotation unless the control's Flutter counterpart is a container. - **Related:** [ADR-0023](ADR-0023-actions-shortcuts-seam.md) (the action chain a focused node @@ -323,7 +323,8 @@ their own elements, and their private inherited views, `FocusParentProvider` and semantics properties; then the actions the enabled recognizers give (tap, long press, scroll) and the gesture alternatives; then `focusable`, `focused` and `on_focus` from the focus part. The configuration forms the node the control's Flutter counterpart forms: an annotation that joins - the one above it, a container, or a merge (ADR-0407). + the one above it, a container, or a merge, and a `Semantics` that holds only the control names + the control's node whatever its form (ADR-0407). - **Gestures.** The recognizers are the ones `GestureDetector` builds, mounted by the same factories against the same arena scope and settings, entered in the same order on a pointer down. A control inside a `Scrollable` and a control inside another control therefore contest as diff --git a/docs/adr/ADR-0332-a-control-takes-the-content-roles-beneath-it.md b/docs/adr/ADR-0332-a-control-takes-the-content-roles-beneath-it.md index 8c1635c249..2d643af06c 100644 --- a/docs/adr/ADR-0332-a-control-takes-the-content-roles-beneath-it.md +++ b/docs/adr/ADR-0332-a-control-takes-the-content-roles-beneath-it.md @@ -130,7 +130,7 @@ its precedence, in which a control outranks content, so the node keeps the contr content's label and hint concatenate onto the control's in traversal order, which is what names the control. The identifier of absorbed content names the control's node when the control has none, and content named otherwise than its control is refused and forms a node of its own -(ADR-0407 §2); content that must stay a stop of its own forms one with +(ADR-0407 §3); content that must stay a stop of its own forms one with `Semantics::container(true)`. ## Consequences diff --git a/docs/adr/ADR-0407-a-control-joins-the-semantics-annotation-above-it.md b/docs/adr/ADR-0407-an-annotation-names-the-control-it-holds.md similarity index 55% rename from docs/adr/ADR-0407-a-control-joins-the-semantics-annotation-above-it.md rename to docs/adr/ADR-0407-an-annotation-names-the-control-it-holds.md index 9fbe82a646..a03feb7d7a 100644 --- a/docs/adr/ADR-0407-a-control-joins-the-semantics-annotation-above-it.md +++ b/docs/adr/ADR-0407-an-annotation-names-the-control-it-holds.md @@ -1,4 +1,4 @@ -# ADR-0407: A control joins the semantics annotation above it +# ADR-0407: A semantics annotation names the control it holds - **Status:** Accepted (2026-11-30) - **Date:** 2026-11-30 @@ -21,54 +21,65 @@ enabled:)`), and the containers `material/button_style_button.dart:591`, `material/button.dart:433` (`RawMaterialButton`), `material/chip.dart:1503` (`RawChip`), `material/chip.dart:2470` (the delete button's `_RenderEnsureMinSemanticsSize`); - `semantics/semantics.dart:6954` (`absorb` takes the child's identifier when its own is empty) + `semantics/semantics.dart:6954` (`absorb` takes the child's identifier when its own is empty). + The two-stop defect of a label around a Flutter button, as applications record it: + [koniz-dev/flutter-starter#351](https://github.com/koniz-dev/flutter-starter/issues/351), + [flutter/genui#1035](https://github.com/flutter/genui/pull/1035) ## Context and problem statement In Flutter 3.50.1 an application names a switch by wrapping it: `Semantics(label: 'Wi-Fi', child: Switch(...))`. Neither annotation is a container, so the outer one forms the node (its parent asks for explicit children) and the switch's toggled state, -tap and focus join it: one node, a switch named "Wi-Fi". Only `Checkbox` has a `semanticLabel` -of its own, and it is the same `Semantics(label:)` written inside the control. +tap and focus join it: one node, a switch named "Wi-Fi". + +The same wrapper around a button does not work. `ButtonStyleButton`, `RawMaterialButton` and +`RawChip` are containers, so `Semantics(label: 'Send', child: ElevatedButton(...))` publishes a +node "Send" with no action above the button: a screen reader stops twice, and the stop that +carries the name cannot be activated. Applications work around it with `ExcludeSemantics` and a +hand-written button node (the sources above). Flutter's naming builders are uneven as well: +`Checkbox` has a `semanticLabel`, `Switch` and `Radio` have none, and each is the same +`Semantics(label:)` written inside the control. FLUI's controls describe themselves through `InteractiveNode`'s `Description` (ADR-0322 §1), -which built every description as `Semantics::container(true)`. A container always forms its own -node, so the label around a switch formed a second node above it and the switch stayed nameless. -The end-of-test audit refuses a nameless control, so each control would need a label builder of -its own, which Flutter has only on `Checkbox`, and every new control would repeat it. The assembly -already follows Flutter's rule (a configuration that is no boundary is absorbed by the node above it, -and conflicting ones split, ADR-0206); the container flag is what kept a control out of it. +which built every description as `Semantics::container(true)`, so even the switch case formed a +second node and the control stayed nameless. The end-of-test audit refuses a nameless control, so +each control would need a label builder of its own, and every new control would repeat it. A second rule stood in the way: `SemanticsConfiguration::absorb` dropped the identifier of what it absorbed, so a switch that joined the label's node would lose `Switch::identifier`. -Which node does a control's description form, and what does a node keep of what joins it? +Which node does a control's description form, how does an application name any control, and what +does a node keep of what joins it? ## Decision drivers -- What an application writes is Flutter's: `Semantics::label` around a control names it where it - names it in Flutter, and no control grows a naming builder Flutter lacks. -- One rule for every control, held where the node is built, not a builder per widget. -- Nothing else a user observes moves: a button stays a node of its own, a chip and its delete - button stay apart, a disabled list tile does not make its list read as disabled. +- One way to name a control: `Semantics::label` around it names the control's own node, whatever + the control is, and no control has a builder that only sets its name. +- One rule, held where the node is built, not a builder or a flag per widget. +- Where Flutter's tree serves a screen reader, keep it; where it publishes a node a reader stops + on for nothing, or reads one control's state as another's, depart and say why. +- A button keeps its own node beside other content, a chip and its delete button stay apart, a + disabled list tile does not make its list read as disabled. - A control's cost does not rise: no element, render node or allocation, and `Description` stays two words (its size assertion in `interaction/node.rs`); the idle frame allocates nothing. - A locator that selected a control by its identifier still selects it. ## Considered options -1. A description is an annotation unless its Flutter counterpart is a container, and `absorb` - carries an identifier, first wins, while two different identifiers are two nodes. -2. Keep every description a container and give each control a label builder (`semantic_label`, +1. A description forms the node its Flutter counterpart forms, an annotation whose only content + is a control's node joins that node, and `absorb` carries an identifier, first wins, while two + different identifiers are two nodes. +2. Option 1 without the second clause: a label around a button is a node above it, as in Flutter. +3. Keep every description a container and give each control a label builder (`semantic_label`, or a `label` on `Description`). -3. Make every description an annotation, buttons and chips included. -4. Keep containers and let the assembly fold a label annotation into the container directly - beneath it. +4. Make every description an annotation, buttons and chips included. ## Decision -Chosen option: 1, because it is Flutter's rule applied once at the seam every control already -uses, and the only option under which an application's `Semantics` behaves as it does in Flutter. +Chosen option: 1, because it gives every control one way to be named, held at the two seams +every control already goes through (its `Description` and the semantics assembly), and keeps +Flutter's tree wherever that tree serves a screen reader. ### §1 A description forms the node its Flutter counterpart forms @@ -100,25 +111,45 @@ Flutter counterpart: | `Chip`, `FilterChip`, a chip's delete button | container | `material/chip.dart:1503`, `material/chip.dart:2470` | | A `TabBar` tab, a `NavigationBar` destination | merge | `MergeSemantics`, `material/tabs.dart:2108`, `material/navigation_bar.dart:303` | -So `Semantics::new().label("Wi-Fi").child(Switch::new(on))` publishes one switch named "Wi-Fi", -and `Semantics::new().label("Send").child(ElevatedButton::new(Text::new("Go")))` a node "Send" -above a button "Go", as in Flutter. A control that names itself, as `Checkbox::semantic_label` -does, writes the same label inside the control. `Switch` and `Radio` take no label builder. +A container keeps its node apart from the content beside it: a button in a row of text stays a +button. It does not keep it apart from an annotation that holds nothing else. + +### §2 An annotation around a control names the control's node + +`Semantics::label` around a control is the one way an application names it. An annotation +control joins the annotation above it, as in Flutter. A container control's node takes an +annotation whose only content it is (`sole_control_it_names` in `flui-rendering`'s semantics +assembly, `SemanticsConfiguration::absorb_enclosing`), where Flutter forms the annotation's node +above it. So `Semantics::new().label("Wi-Fi").child(Switch::new(on))` publishes one switch named +"Wi-Fi", and `Semantics::new().label("Send").child(ElevatedButton::new(Text::new("Go")))` one +button named "Send Go". + +Either way the node is the control's, and the names read in tree order: the annotation's label and +hint first, then the control's own, joined with a space as every absorbed label is. The annotation +takes part only when it is none of a boundary, a merge, a part of a merge or a node with explicit +children, its only child fragment is a node whose role its content names (a button, a link, a +checkable, a tab, an option), and the two can share a node (`can_absorb`, §3). An annotation over +the control and other content forms or joins the node above both, as before. + +A control has no builder that only sets its name (the ones still on `main` are listed in +[gaps](../gaps.md#accepted-adr-sections-not-built-yet)). A builder that changes what a control +shows (a slider's value indicator, a tab's label) or replaces the name its content gives +(`Disclosure::label`) is not a naming builder. A disabled toggle joins a label too: the label's node reads as that disabled switch, which is what the label names. It does not join a node that offers a user action of its own (a tappable row, an `InkWell`): folded, that node would read as disabled and refuse its own action, so the two stay -apart (§2). The tile's departure is its own, because a tile is a row of content whose +apart (§3). The tile's departure is its own, because a tile is a row of content whose `enabled: false` would otherwise be read as the state of the list holding it; a toggle's node is the toggle. The carousel item and the cupertino tab item sit where their parent asks for explicit children (another item's tap, the tab list's `explicit_child_nodes`), so their two forms publish the same tree; they follow Flutter for the next parent that does not. -Where two annotations cannot share a node (two roles, two handlers for one action, ADR-0206 -decision 4, or two identifiers or a disabled control beside an action, §2), they split as +Where two configurations cannot share a node (two roles, two handlers for one action, ADR-0206 +decision 4, or two identifiers or a disabled control beside an action, §3), they split as before: a switch inside a tappable `ListTile` is a node of its own. -### §2 A node carries one identifier and one enablement for its actions +### §3 A node carries one identifier and one enablement for its actions `SemanticsConfiguration::absorb` keeps the receiver's identifier and takes the absorbed configuration's when the receiver has none, as Flutter's `absorb` does @@ -144,11 +175,12 @@ row's tap included. Flutter merges the two; its merged node is disabled with the A node that is itself disabled still absorbs the actions below it: that is its author declaring the subtree disabled. -### Flutter counterparts +### Where this departs from Flutter | Here | Flutter | Why it differs | |---|---|---| -| `Description::new`, `container`, `merging` | `Semantics(container: false)`, `Semantics(container: true)`, `MergeSemantics` | the same three forms, chosen per control by its Flutter counterpart | +| A label around a button, a chip or a FAB names the control's node | a node with the label and no action above the control's | a screen reader stops on the label, which cannot be activated, then on the control | +| `Semantics::label` is the one way to name a control | `Checkbox.semanticLabel`, none on `Switch` or `Radio` | one path for every control, present and future | | A disabled `ListTile` is a container | `Semantics(enabled: false)` joins the node above | an enclosing list or row would read as disabled | | Two identifiers are two nodes | `absorb` keeps the first, the other is dropped | a control's id is a test's handle on it, and dropping it silently loses the control | | An identifier alone annotates nothing | setting `identifier` sets `hasBeenAnnotated` | ADR-0240 §1: an id added for a test does not change the tree a screen reader reads | @@ -156,36 +188,39 @@ the subtree disabled. ### Consequences -- Good, because a control is named the way Flutter names it, and the testing platform names - `Switch` and `Radio` in its tests by `Semantics::label` with no builder of their own. -- Good, because the rule is the description's, so a control moved onto `InteractiveNode` later - states its form once and inherits the rest. +- Good, because every control is named one way, and a control added later is named by the same + `Semantics::label` with no builder of its own. +- Good, because the rule is the description's and the assembly's, so a control moved onto + `InteractiveNode` later states its form once and inherits the rest. - Good, because nothing is added to a control's element, render node or view: the form replaces - a `bool` in `Description`, and the perf baselines of `flui-widgets`, `flui-material` and - `flui-cupertino` hold unchanged. + a `bool` in `Description`, and the fold reuses the node the control already forms. - Bad, because an annotation joins whatever annotation above it can take it: a toggle inside a `Semantics` that is no container and holds other content folds into that node, as it does in Flutter. An author who wants the toggle apart writes a container around it. +- Bad, because a label around a button that has text of its own adds to its name rather than + replacing it ("Send Go"); an author who wants only the label writes `ExcludeSemantics` around + the button's content. - Bad, because a row template whose control joins its row moves the control's identifier to the - row, where siblings share it (§2). + row, where siblings share it (§3). ### Confirmation +- `flui-rendering`'s `an_annotation_around_a_control_alone_names_the_controls_node`: a label + around a button node names that node, its label first, and a label over a button and text stays + above them; it fails with the fold removed and with the label read after the button's. - `packages/flui-material/tests/named_by_semantics.rs`: - `a_label_around_a_toggle_or_a_tile_names_the_controls_own_node` finds one node by the label - around a `Switch` (enabled and disabled), a `Checkbox`, a `Radio` and an enabled `ListTile`, of - the control's role and enablement, with the identifier, and its tap reaches the control; it fails - with any of them a container. `a_toggle_keeps_its_identifier_whatever_names_the_node_above_it`: - the switch's identifier on the label's node, and its own node under a node named otherwise; it - fails with `absorb` dropping the identifier and with the refusal removed. + `a_label_around_a_control_names_the_controls_own_node` finds one node by the label around a + `Switch` (enabled and disabled), a `Checkbox`, a `Radio`, an enabled `ListTile`, an + `ElevatedButton`, the FAB and a `FilterChip`, of the control's role and enablement, named by the + label first, with the identifier, and its tap reaches the control; it fails with a toggle a + container and with the fold removed. + `a_toggle_keeps_its_identifier_whatever_names_the_node_above_it`: the switch's identifier on + the label's node, and its own node under a node named otherwise; it fails with `absorb` + dropping the identifier and with the refusal removed. `a_disabled_toggle_does_not_join_a_row_that_taps`: a disabled `Switch` in an `InkWell` row keeps its own disabled node and the row its tap; it fails with the refusal removed. - `a_label_around_a_container_control_is_a_node_above_it`: `ElevatedButton`, the FAB and a - `FilterChip` keep their own node and name beneath the label; it fails with the FAB an - annotation. - `flui-cupertino`'s `button::a_label_around_a_button_names_the_buttons_own_node` and - `flui-widgets`' `raw_button::a_label_around_a_raw_button_is_a_node_above_it`, each failing with - the other form. + `flui-widgets`' `raw_button::a_label_around_a_raw_button_names_the_buttons_node`. - `flui-semantics`'s `the_identifier_is_exported_unannounced_no_boundary_and_joins_first_wins` (first wins, two identifiers refused by `can_absorb` and `can_join`, and a disabled control refused by a node with an action while a disabled node still absorbs one) and `flui-rendering`'s @@ -194,31 +229,32 @@ the subtree disabled. - `raw_button_a11y_tree_matches_wrappers` and `ink_well_a11y_tree_matches_wrappers` (ADR-0322) still hold. - `const _: () = assert!(size_of::() <= 16)` in `interaction/node.rs`, and the - `perf` targets of the three crates under `FLUI_PERF_BASELINE=check`. + `perf` targets of `flui-widgets`, `flui-material` and `flui-cupertino` under + `FLUI_PERF_BASELINE=check`. ## Pros and cons of the options -### 1. Annotation unless the counterpart is a container, one identifier per node +### 1. Flutter's forms, an annotation around a control alone joins it, one identifier per node -- Good, because an application's `Semantics` means what it means in Flutter. -- Good, because the choice is one line per control, read against its Flutter counterpart. -- Bad, because the trees of the toggles under a non-container annotation change shape, as they - would have in Flutter. +- Good, because a label names every control the same way, and no control needs a builder for it. +- Good, because the forms are one line per control, read against its Flutter counterpart. +- Bad, because the assembly has a rule Flutter does not, and the trees of a labelled button and + of the toggles under a non-container annotation change shape. -### 2. Containers and a label builder per control +### 2. Flutter's forms only -- Good, because no tree changes shape. -- Bad, because every control grows a builder Flutter does not have, and `Semantics::label` - around a control still leaves it nameless: the duplication this record removes. +- Good, because the tree is Flutter's everywhere. +- Bad, because a label around a button keeps Flutter's two stops, and naming a button takes a + second form (`ExcludeSemantics` and a hand-written node): two ways to name a control. -### 3. Every description an annotation +### 3. Containers and a label builder per control -- Good, because there is no per-control choice. -- Bad, because a label around a button would rename it and a chip would fold into the row that - holds it, where Flutter keeps both apart. +- Good, because no tree changes shape. +- Bad, because every control grows a builder, and `Semantics::label` around a control still + leaves it nameless: the duplication this record removes. -### 4. Fold a label into the container beneath it +### 4. Every description an annotation -- Good, because no description changes. -- Bad, because the assembly gains a rule Flutter does not have, and a container would no longer - mean a node of its own. +- Good, because there is no per-control choice. +- Bad, because a button would fold into the row of text that holds it and a chip into its row, + where a screen reader needs them apart. diff --git a/docs/gaps.md b/docs/gaps.md index 83514dbf28..5a3fe8979c 100644 --- a/docs/gaps.md +++ b/docs/gaps.md @@ -740,6 +740,7 @@ its anchor: update the links and the `GapId` slug in the same pull request. - **ADR-0403 §7.** `flui mcp`'s seven tools are named `flui_windows`, `flui_read`, `flui_locate`, `flui_act`, `flui_wait`, `flui_motion` and `flui_reload`, not for their methods (`crates/flui-cli/src/agent/mcp.rs`). They go when the tool list is generated from the method table, which the flui-driver spec's CLI and MCP task builds (FD17, `docs/plans/specs/flui-driver/tasks.md`); that task also holds the questions about the adapter this record left open. - **ADR-0396 §4–§6.** No nightly run records frame times. `packages/flui-material/benches/app_scenarios.rs`, written for one audit, is still on `main`. The acceptance application's perf scenarios (`tests/perf.rs`) count its start, a page pushed and popped and a toggle, and flui-widgets' `list_10k_` scenarios count a long list's scroll; no counted scenario holds a page of wrapped paragraphs started, scrolled or edited, and nothing records a scenario's wall time. The 36 criterion targets name no question in their headers. - **ADR-0406 §1–§5.** Not built. No `flui_testing::frame::Seam`, `FrameCapture` or `Frame::capture`: a failed step reports the window's outline and its journal and writes no record of the seams below the element tree, and `Frame::draw_list` and `Frame::layers` both read the presented scene, so nothing reads what paint produced apart from what the scene kept. No `Tester::recompute`: no test of a tree compares a frame with the frame its reassemble presents. No kit function holds what a box predicts (intrinsic sizes, dry layout, dry baseline) to its layout. No test above the engine draws a frame: a headless window presents to a sink that draws nothing, `flui_layer::testing` has no `Rasterize` or `Present`, the capture that runs the engine's frame protocol (`RetainedCapture`) is `cfg(test)` in `flui-engine`, `RasterHost` adds a frame's texture damage outside `RasterBase`, `Frame::report` has no `raster` section and `flui-engine` has no `perf` target, so the `Raster` and `Pixels` seams wait for the golden holder of ADR-0400 §6. The tasks are `docs/plans/specs/layer-verification/tasks.md`. +- **ADR-0407 §2.** Controls still have builders that only set their name, beside `Semantics::label`: `Checkbox::semantic_label` (`packages/flui-material/src/checkbox.rs`) and `Slider::label` (`crates/flui-widgets/src/controls/slider.rs`, the assistive name only, where Flutter's `label` is the value indicator's text). The change that removes them moves their users to `Semantics::label`. ### A clip in a node's own content under an ancestor's scale below 1 diff --git a/packages/flui-material/tests/named_by_semantics.rs b/packages/flui-material/tests/named_by_semantics.rs index cf4b38826a..6ca3be2dd3 100644 --- a/packages/flui-material/tests/named_by_semantics.rs +++ b/packages/flui-material/tests/named_by_semantics.rs @@ -143,7 +143,10 @@ pub fn a_label_around_a_control_names_the_controls_own_node() { row.control ); assert!( - named.name.as_deref().is_some_and(|name| name.starts_with(LABEL)), + named + .name + .as_deref() + .is_some_and(|name| name.starts_with(LABEL)), "{}: the label reads first, got {:?}", row.control, named.name @@ -179,7 +182,7 @@ pub fn a_label_around_a_control_names_the_controls_own_node() { } /// A control named by its identifier keeps it when it joins the label's node, which has none of -/// its own; under a node named otherwise it forms its own node and keeps its id (ADR-0407 §2). +/// its own; under a node named otherwise it forms its own node and keeps its id (ADR-0407 §3). pub fn a_toggle_keeps_its_identifier_whatever_names_the_node_above_it() { let toggle = || { Switch::new(false) @@ -218,7 +221,7 @@ pub fn a_toggle_keeps_its_identifier_whatever_names_the_node_above_it() { } /// A disabled toggle inside a tappable row does not join the row's node: folded, the node would -/// read as disabled and refuse the row's own tap (ADR-0407 §2). The row keeps its tap, and the +/// read as disabled and refuse the row's own tap (ADR-0407 §3). The row keeps its tap, and the /// toggle is a disabled node of its own. pub fn a_disabled_toggle_does_not_join_a_row_that_taps() { let taps = Rc::new(Cell::new(0_u32));