Space and arrow keys in a text field shouldn't scroll (#74454)

This commit is contained in:
Mouad Debbar
2021-01-22 16:39:04 -08:00
committed by GitHub
parent 177fd261bb
commit e204eb2fca
5 changed files with 130 additions and 41 deletions

View File

@@ -4287,6 +4287,39 @@ void main() {
expect(focusNode3.hasPrimaryFocus, isTrue);
});
testWidgets('Scrolling shortcuts are disabled in text fields', (WidgetTester tester) async {
bool scrollInvoked = false;
await tester.pumpWidget(
CupertinoApp(
home: Actions(
actions: <Type, Action<Intent>>{
ScrollIntent: CallbackAction<ScrollIntent>(onInvoke: (Intent intent) {
scrollInvoked = true;
}),
},
child: ListView(
children: const <Widget>[
Padding(padding: EdgeInsets.symmetric(vertical: 200)),
CupertinoTextField(),
Padding(padding: EdgeInsets.symmetric(vertical: 800)),
],
),
),
),
);
await tester.pump();
expect(scrollInvoked, isFalse);
// Set focus on the text field.
await tester.tapAt(tester.getTopLeft(find.byType(CupertinoTextField)));
await tester.sendKeyEvent(LogicalKeyboardKey.space);
expect(scrollInvoked, isFalse);
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
expect(scrollInvoked, isFalse);
});
testWidgets('Cupertino text field semantics', (WidgetTester tester) async {
await tester.pumpWidget(
CupertinoApp(

View File

@@ -8754,6 +8754,41 @@ void main() {
expect(focusNode3.hasPrimaryFocus, isTrue);
});
testWidgets('Scrolling shortcuts are disabled in text fields', (WidgetTester tester) async {
bool scrollInvoked = false;
await tester.pumpWidget(
MaterialApp(
home: Actions(
actions: <Type, Action<Intent>>{
ScrollIntent: CallbackAction<ScrollIntent>(onInvoke: (Intent intent) {
scrollInvoked = true;
}),
},
child: Material(
child: ListView(
children: const <Widget>[
Padding(padding: EdgeInsets.symmetric(vertical: 200)),
TextField(),
Padding(padding: EdgeInsets.symmetric(vertical: 800)),
],
),
),
),
),
);
await tester.pump();
expect(scrollInvoked, isFalse);
// Set focus on the text field.
await tester.tapAt(tester.getTopLeft(find.byType(TextField)));
await tester.sendKeyEvent(LogicalKeyboardKey.space);
expect(scrollInvoked, isFalse);
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
expect(scrollInvoked, isFalse);
});
testWidgets("A buildCounter that returns null doesn't affect the size of the TextField", (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/44909