Detect text contrast violations when the semantics label differs from the rendered text#188024
Detect text contrast violations when the semantics label differs from the rendered text#188024manan-tech wants to merge 2 commits into
Conversation
… the rendered text MinimumTextContrastGuideline located the Text/EditableText widget to measure by string-matching the semantics node's label against the rendered text (find.text(label)). When a Semantics widget contributes a label that merges with a descendant Text, or when Text.semanticsLabel is set, no Text widget has that exact string, so the widget was never found and the contrast check was silently skipped -- for example white text on a white background went undetected. Locate the text-bearing widgets by inspecting the widget tree and matching render geometry to each semantics node instead, deduplicating per view so each widget is checked once. Fixes flutter#180081
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request modifies MinimumTextContrastGuideline to locate text-bearing widgets by directly querying the widget tree for Text and EditableText elements, rather than matching semantics labels or values. This change ensures contrast checks are performed even when semantics labels differ from the visible text. Additionally, it tracks evaluated elements to avoid duplicate checks and introduces corresponding regression tests. There are no review comments, and I have no feedback to provide.
Description
MinimumTextContrastGuideline(thetextContrastGuidelineused bymeetsGuideline) located theText/EditableTextwidget to measure by string-matching the semantics node's label against the rendered text (find.text(data.label)).When a
Semanticswidget contributes a label that merges with a descendantText(e.g.Semantics(label: 'A', child: Text('B'))produces the merged label"A\nB"), or whenText.semanticsLabelis set, noTextwidget has that exact string.find.texttherefore returned nothing and the contrast check was silently skipped, so genuine violations such as white text on a white background went undetected.This locates the text-bearing widgets by inspecting the widget tree and matching render geometry to each semantics node, instead of matching label strings. Results are de-duplicated per view so each widget is evaluated once, against the deepest semantics node it belongs to.
Related Issues
Fixes #180081
Tests
Adds 3 regression tests to
packages/flutter_test/test/accessibility_test.dart:Semanticslabel that merges with a childText(white-on-white is now detected),Text.semanticsLabeldiffering from the visible text (now detected),Note for reviewers
Because the guideline now checks text it previously skipped, it surfaces some pre-existing contrast problems in the dev sample apps (
dev/a11y_assessments,dev/integration_tests/flutter_gallery) — for example aBadgewith white text onColors.green, and tab labels drawn in the same color as aprimary-colored app bar. These are genuine accessibility issues in those sample apps rather than regressions introduced here, and are best fixed separately.