Unverified Commit f134f039 authored by Viren Khatri's avatar Viren Khatri Committed by GitHub

added autofocus and test (#87591)

parent d841dd40
......@@ -151,6 +151,7 @@ class CupertinoSearchTextField extends StatefulWidget {
this.onSuffixTap,
this.restorationId,
this.focusNode,
this.autofocus = false,
this.onTap,
this.autocorrect = true,
this.enabled,
......@@ -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;
......@@ -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,
);
......
......@@ -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);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment