CupertinoTextField should not accept requestFocus when disabled (#65235)
This commit is contained in:
parent
408cd71d82
commit
dd41f41f34
@ -653,6 +653,7 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with Restoratio
|
|||||||
if (widget.controller == null) {
|
if (widget.controller == null) {
|
||||||
_createLocalController();
|
_createLocalController();
|
||||||
}
|
}
|
||||||
|
_effectiveFocusNode.canRequestFocus = widget.enabled ?? true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -665,11 +666,7 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with Restoratio
|
|||||||
_controller!.dispose();
|
_controller!.dispose();
|
||||||
_controller = null;
|
_controller = null;
|
||||||
}
|
}
|
||||||
final bool isEnabled = widget.enabled ?? true;
|
_effectiveFocusNode.canRequestFocus = widget.enabled ?? true;
|
||||||
final bool wasEnabled = oldWidget.enabled ?? true;
|
|
||||||
if (wasEnabled && !isEnabled) {
|
|
||||||
_effectiveFocusNode.unfocus();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -2707,6 +2707,43 @@ void main() {
|
|||||||
expect(tapCount, 1);
|
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(
|
testWidgets(
|
||||||
'text field respects theme',
|
'text field respects theme',
|
||||||
(WidgetTester tester) async {
|
(WidgetTester tester) async {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user