diff --git a/packages/flutter/lib/src/material/autocomplete.dart b/packages/flutter/lib/src/material/autocomplete.dart index 77d11a9c765..584b71321fb 100644 --- a/packages/flutter/lib/src/material/autocomplete.dart +++ b/packages/flutter/lib/src/material/autocomplete.dart @@ -291,20 +291,23 @@ class _AutocompleteOptionsListState extends State<_Autocomplet itemCount: widget.options.length, itemBuilder: (BuildContext context, int index) { final T option = widget.options.elementAt(index); - return InkWell( - key: GlobalObjectKey(option), - onTap: () { - widget.onSelected(option); - }, - child: Builder( - builder: (BuildContext context) { - final bool highlight = highlightedIndex == index; - return Container( - color: highlight ? Theme.of(context).focusColor : null, - padding: const EdgeInsets.all(16.0), - child: Text(widget.displayStringForOption(option)), - ); + return Semantics( + button: true, + child: InkWell( + key: GlobalObjectKey(option), + onTap: () { + widget.onSelected(option); }, + child: Builder( + builder: (BuildContext context) { + final bool highlight = highlightedIndex == index; + return Container( + color: highlight ? Theme.of(context).focusColor : null, + padding: const EdgeInsets.all(16.0), + child: Text(widget.displayStringForOption(option)), + ); + }, + ), ), ); }, diff --git a/packages/flutter/test/material/autocomplete_test.dart b/packages/flutter/test/material/autocomplete_test.dart index f00f91b1599..d7776dc3405 100644 --- a/packages/flutter/test/material/autocomplete_test.dart +++ b/packages/flutter/test/material/autocomplete_test.dart @@ -730,4 +730,36 @@ void main() { final TextField field2 = find.byType(TextField).evaluate().first.widget as TextField; expect(field2.controller!.text, textSelection); }); + + testWidgets('autocomplete options have button semantics', (WidgetTester tester) async { + const Color highlightColor = Color(0xFF112233); + await tester.pumpWidget( + MaterialApp( + theme: ThemeData(focusColor: highlightColor), + home: Scaffold( + body: Autocomplete( + optionsBuilder: (TextEditingValue textEditingValue) { + return kOptions.where((String option) { + return option.contains(textEditingValue.text.toLowerCase()); + }); + }, + ), + ), + ), + ); + await tester.tap(find.byType(TextField)); + await tester.pump(); + await tester.enterText(find.byType(TextField), 'aa'); + await tester.pump(); + expect( + tester.getSemantics(find.text('aardvark')), + matchesSemantics( + isButton: true, + isFocusable: true, + hasTapAction: true, + hasFocusAction: true, + label: 'aardvark', + ), + ); + }); }