未验证 提交 5b87cd07 编写于 作者: M Mouad Debbar 提交者: GitHub

Fix bug where Enter doesn't add new line in multi-line fields (#13630)

上级 fcd8a218
......@@ -59,6 +59,9 @@ abstract class EngineInputType {
/// <https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inputmode>.
String get inputmodeAttribute;
/// Whether this input type allows the "Enter" key to submit the input action.
bool get submitActionOnEnter => true;
/// Create the appropriate DOM element for this input type.
html.HtmlElement createDomElement() => html.InputElement();
......@@ -124,6 +127,9 @@ class MultilineInputType extends EngineInputType {
@override
final String inputmodeAttribute = null;
@override
bool get submitActionOnEnter => false;
@override
html.HtmlElement createDomElement() => html.TextAreaElement();
}
......@@ -437,7 +437,8 @@ class TextEditingElement {
}
void _maybeSendAction(html.KeyboardEvent event) {
if (event.keyCode == _kReturnKeyCode) {
if (_inputConfiguration.inputType.submitActionOnEnter &&
event.keyCode == _kReturnKeyCode) {
event.preventDefault();
_onAction(_inputConfiguration.inputAction);
}
......
......@@ -13,6 +13,9 @@ import 'package:test/test.dart';
import 'matchers.dart';
/// The `keyCode` of the "Enter" key.
const int _kReturnKeyCode = 13;
const MethodCodec codec = JSONMethodCodec();
TextEditingElement editingElement;
......@@ -250,10 +253,41 @@ void main() {
// No input action so far.
expect(lastInputAction, isNull);
dispatchKeyboardEvent(editingElement.domElement, 'keydown', keyCode: 13);
dispatchKeyboardEvent(
editingElement.domElement,
'keydown',
keyCode: _kReturnKeyCode,
);
expect(lastInputAction, 'TextInputAction.done');
});
test('Does not trigger input action in multi-line mode', () {
final InputConfiguration config = InputConfiguration(
inputType: EngineInputType.multiline,
obscureText: false,
inputAction: 'TextInputAction.done',
);
editingElement.enable(
config,
onChange: trackEditingState,
onAction: trackInputAction,
);
// No input action so far.
expect(lastInputAction, isNull);
final KeyboardEvent event = dispatchKeyboardEvent(
editingElement.domElement,
'keydown',
keyCode: _kReturnKeyCode,
);
// Still no input action.
expect(lastInputAction, isNull);
// And default behavior of keyboard event shouldn't have been prevented.
expect(event.defaultPrevented, isFalse);
});
group('[persistent mode]', () {
test('Does not accept dom elements of a wrong type', () {
// A regular <span> shouldn't be accepted.
......@@ -883,7 +917,7 @@ void main() {
dispatchKeyboardEvent(
textEditing.editingElement.domElement,
'keydown',
keyCode: 13,
keyCode: _kReturnKeyCode,
);
expect(spy.messages, hasLength(1));
......@@ -894,6 +928,24 @@ void main() {
<dynamic>[clientId, 'TextInputAction.next'],
);
});
test('does not send input action in multi-line mode', () {
showKeyboard(
inputType: 'multiline',
inputAction: 'TextInputAction.next',
);
final KeyboardEvent event = dispatchKeyboardEvent(
textEditing.editingElement.domElement,
'keydown',
keyCode: _kReturnKeyCode,
);
// No input action and no platform message have been sent.
expect(spy.messages, isEmpty);
// And default behavior of keyboard event shouldn't have been prevented.
expect(event.defaultPrevented, isFalse);
});
});
group('EditingState', () {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册