Skip to content

Commit 2fe10df

Browse files
authored
[material_ui] fixes expanded state in the a11y_assessment home page dropdown (flutter#13219)
fixes flutter#194247 ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent 335f424 commit 2fe10df

2 files changed

Lines changed: 114 additions & 1 deletion

File tree

‎packages/material_ui/test_apps/a11y_assessments/lib/main.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class HomePageState extends State<HomePage> {
128128
builder: (BuildContext context, MenuController controller, Widget? child) {
129129
return IconButton(
130130
tooltip: 'Filter by tags',
131-
icon: const Icon(Icons.filter_list),
131+
icon: Semantics(expanded: controller.isOpen, child: const Icon(Icons.filter_list)),
132132
onPressed: () {
133133
if (controller.isOpen) {
134134
controller.close();

‎packages/material_ui/test_apps/a11y_assessments/test/home_page_test.dart‎

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import 'package:a11y_assessments/use_cases/switch_list_tile.dart';
2323
import 'package:a11y_assessments/use_cases/text_button.dart';
2424
import 'package:a11y_assessments/use_cases/text_field.dart';
2525
import 'package:a11y_assessments/use_cases/text_field_password.dart';
26+
import 'package:a11y_assessments/use_cases/use_cases.dart';
2627
import 'package:flutter/services.dart';
2728
import 'package:flutter_test/flutter_test.dart';
2829
import 'package:material_color_utilities/material_color_utilities.dart';
@@ -426,4 +427,116 @@ void main() {
426427
await tester.pumpAndSettle();
427428
expect(findHeadingLevelOnes, findsOne);
428429
});
430+
431+
testWidgets('Filter by tags button has correct expanded/collapsed semantics state', (
432+
WidgetTester tester,
433+
) async {
434+
await tester.pumpWidget(const App());
435+
await tester.pumpAndSettle();
436+
437+
final Finder filterButton = find.byTooltip('Filter by tags');
438+
expect(
439+
tester.getSemantics(filterButton),
440+
matchesSemantics(
441+
isButton: true,
442+
hasEnabledState: true,
443+
isEnabled: true,
444+
hasExpandedState: true,
445+
isFocusable: true,
446+
hasTapAction: true,
447+
hasFocusAction: true,
448+
tooltip: 'Filter by tags',
449+
),
450+
);
451+
452+
// Open the filter menu.
453+
await tester.tap(filterButton);
454+
await tester.pumpAndSettle();
455+
456+
expect(
457+
tester.getSemantics(filterButton),
458+
matchesSemantics(
459+
isButton: true,
460+
hasEnabledState: true,
461+
isEnabled: true,
462+
hasExpandedState: true,
463+
isExpanded: true,
464+
isFocusable: true,
465+
hasTapAction: true,
466+
hasFocusAction: true,
467+
tooltip: 'Filter by tags',
468+
),
469+
);
470+
471+
// Toggling a tag keeps the menu open and the button expanded.
472+
await tester.tap(find.text(Tag.batch1.name));
473+
await tester.pumpAndSettle();
474+
475+
expect(
476+
tester.getSemantics(filterButton),
477+
matchesSemantics(
478+
isButton: true,
479+
hasEnabledState: true,
480+
isEnabled: true,
481+
hasExpandedState: true,
482+
isExpanded: true,
483+
isFocusable: true,
484+
hasTapAction: true,
485+
hasFocusAction: true,
486+
tooltip: 'Filter by tags',
487+
),
488+
);
489+
490+
// Close the filter menu by tapping the button again.
491+
await tester.tap(filterButton);
492+
await tester.pumpAndSettle();
493+
494+
expect(
495+
tester.getSemantics(filterButton),
496+
matchesSemantics(
497+
isButton: true,
498+
hasEnabledState: true,
499+
isEnabled: true,
500+
hasExpandedState: true,
501+
isFocusable: true,
502+
hasTapAction: true,
503+
hasFocusAction: true,
504+
tooltip: 'Filter by tags',
505+
),
506+
);
507+
508+
// Reopen and close by tapping outside the menu.
509+
await tester.tap(filterButton);
510+
await tester.pumpAndSettle();
511+
expect(
512+
tester.getSemantics(filterButton),
513+
matchesSemantics(
514+
isButton: true,
515+
hasEnabledState: true,
516+
isEnabled: true,
517+
hasExpandedState: true,
518+
isExpanded: true,
519+
isFocusable: true,
520+
hasTapAction: true,
521+
hasFocusAction: true,
522+
tooltip: 'Filter by tags',
523+
),
524+
);
525+
526+
await tester.tapAt(Offset.zero);
527+
await tester.pumpAndSettle();
528+
expect(
529+
tester.getSemantics(filterButton),
530+
matchesSemantics(
531+
isButton: true,
532+
hasEnabledState: true,
533+
isEnabled: true,
534+
hasExpandedState: true,
535+
isFocusable: true,
536+
hasTapAction: true,
537+
hasFocusAction: true,
538+
tooltip: 'Filter by tags',
539+
),
540+
);
541+
});
429542
}

0 commit comments

Comments
 (0)