Skip to content

a11y(a2ui_flutter): mark Text and Markdown headings as headings in the semantics tree - #3788

Open
karolkulesza wants to merge 35 commits into
a2ui-project:mainfrom
karolkulesza:a11y/flutter-heading-semantics
Open

karolkulesza wants to merge 35 commits into
a2ui-project:mainfrom
karolkulesza:a11y/flutter-heading-semantics

Conversation

@karolkulesza

Copy link
Copy Markdown
Contributor

Description

Flutter counterpart of #3761. The Flutter Text component styles the h1–h5 variants, and a body Text that is one Markdown heading line (## Title), with heading fonts, but the semantics tree doesn't mark them as headings. TalkBack and VoiceOver read them as plain text, and heading navigation finds nothing on an A2UI surface. The web renderer emits <h1>–<h5> for the same variants, and SwiftUI now sets the heading trait and level.

Changes:

  • buildText: the h1–h5 variants and a one-line Markdown heading are wrapped in Semantics(container: true, header: true, headingLevel: n). A Markdown heading keeps its real level, 1 to 6, though ###### still takes the h5 style. Body, caption, multi-line and quote text are unchanged. container: true is needed: without it the heading flag merges into the enclosing node, so in a Card (or a component with an accessibility.label) the body text next to the heading was announced as part of the heading.
  • buildButton: the button is wrapped in MergeSemantics. A Button's child can be any component, and Material buttons only take their name from descendants that aren't semantics containers. Without the merge, a Button whose child is an h2 Text would have an empty name. With it, the button reads "Go", as a button and a level-2 heading. This also gives a name to a Button whose child has its own accessibility.label, which had the same empty-name problem on main.
  • Tests: heading flag and level for each variant and for #, ### and ###### Markdown lines, and no heading for caption, body, plain, #######, multi-line and quote text (leaf_components_test.dart). A heading next to body text in a Card and in a labelled Column keeps the flag to itself. A Button with an h2 child is named "Go" (button_test.dart).
  • CHANGELOG entry under Unreleased.

Text built by an app's own A2uiMarkdown builder is not touched: the app's Markdown widget owns the semantics of its headings.

Testing:

  • flutter test in dart/a2ui_flutter: 407 passed (after merging main). The new Text tests fail without the text.dart change, the Card/labelled-Column test fails without container: true, and the Button test fails without the button.dart change.
  • dart analyze: no issues. dart format: clean.

Part of #2738.

Pre-launch Checklist

One time:

For this PR:

  • I have updated the relevant CHANGELOG.md file.
  • I updated/added relevant documentation. (No docs change: this brings the Flutter renderer in line with the web and SwiftUI ones.)
  • My code changes (if any) have tests.
  • If my branch is on a fork, I have verified that scripts/e2e_test.sh passes.

If you need help, consider asking for advice on the discussion board.

…e semantics tree

The h1-h5 variants and a one-line Markdown heading in a body Text are
wrapped in Semantics(container: true, header: true, headingLevel: n), so
screen readers announce them as headings and can navigate by them, like
the <h1>-<h5> elements on the web and the SwiftUI change in a2ui-project#3761.

The container keeps the heading flag from merging into the texts beside
it in a Card or a labelled component. Button now merges the semantics of
its child, so a heading (or labelled) child still gives the button its
name.
…semantics

# Conflicts:
#	dart/a2ui_flutter/CHANGELOG.md
@github-actions github-actions Bot added the status: needs-triage auto-managed: https://github.com/a2ui-project/a2ui/blob/main/scripts/triage.mjs label Oct 30, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds heading semantics to the Text component for h1-h5 variants and Markdown heading lines, allowing screen readers to navigate them. It also attempts to merge semantics in the Button component. The reviewer feedback points out that merging semantics on Button causes it to incorrectly inherit heading properties, which is an accessibility anti-pattern. The reviewer suggests introducing an ExcludeHeadingSemantics inherited widget to disable heading semantics for children of a Button while still allowing the button to inherit the text label, and provides corresponding updates for the tests and changelog.

Comment thread dart/a2ui_flutter/CHANGELOG.md Resolved
@Varun-S10 Varun-S10 self-assigned this Nov 2, 2026
@Varun-S10

Copy link
Copy Markdown
Collaborator

Hi @karolkulesza, thank you for raising this PR and addressing the review comments. Could you please rebase or merge the latest main branch to resolve the merge conflict in dart/a2ui_flutter/CHANGELOG.md?

@Varun-S10 Varun-S10 added status: waiting-for-author-response and removed status: needs-triage auto-managed: https://github.com/a2ui-project/a2ui/blob/main/scripts/triage.mjs labels Nov 2, 2026
…semantics

# Conflicts:
#	dart/a2ui_flutter/CHANGELOG.md
@karolkulesza

Copy link
Copy Markdown
Contributor Author

Thanks @Varun-S10. I merged the latest main in 08f54db. The conflict was only in dart/a2ui_flutter/CHANGELOG.md, and I kept both main's new entries and the heading entry. flutter analyze is clean and all 413 a2ui_flutter tests pass.

@github-actions github-actions Bot added status: needs-triage auto-managed: https://github.com/a2ui-project/a2ui/blob/main/scripts/triage.mjs and removed status: waiting-for-author-response labels Nov 2, 2026
@Varun-S10

Copy link
Copy Markdown
Collaborator

Hi @karolkulesza, thank you for merging the latest main branch and resolving the conflict. We have verified the updated PR and it resolves the issue cleanly. I will escalate this to the team for review. Thank you for your patience and understanding.
Hi @gspencergoog, could you please take a look?

@Varun-S10 Varun-S10 added status: needs review and removed status: needs-triage auto-managed: https://github.com/a2ui-project/a2ui/blob/main/scripts/triage.mjs labels Nov 3, 2026
@github-actions github-actions Bot added the status: needs-triage auto-managed: https://github.com/a2ui-project/a2ui/blob/main/scripts/triage.mjs label Nov 20, 2026
@polina-c

polina-c commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

From triage bot, analysis:

For humans

TL;DR
Case: this Flutter accessibility change by an external contributor waits for its first team review.
Suggestion: review it and assign andrewkolos.

Summary:
The PR marks the h1 to h5 variants of the Flutter Text component, and body text that is one Markdown heading line, as headings in the semantics tree, so that TalkBack and VoiceOver can navigate by heading. A Button with a heading child keeps its name but is not announced as a heading. It is the Flutter counterpart of the merged SwiftUI change #3761.

Targeted issues:
#2738

Suggestion:
Review the PR and assign andrewkolos, who wrote 2 of the 3 commits to text.dart and to button.dart, and is reviewing the slider accessibility fix #3411. Keep Varun-S10 assigned. Varun-S10 asked gspencergoog to review on 2026-11-03, but no team member has reviewed the PR since. Also add type: feature/enhancement, component: flutter adapter and lang: dart.

The PR meets the review criteria:

  1. It is a small change with tests (193 lines added, 9 removed, in 5 files). It works on #2738 (P3) but does not close it, and that issue is not assigned to the author.
  2. No open PR does the same work. #4280, which migrates a2ui_flutter to material_ui, touches text.dart, button.dart and their tests, and the draft #4120 touches text.dart, both for other reasons, so the second one to land may need a rebase.
  3. The team can maintain it: the PR description says the web renderer already emits <h1> to <h5> for these variants, and SwiftUI sets the heading trait since #3761.

The author addressed the Gemini review: a heading Text inside a Button is no longer marked as a heading (reply). GitHub reports no merge conflict.

  1. Add labels: type: feature/enhancement, component: flutter adapter, lang: dart
  2. Assign: andrewkolos
  3. Related items: a11y(swiftui): mark Text and Markdown headings as accessibility headings #3761, fix(a2ui_flutter): name the slider by its label #3411, feat(a2ui_flutter)!: migrate from flutter/material.dart to material_ui (#3235) #4280, feat(flutter): route media and Markdown URLs through the URL security policy #4120

To adjust the analysis and apply its suggestion, run in your a2ui checkout:

tools/internal/triage/triage_ui.sh https://github.com/a2ui-project/a2ui/pull/3788
For software
<a2ui>
root = TriageAnalysis(
  tldr="""Case: this Flutter accessibility change by an external contributor waits for its first team review.
Suggestion: review it and assign `andrewkolos`.""",
  summary="""The PR marks the `h1` to `h5` variants of the Flutter `Text` component, and body text that is one Markdown heading line, as headings in the semantics tree, so that TalkBack and VoiceOver can navigate by heading. A Button with a heading child keeps its name but is not announced as a heading. It is the Flutter counterpart of the merged SwiftUI change [#3761](https://github.com/a2ui-project/a2ui/pull/3761).""",
  suggestion="""Review the PR and assign `andrewkolos`, who wrote 2 of the 3 commits to [`text.dart`](https://github.com/a2ui-project/a2ui/commits/main/dart/a2ui_flutter/lib/src/catalog/basic/text.dart) and to [`button.dart`](https://github.com/a2ui-project/a2ui/commits/main/dart/a2ui_flutter/lib/src/catalog/basic/button.dart), and is reviewing the slider accessibility fix [#3411](https://github.com/a2ui-project/a2ui/pull/3411). Keep `Varun-S10` assigned. `Varun-S10` [asked](https://github.com/a2ui-project/a2ui/pull/3788#issuecomment-6597159117) `gspencergoog` to review on 2026-11-03, but no team member has reviewed the PR since. Also add `type: feature/enhancement`, `component: flutter adapter` and `lang: dart`.

The PR meets the review criteria:

1. It is a small change with tests (193 lines added, 9 removed, in 5 files). It works on [#2738](https://github.com/a2ui-project/a2ui/issues/2738) (P3) but does not close it, and that issue is not assigned to the author.
2. No open PR does the same work. [#4280](https://github.com/a2ui-project/a2ui/pull/4280), which migrates `a2ui_flutter` to `material_ui`, touches `text.dart`, `button.dart` and their tests, and the draft [#4120](https://github.com/a2ui-project/a2ui/pull/4120) touches `text.dart`, both for other reasons, so the second one to land may need a rebase.
3. The team can maintain it: the PR description says the web renderer already emits `<h1>` to `<h5>` for these variants, and SwiftUI sets the heading trait since [#3761](https://github.com/a2ui-project/a2ui/pull/3761).

The author addressed the Gemini review: a heading Text inside a Button is no longer marked as a heading ([reply](https://github.com/a2ui-project/a2ui/pull/3788#discussion_r4427074524)). GitHub reports no merge conflict.""",
  added_labels=["type: feature/enhancement", "component: flutter adapter", "lang: dart"],
  new_assignees=["andrewkolos"],
  targeted_issues=[2738],
  related_items=[3761, 3411, 4280, 4120]
)
</a2ui>

This analysis is auto-created to help humans to triage this item. Please, do not treat it as a team decision.

🤖 Agent-generated

@polina-c

Copy link
Copy Markdown
Collaborator

Thanks for the change and the tests. Assigning this PR to andrewkolos, who maintains the Flutter Text and Button components, to decide on it.

@polina-c polina-c added component: flutter adapter Affects the Flutter framework adapter lang: dart Affects SDKs or apps in the Dart programming language status: assigned-for-triage issue/pr is assigned to a domain expert for further triage type: feature/enhancement and removed status: needs-triage auto-managed: https://github.com/a2ui-project/a2ui/blob/main/scripts/triage.mjs labels Nov 20, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: flutter adapter Affects the Flutter framework adapter lang: dart Affects SDKs or apps in the Dart programming language status: assigned-for-triage issue/pr is assigned to a domain expert for further triage status: needs review type: feature/enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants