Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added autofocus property to CupertinoSearchTextField #87591

Merged
merged 1 commit into from Aug 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/flutter/lib/src/cupertino/search_field.dart
Expand Up @@ -151,6 +151,7 @@ class CupertinoSearchTextField extends StatefulWidget {
this.onSuffixTap,
this.restorationId,
this.focusNode,
this.autofocus = false,
this.onTap,
this.autocorrect = true,
this.enabled,
Expand Down Expand Up @@ -287,6 +288,9 @@ class CupertinoSearchTextField extends StatefulWidget {
/// {@macro flutter.widgets.Focus.focusNode}
final FocusNode? focusNode;

/// {@macro flutter.widgets.editableText.autofocus}
final bool autofocus;

/// {@macro flutter.material.textfield.onTap}
final VoidCallback? onTap;

Expand Down Expand Up @@ -429,6 +433,7 @@ class _CupertinoSearchTextFieldState extends State<CupertinoSearchTextField>
onChanged: widget.onChanged,
onSubmitted: widget.onSubmitted,
focusNode: widget.focusNode,
autofocus: widget.autofocus,
autocorrect: widget.autocorrect,
textInputAction: TextInputAction.search,
);
Expand Down
16 changes: 16 additions & 0 deletions packages/flutter/test/cupertino/search_field_test.dart
Expand Up @@ -562,4 +562,20 @@ void main() {
final CupertinoTextField textField = tester.widget(find.byType(CupertinoTextField));
expect(textField.textInputAction, TextInputAction.search);
});

testWidgets('autofocus:true gives focus to the widget', (WidgetTester tester) async {
final FocusNode focusNode = FocusNode();
await tester.pumpWidget(
CupertinoApp(
home: Center(
child: CupertinoSearchTextField(
focusNode: focusNode,
autofocus: true,
),
),
),
);

expect(focusNode.hasFocus, isTrue);
});
}