From 2b72e9cf348fddba39f06c50d005a5dd1c8564d2 Mon Sep 17 00:00:00 2001 From: Hannah Jin Date: Wed, 23 Jul 2025 16:56:47 -0700 Subject: [PATCH] [Web][a11y] Update selected chips semantics (#172660) internal: b/430166300 ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [ ] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --- packages/flutter/lib/src/material/chip.dart | 10 ++++-- packages/flutter/test/material/chip_test.dart | 36 +++++++++++++------ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/packages/flutter/lib/src/material/chip.dart b/packages/flutter/lib/src/material/chip.dart index 043b8d62e65..ff2149e8003 100644 --- a/packages/flutter/lib/src/material/chip.dart +++ b/packages/flutter/lib/src/material/chip.dart @@ -13,7 +13,7 @@ library; import 'dart:math' as math; -import 'package:flutter/foundation.dart' show clampDouble; +import 'package:flutter/foundation.dart' show clampDouble, kIsWeb; import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; @@ -1502,7 +1502,13 @@ class _RawChipState extends State with TickerProviderStateMixin[ - SemanticsFlag.hasSelectedState, + if (kIsWeb) SemanticsFlag.hasCheckedState, + if (!kIsWeb) SemanticsFlag.hasSelectedState, SemanticsFlag.hasEnabledState, SemanticsFlag.isButton, ], @@ -2868,7 +2869,8 @@ void main() { label: 'test', textDirection: TextDirection.ltr, flags: [ - SemanticsFlag.hasSelectedState, + if (kIsWeb) SemanticsFlag.hasCheckedState, + if (!kIsWeb) SemanticsFlag.hasSelectedState, SemanticsFlag.hasEnabledState, SemanticsFlag.isButton, ], @@ -2931,7 +2933,8 @@ void main() { label: 'test', textDirection: TextDirection.ltr, flags: [ - SemanticsFlag.hasSelectedState, + if (kIsWeb) SemanticsFlag.hasCheckedState, + if (!kIsWeb) SemanticsFlag.hasSelectedState, SemanticsFlag.hasEnabledState, SemanticsFlag.isButton, SemanticsFlag.isEnabled, @@ -2991,7 +2994,8 @@ void main() { label: 'test', textDirection: TextDirection.ltr, flags: [ - SemanticsFlag.hasSelectedState, + if (kIsWeb) SemanticsFlag.hasCheckedState, + if (!kIsWeb) SemanticsFlag.hasSelectedState, SemanticsFlag.hasEnabledState, SemanticsFlag.isButton, SemanticsFlag.isEnabled, @@ -3050,8 +3054,14 @@ void main() { SemanticsFlag.isButton, SemanticsFlag.isEnabled, SemanticsFlag.isFocusable, - SemanticsFlag.hasSelectedState, - SemanticsFlag.isSelected, + if (kIsWeb) ...[ + SemanticsFlag.hasCheckedState, + SemanticsFlag.isChecked, + ], + if (!kIsWeb) ...[ + SemanticsFlag.hasSelectedState, + SemanticsFlag.isSelected, + ], ], actions: [SemanticsAction.tap, SemanticsAction.focus], ), @@ -3100,7 +3110,8 @@ void main() { label: 'test', textDirection: TextDirection.ltr, flags: [ - SemanticsFlag.hasSelectedState, + if (kIsWeb) SemanticsFlag.hasCheckedState, + if (!kIsWeb) SemanticsFlag.hasSelectedState, SemanticsFlag.hasEnabledState, SemanticsFlag.isButton, ], @@ -3149,7 +3160,10 @@ void main() { label: 'test', textDirection: TextDirection.ltr, // Must not be a button when tapping is disabled. - flags: [SemanticsFlag.hasSelectedState], + flags: [ + if (kIsWeb) SemanticsFlag.hasCheckedState, + if (!kIsWeb) SemanticsFlag.hasSelectedState, + ], actions: [], ), ], @@ -3198,7 +3212,8 @@ void main() { label: 'test', textDirection: TextDirection.ltr, flags: [ - SemanticsFlag.hasSelectedState, + if (kIsWeb) SemanticsFlag.hasCheckedState, + if (!kIsWeb) SemanticsFlag.hasSelectedState, SemanticsFlag.hasEnabledState, SemanticsFlag.isButton, SemanticsFlag.isEnabled, @@ -3249,7 +3264,8 @@ void main() { label: 'test', textDirection: TextDirection.ltr, flags: [ - SemanticsFlag.hasSelectedState, + if (kIsWeb) SemanticsFlag.hasCheckedState, + if (!kIsWeb) SemanticsFlag.hasSelectedState, SemanticsFlag.hasEnabledState, SemanticsFlag.isButton, ],