Fix TextField performing both new line and input action (flutter/engine#36893)
Co-authored-by: Bruno Leroux <bruno.leroux@gmail.com>
This commit is contained in:
@@ -1376,6 +1376,10 @@ abstract class DefaultTextEditingStrategy with CompositionAwareMixin implements
|
||||
final DomKeyboardEvent event = e as DomKeyboardEvent;
|
||||
if (event.keyCode == _kReturnKeyCode) {
|
||||
onAction!(inputConfiguration.inputAction);
|
||||
// Prevent the browser from inserting a new line when it's not a multiline input.
|
||||
if (inputConfiguration.inputType is! MultilineInputType) {
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -390,6 +390,28 @@ Future<void> testMain() async {
|
||||
expect(event.defaultPrevented, isFalse);
|
||||
});
|
||||
|
||||
test('Triggers input action and prevent new line key event for single line field', () {
|
||||
// Regression test for https://github.com/flutter/flutter/issues/113559
|
||||
final InputConfiguration config = InputConfiguration();
|
||||
editingStrategy!.enable(
|
||||
config,
|
||||
onChange: trackEditingState,
|
||||
onAction: trackInputAction,
|
||||
);
|
||||
|
||||
// No input action so far.
|
||||
expect(lastInputAction, isNull);
|
||||
|
||||
final DomKeyboardEvent event = dispatchKeyboardEvent(
|
||||
editingStrategy!.domElement!,
|
||||
'keydown',
|
||||
keyCode: _kReturnKeyCode,
|
||||
);
|
||||
expect(lastInputAction, 'TextInputAction.done');
|
||||
// And default behavior of keyboard event should have been prevented.
|
||||
expect(event.defaultPrevented, isTrue);
|
||||
});
|
||||
|
||||
test('globally positions and sizes its DOM element', () {
|
||||
editingStrategy!.enable(
|
||||
singlelineConfig,
|
||||
|
||||
Reference in New Issue
Block a user