diff --git a/packages/flutter/lib/src/cupertino/text_field.dart b/packages/flutter/lib/src/cupertino/text_field.dart index 9969535c4c..ffb6ade658 100644 --- a/packages/flutter/lib/src/cupertino/text_field.dart +++ b/packages/flutter/lib/src/cupertino/text_field.dart @@ -929,7 +929,8 @@ class _CupertinoTextFieldState extends State with AutomaticK ); return Semantics( - onTap: () { + enabled: enabled, + onTap: !enabled ? null : () { if (!controller.selection.isValid) { controller.selection = TextSelection.collapsed(offset: controller.text.length); } diff --git a/packages/flutter/test/cupertino/text_field_test.dart b/packages/flutter/test/cupertino/text_field_test.dart index f9abd3df7c..ce9ea76ec9 100644 --- a/packages/flutter/test/cupertino/text_field_test.dart +++ b/packages/flutter/test/cupertino/text_field_test.dart @@ -3944,4 +3944,61 @@ void main() { await tester.pump(); expect(focusNode3.hasPrimaryFocus, isTrue); }); + + testWidgets('Cupertino text field semantics', (WidgetTester tester) async { + await tester.pumpWidget( + CupertinoApp( + home: Center( + child: ConstrainedBox( + constraints: BoxConstraints.loose(const Size(200, 200)), + child: const CupertinoTextField(), + ), + ), + ), + ); + + expect( + tester.getSemantics( + find.descendant( + of: find.byType(CupertinoTextField), + matching: find.byType(Semantics), + ).first, + ), + matchesSemantics( + isTextField: true, + isEnabled: true, + hasEnabledState: true, + hasTapAction: true, + ), + ); + }); + + testWidgets('Disabled Cupertino text field semantics', (WidgetTester tester) async { + await tester.pumpWidget( + CupertinoApp( + home: Center( + child: ConstrainedBox( + constraints: BoxConstraints.loose(const Size(200, 200)), + child: const CupertinoTextField( + enabled: false, + ), + ), + ), + ), + ); + + expect( + tester.getSemantics( + find.descendant( + of: find.byType(CupertinoTextField), + matching: find.byType(Semantics), + ).first, + ), + matchesSemantics( + isEnabled: false, + hasEnabledState: true, + hasTapAction: false, + ), + ); + }); }