From 7319acf575cfdbcc4692a7a92627646d8a401809 Mon Sep 17 00:00:00 2001 From: Nolan Scobie Date: Tue, 23 Jun 2020 19:02:54 -0400 Subject: [PATCH 1/2] Tweaking Material Chip a11y semantics to match buttons --- packages/flutter/lib/src/material/chip.dart | 3 +- packages/flutter/test/material/chip_test.dart | 152 +++++++++++++++++- 2 files changed, 152 insertions(+), 3 deletions(-) diff --git a/packages/flutter/lib/src/material/chip.dart b/packages/flutter/lib/src/material/chip.dart index d31a6ab63d71d..bfd74e5ee4edf 100644 --- a/packages/flutter/lib/src/material/chip.dart +++ b/packages/flutter/lib/src/material/chip.dart @@ -1944,9 +1944,10 @@ class _RawChipState extends State with TickerProviderStateMixin[ + SemanticsFlag.hasEnabledState, + SemanticsFlag.isButton, + ], ), ], ), @@ -1662,6 +1666,10 @@ void main() { TestSemantics( label: 'test', textDirection: TextDirection.ltr, + flags: [ + SemanticsFlag.hasEnabledState, + SemanticsFlag.isButton, + ], children: [ TestSemantics( label: 'Delete', @@ -1712,6 +1720,7 @@ void main() { textDirection: TextDirection.ltr, flags: [ SemanticsFlag.hasEnabledState, + SemanticsFlag.isButton, SemanticsFlag.isEnabled, SemanticsFlag.isFocusable, ], @@ -1763,6 +1772,7 @@ void main() { textDirection: TextDirection.ltr, flags: [ SemanticsFlag.hasEnabledState, + SemanticsFlag.isButton, SemanticsFlag.isEnabled, SemanticsFlag.isFocusable, ], @@ -1808,6 +1818,7 @@ void main() { textDirection: TextDirection.ltr, flags: [ SemanticsFlag.hasEnabledState, + SemanticsFlag.isButton, SemanticsFlag.isEnabled, SemanticsFlag.isFocusable, SemanticsFlag.isSelected, @@ -1853,7 +1864,51 @@ void main() { TestSemantics( label: 'test', textDirection: TextDirection.ltr, - flags: [], + flags: [ + SemanticsFlag.hasEnabledState, + SemanticsFlag.isButton, + ], + actions: [], + ), + ], + ), + ], + ), + ], + ), + ], + ), ignoreTransform: true, ignoreId: true, ignoreRect: true)); + + semanticsTester.dispose(); + }); + + testWidgets('tapEnabled explicitly false', (WidgetTester tester) async { + final SemanticsTester semanticsTester = SemanticsTester(tester); + + await tester.pumpWidget(const MaterialApp( + home: Material( + child: RawChip( + tapEnabled: false, + label: Text('test'), + ), + ), + )); + + expect(semanticsTester, hasSemantics( + TestSemantics.root( + children: [ + TestSemantics( + textDirection: TextDirection.ltr, + children: [ + TestSemantics( + children: [ + TestSemantics( + flags: [SemanticsFlag.scopesRoute], + children: [ + TestSemantics( + label: 'test', + textDirection: TextDirection.ltr, + flags: [], // Must not be a button when tapping is disabled. actions: [], ), ], @@ -1867,6 +1922,99 @@ void main() { semanticsTester.dispose(); }); + + testWidgets('enabled when tapEnabled and canTap', (WidgetTester tester) async { + final SemanticsTester semanticsTester = SemanticsTester(tester); + + // These settings make a Chip which can be tapped, both in general and at this moment. + await tester.pumpWidget(MaterialApp( + home: Material( + child: RawChip( + isEnabled: true, + tapEnabled: true, + onPressed: () {}, + label: const Text('test'), + ), + ), + )); + + expect(semanticsTester, hasSemantics( + TestSemantics.root( + children: [ + TestSemantics( + textDirection: TextDirection.ltr, + children: [ + TestSemantics( + children: [ + TestSemantics( + flags: [SemanticsFlag.scopesRoute], + children: [ + TestSemantics( + label: 'test', + textDirection: TextDirection.ltr, + flags: [ + SemanticsFlag.hasEnabledState, + SemanticsFlag.isButton, + SemanticsFlag.isEnabled, + SemanticsFlag.isFocusable, + ], + actions: [SemanticsAction.tap], + ), + ], + ), + ], + ), + ], + ), + ], + ), ignoreTransform: true, ignoreId: true, ignoreRect: true)); + + semanticsTester.dispose(); + }); + + testWidgets('disabled when tapEnabled but not canTap', (WidgetTester tester) async { + final SemanticsTester semanticsTester = SemanticsTester(tester); + // These settings make a Chip which _could_ be tapped, but not currently (ensures `canTap == false`). + await tester.pumpWidget(const MaterialApp( + home: Material( + child: RawChip( + isEnabled: true, + tapEnabled: true, + label: Text('test'), + ), + ), + )); + + expect(semanticsTester, hasSemantics( + TestSemantics.root( + children: [ + TestSemantics( + textDirection: TextDirection.ltr, + children: [ + TestSemantics( + children: [ + TestSemantics( + flags: [SemanticsFlag.scopesRoute], + children: [ + TestSemantics( + label: 'test', + textDirection: TextDirection.ltr, + flags: [ + SemanticsFlag.hasEnabledState, + SemanticsFlag.isButton, + ], + ), + ], + ), + ], + ), + ], + ), + ], + ), ignoreTransform: true, ignoreId: true, ignoreRect: true)); + + semanticsTester.dispose(); + }); }); testWidgets('can be tapped outside of chip delete icon', (WidgetTester tester) async { @@ -2547,4 +2695,4 @@ void main() { const Color(0xffff0000), ); }); -} +} \ No newline at end of file From 207e952be71fc57ffddc3f874d8078f48514b1f0 Mon Sep 17 00:00:00 2001 From: Nolan Scobie Date: Fri, 26 Jun 2020 12:52:27 -0400 Subject: [PATCH 2/2] added a newline to the end of chip_test.dart --- packages/flutter/test/material/chip_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/flutter/test/material/chip_test.dart b/packages/flutter/test/material/chip_test.dart index 04eb385dc2494..a33052ddf7623 100644 --- a/packages/flutter/test/material/chip_test.dart +++ b/packages/flutter/test/material/chip_test.dart @@ -2695,4 +2695,4 @@ void main() { const Color(0xffff0000), ); }); -} \ No newline at end of file +}