Skip to content

Commit 4bf35bf

Browse files
authored
[web] Send input action even in multiline editing mode (flutter#33428)
1 parent 4742042 commit 4bf35bf

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

lib/web_ui/lib/src/engine/text_editing/input_type.dart

-6
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ abstract class EngineInputType {
6868
/// <https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inputmode>.
6969
String? get inputmodeAttribute;
7070

71-
/// Whether this input type allows the "Enter" key to submit the input action.
72-
bool get submitActionOnEnter => true;
73-
7471
/// Create the appropriate DOM element for this input type.
7572
html.HtmlElement createDomElement() => html.InputElement();
7673

@@ -158,9 +155,6 @@ class MultilineInputType extends EngineInputType {
158155
@override
159156
String? get inputmodeAttribute => null;
160157

161-
@override
162-
bool get submitActionOnEnter => false;
163-
164158
@override
165159
html.HtmlElement createDomElement() => html.TextAreaElement();
166160
}

lib/web_ui/lib/src/engine/text_editing/text_editing.dart

+2-6
Original file line numberDiff line numberDiff line change
@@ -1302,12 +1302,8 @@ abstract class DefaultTextEditingStrategy implements TextEditingStrategy {
13021302
}
13031303

13041304
void maybeSendAction(html.Event event) {
1305-
if (event is html.KeyboardEvent) {
1306-
if (inputConfiguration.inputType.submitActionOnEnter &&
1307-
event.keyCode == _kReturnKeyCode) {
1308-
event.preventDefault();
1309-
onAction!(inputConfiguration.inputAction);
1310-
}
1305+
if (event is html.KeyboardEvent && event.keyCode == _kReturnKeyCode) {
1306+
onAction!(inputConfiguration.inputAction);
13111307
}
13121308
}
13131309

lib/web_ui/test/text_editing_test.dart

+12-6
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ Future<void> testMain() async {
353353
// TODO(mdebbar): https://github.com/flutter/flutter/issues/50769
354354
skip: browserEngine == BrowserEngine.edge);
355355

356-
test('Does not trigger input action in multi-line mode', () {
356+
test('Triggers input action in multi-line mode', () {
357357
final InputConfiguration config = InputConfiguration(
358358
inputType: EngineInputType.multiline,
359359
inputAction: 'TextInputAction.done',
@@ -373,8 +373,8 @@ Future<void> testMain() async {
373373
keyCode: _kReturnKeyCode,
374374
);
375375

376-
// Still no input action.
377-
expect(lastInputAction, isNull);
376+
// Input action is triggered!
377+
expect(lastInputAction, 'TextInputAction.done');
378378
// And default behavior of keyboard event shouldn't have been prevented.
379379
expect(event.defaultPrevented, isFalse);
380380
});
@@ -1903,7 +1903,7 @@ Future<void> testMain() async {
19031903
// TODO(mdebbar): https://github.com/flutter/flutter/issues/50769
19041904
skip: browserEngine == BrowserEngine.edge);
19051905

1906-
test('does not send input action in multi-line mode', () {
1906+
test('sends input action in multi-line mode', () {
19071907
showKeyboard(
19081908
inputType: 'multiline',
19091909
inputAction: 'TextInputAction.next',
@@ -1915,8 +1915,14 @@ Future<void> testMain() async {
19151915
keyCode: _kReturnKeyCode,
19161916
);
19171917

1918-
// No input action and no platform message have been sent.
1919-
expect(spy.messages, isEmpty);
1918+
// Input action is sent as a platform message.
1919+
expect(spy.messages, hasLength(1));
1920+
expect(spy.messages[0].channel, 'flutter/textinput');
1921+
expect(spy.messages[0].methodName, 'TextInputClient.performAction');
1922+
expect(
1923+
spy.messages[0].methodArguments,
1924+
<dynamic>[clientId, 'TextInputAction.next'],
1925+
);
19201926
// And default behavior of keyboard event shouldn't have been prevented.
19211927
expect(event.defaultPrevented, isFalse);
19221928
});

0 commit comments

Comments
 (0)