diff --git a/packages/flutter/lib/src/material/dropdown.dart b/packages/flutter/lib/src/material/dropdown.dart index c2abe0d859..1f4a5e35fa 100644 --- a/packages/flutter/lib/src/material/dropdown.dart +++ b/packages/flutter/lib/src/material/dropdown.dart @@ -785,9 +785,12 @@ class _DropdownMenuItemContainer extends StatelessWidget { @override Widget build(BuildContext context) { - return ConstrainedBox( - constraints: const BoxConstraints(minHeight: _kMenuItemHeight), - child: Align(alignment: alignment, child: child), + return Semantics( + button: true, + child: ConstrainedBox( + constraints: const BoxConstraints(minHeight: _kMenuItemHeight), + child: Align(alignment: alignment, child: child), + ), ); } } @@ -1583,9 +1586,9 @@ class _DropdownButtonState extends State> with WidgetsBindi child: result, ); } - + final bool childHasButtonSemantic = hintIndex != null || (_selectedIndex != null && widget.selectedItemBuilder == null); return Semantics( - button: true, + button: !childHasButtonSemantic, child: Actions( actions: _actionMap, child: InkWell( diff --git a/packages/flutter/test/material/dropdown_test.dart b/packages/flutter/test/material/dropdown_test.dart index c04ae2b1aa..135ef2dda6 100644 --- a/packages/flutter/test/material/dropdown_test.dart +++ b/packages/flutter/test/material/dropdown_test.dart @@ -1296,7 +1296,7 @@ void main() { )); // By default the hint contributes the label. - expect(tester.getSemantics(find.byKey(key)), matchesSemantics( + expect(tester.getSemantics(find.text('test')), matchesSemantics( isButton: true, label: 'test', hasTapAction: true, @@ -1311,8 +1311,8 @@ void main() { hint: const Text('test'), )); - // Displays label of select item and is no longer tappable. - expect(tester.getSemantics(find.byKey(key)), matchesSemantics( + // Displays label of select item. + expect(tester.getSemantics(find.text('three')), matchesSemantics( isButton: true, label: 'three', hasTapAction: true, @@ -1358,6 +1358,7 @@ void main() { label: 'one', textDirection: TextDirection.ltr, flags: [ + SemanticsFlag.isButton, SemanticsFlag.isFocused, SemanticsFlag.isFocusable, ], @@ -1367,21 +1368,30 @@ void main() { TestSemantics( label: 'two', textDirection: TextDirection.ltr, - flags: [SemanticsFlag.isFocusable], + flags: [ + SemanticsFlag.isButton, + SemanticsFlag.isFocusable, + ], tags: [const SemanticsTag('RenderViewport.twoPane')], actions: [SemanticsAction.tap, SemanticsAction.focus], ), TestSemantics( label: 'three', textDirection: TextDirection.ltr, - flags: [SemanticsFlag.isFocusable], + flags: [ + SemanticsFlag.isButton, + SemanticsFlag.isFocusable, + ], tags: [const SemanticsTag('RenderViewport.twoPane')], actions: [SemanticsAction.tap, SemanticsAction.focus], ), TestSemantics( label: 'four', textDirection: TextDirection.ltr, - flags: [SemanticsFlag.isFocusable], + flags: [ + SemanticsFlag.isButton, + SemanticsFlag.isFocusable, + ], tags: [const SemanticsTag('RenderViewport.twoPane')], actions: [SemanticsAction.tap, SemanticsAction.focus], ),