Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[web] Send input action even in multiline editing mode #33428

Merged
merged 1 commit into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions lib/web_ui/lib/src/engine/text_editing/input_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ 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();

Expand Down Expand Up @@ -158,9 +155,6 @@ class MultilineInputType extends EngineInputType {
@override
String? get inputmodeAttribute => null;

@override
bool get submitActionOnEnter => false;

@override
html.HtmlElement createDomElement() => html.TextAreaElement();
}
8 changes: 2 additions & 6 deletions lib/web_ui/lib/src/engine/text_editing/text_editing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1302,12 +1302,8 @@ abstract class DefaultTextEditingStrategy implements TextEditingStrategy {
}

void maybeSendAction(html.Event event) {
if (event is html.KeyboardEvent) {
if (inputConfiguration.inputType.submitActionOnEnter &&
event.keyCode == _kReturnKeyCode) {
event.preventDefault();
onAction!(inputConfiguration.inputAction);
}
if (event is html.KeyboardEvent && event.keyCode == _kReturnKeyCode) {
onAction!(inputConfiguration.inputAction);
}
}

Expand Down
18 changes: 12 additions & 6 deletions lib/web_ui/test/text_editing_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ Future<void> testMain() async {
// TODO(mdebbar): https://github.com/flutter/flutter/issues/50769
skip: browserEngine == BrowserEngine.edge);

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

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

test('does not send input action in multi-line mode', () {
test('sends input action in multi-line mode', () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know how many people relied in the old behavior? Is this going to be a breaking change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default, multiline text fields have the action TextInputAction.newline as you can see here:

https://github.com/flutter/flutter/blob/5739bf4fabb8340ced93eecc0d15072498d3a7ac/packages/flutter/lib/src/widgets/editable_text.dart#L1420-L1426

and here:
https://github.com/flutter/flutter/blob/5739bf4fabb8340ced93eecc0d15072498d3a7ac/packages/flutter/lib/src/widgets/editable_text.dart#L3070-L3073

This PR doesn't change the behavior of the above default action.

What this PR changes is the case where the user provides a different action (e.g. TextInputAction.done). In this case, the user is specifically asking us to perform the "done" action when ENTER is clicked. But we used to ignore that and treat everything as a "newline" action in multiline text fields. That was a BUG on our side.

I don't see a reason for users to rely on the old behavior because they could've just left everything at default and got the same behavior.

showKeyboard(
inputType: 'multiline',
inputAction: 'TextInputAction.next',
Expand All @@ -1915,8 +1915,14 @@ Future<void> testMain() async {
keyCode: _kReturnKeyCode,
);

// No input action and no platform message have been sent.
expect(spy.messages, isEmpty);
// Input action is sent as a platform message.
expect(spy.messages, hasLength(1));
expect(spy.messages[0].channel, 'flutter/textinput');
expect(spy.messages[0].methodName, 'TextInputClient.performAction');
expect(
spy.messages[0].methodArguments,
<dynamic>[clientId, 'TextInputAction.next'],
);
// And default behavior of keyboard event shouldn't have been prevented.
expect(event.defaultPrevented, isFalse);
});
Expand Down