Unverified Commit dd41f41f authored by xubaolin's avatar xubaolin Committed by GitHub

CupertinoTextField should not accept requestFocus when disabled (#65235)

parent 408cd71d
......@@ -653,6 +653,7 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with Restoratio
if (widget.controller == null) {
_createLocalController();
}
_effectiveFocusNode.canRequestFocus = widget.enabled ?? true;
}
@override
......@@ -665,11 +666,7 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with Restoratio
_controller!.dispose();
_controller = null;
}
final bool isEnabled = widget.enabled ?? true;
final bool wasEnabled = oldWidget.enabled ?? true;
if (wasEnabled && !isEnabled) {
_effectiveFocusNode.unfocus();
}
_effectiveFocusNode.canRequestFocus = widget.enabled ?? true;
}
@override
......
......@@ -2707,6 +2707,43 @@ void main() {
expect(tapCount, 1);
});
testWidgets('Focus test when the text field is disabled', (WidgetTester tester) async {
final FocusNode focusNode = FocusNode();
await tester.pumpWidget(
CupertinoApp(
home: Center(
child: CupertinoTextField(
focusNode: focusNode,
),
),
),
);
expect(focusNode.hasFocus, false); // initial status
// Should accept requestFocus.
focusNode.requestFocus();
await tester.pump();
expect(focusNode.hasFocus, true);
// Disable the text field, now it should not accept requestFocus.
await tester.pumpWidget(
CupertinoApp(
home: Center(
child: CupertinoTextField(
enabled: false,
focusNode: focusNode,
),
),
),
);
// Should not accept requestFocus.
focusNode.requestFocus();
await tester.pump();
expect(focusNode.hasFocus, false);
});
testWidgets(
'text field respects theme',
(WidgetTester tester) async {
......
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