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

Conversation

mdebbar
Copy link
Contributor

@mdebbar mdebbar commented May 17, 2022

On non-web platforms, the engine always sends an input action message to the framework when ENTER is clicked (regardless of the field being single or multi-line).

On the web, we don't send an input action for multi-line fields. This PR fixes it so we always send an input action just like the native engine does.

Fixes flutter/flutter#99900

@mdebbar mdebbar requested review from yjbanov and ditman May 17, 2022 15:46
@flutter-dashboard flutter-dashboard bot added the platform-web Code specifically for the web engine label May 17, 2022
@mdebbar mdebbar requested a review from ditman May 20, 2022 14:52
Copy link
Member

@ditman ditman left a comment

Choose a reason for hiding this comment

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

Other than the "maybe breaking change" comment, LGTM!

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.

@mdebbar mdebbar added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label May 24, 2022
@fluttergithubbot fluttergithubbot merged commit 4bf35bf into flutter:main May 24, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 24, 2022
houhuayong pushed a commit to houhuayong/engine that referenced this pull request Jun 21, 2022
@mdebbar mdebbar deleted the multiline_action branch January 17, 2023 18:25
auto-submit bot pushed a commit that referenced this pull request Jun 20, 2024
#53453)

## Description

This PR prevents new line key event from being dispatched for a multiline text field when `TextField.textInputAction` is not `TextInputAction.newline`.

Since #33428, web engine does not prevent new line key events.
In #36893, I fixed a similar issue for single line text fields. At that time I was not sure if we want to fix it for multiline text fields. I checked again on non-web platforms (macos, iOS, Android) and the new line is not added if the input action is not `TextInputAction.newline`.

For a **multiline field**, the default text input action is `TextInputAction.newline`.
If the developer sets text input action to another value:
- before this PR, the action is performed and a new line is added.
- after this PR, the action is performed but no new line is added.

## Related Issue

Fixes flutter/flutter#145051

## Tests

Adds 1 tests, updates 3 tests.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform-web Code specifically for the web engine waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Web]: A multiline TextFormField doesn't trigger onFieldSubmitted
3 participants