fix(button): excludeSemantics so semanticLabel replaces child text (a11y)#50
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Button:
semanticLabelnow truly replaces the child's semanticsButtonwrapped its content inSemantics(button: true, enabled:, label: semanticLabel, child: …)withoutexcludeSemantics: true. Its doc-comment promisessemanticLabel"replaces the child's semantics (likearia-label)" — but verified empirically (semantics-tree inspection) that with a text child the child's text merges with the label, so a screen reader announces both ("override" and the button's own text). This surfaced while shippingBadge(PR #49), which had the identical pattern and was fixed there.Verify-first (the spawned task asked for it)
A new RED test
Button(semanticLabel: 'override', child: Text('VISIBLE_CHILD'))confirmed the leak:find.bySemanticsLabel('override')found 0 nodes because the node's label was the merged"override\nVISIBLE_CHILD".The fix is conditional (not Badge's unconditional one)
Unlike Badge — which only wraps in
SemanticswhensemanticLabel != null—Buttonalways wraps (it needs thebutton:/enabled:flags). With nosemanticLabel, the child text must remain the button's accessible name. So:semanticLabel→ exclude the child so the label is the sole name (replaces). ✓getSemantics(find.text('Save'))still reportsisButton). ✓Tests (TDD)
semanticLabel replaces a TEXT child label (no double-announce)— was RED, now GREEN.without semanticLabel, the child text IS the accessible name— guards the no-override path (passed before and after; locks the conditional).flutter analyze --fatal-infos --fatal-warningsclean;dart formatclean.This makes the existing doc-comment's "replaces" guarantee true in all cases (it previously held only for icon-only buttons, where there's no child text to leak). Spawned from the Badge PR as a focused a11y-correctness follow-up.
🤖 Generated with Claude Code
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com