This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
add enterkeyhint property to web textfields #35411
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
155 changes: 155 additions & 0 deletions
155
lib/web_ui/lib/src/engine/text_editing/input_action.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import '../browser_detection.dart'; | ||
| import '../dom.dart'; | ||
|
|
||
| /// Various input action types used in text fields. | ||
| /// | ||
| /// These types are coming from Flutter's [TextInputAction]. Currently, the web doesn't | ||
| /// support all the types. We fallback to [EngineInputAction.none] when Flutter | ||
| /// sends a type that isn't supported. | ||
| abstract class EngineInputAction { | ||
| const EngineInputAction(); | ||
|
|
||
| static EngineInputAction fromName(String name) { | ||
| switch (name) { | ||
| case 'TextInputAction.continueAction': | ||
| case 'TextInputAction.next': | ||
| return next; | ||
| case 'TextInputAction.previous': | ||
| return previous; | ||
| case 'TextInputAction.done': | ||
| return done; | ||
| case 'TextInputAction.go': | ||
| return go; | ||
| case 'TextInputAction.newline': | ||
| return enter; | ||
| case 'TextInputAction.search': | ||
| return search; | ||
| case 'TextInputAction.send': | ||
| return send; | ||
| case 'TextInputAction.emergencyCall': | ||
| case 'TextInputAction.join': | ||
| case 'TextInputAction.none': | ||
| case 'TextInputAction.route': | ||
| case 'TextInputAction.unspecified': | ||
| default: | ||
| return none; | ||
| } | ||
| } | ||
|
|
||
| /// No input action | ||
| static const NoInputAction none = NoInputAction(); | ||
|
|
||
| /// Action to go to next | ||
| static const NextInputAction next = NextInputAction(); | ||
|
|
||
| /// Action to go to previous | ||
| static const PreviousInputAction previous = PreviousInputAction(); | ||
|
|
||
| /// Action to be finished | ||
| static const DoneInputAction done = DoneInputAction(); | ||
|
|
||
| /// Action to Go | ||
| static const GoInputAction go = GoInputAction(); | ||
|
|
||
| /// Action to insert newline | ||
| static const EnterInputAction enter = EnterInputAction(); | ||
|
|
||
| /// Action to search | ||
| static const SearchInputAction search = SearchInputAction(); | ||
|
|
||
| /// Action to send | ||
| static const SendInputAction send = SendInputAction(); | ||
|
|
||
|
|
||
| /// The HTML `enterkeyhint` attribute to be set on the DOM element. | ||
| /// | ||
| /// This HTML attribute helps the browser decide what kind of keyboard action | ||
| /// to use for this text field | ||
| /// | ||
| /// For various `enterkeyhint` values supported by browsers, see: | ||
| /// <https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/enterkeyhint>. | ||
| String? get enterkeyhintAttribute; | ||
|
|
||
| /// Given a [domElement], set attributes that are specific to this input action. | ||
| void configureInputAction(DomHTMLElement domElement) { | ||
| if (enterkeyhintAttribute == null) { | ||
| return; | ||
| } | ||
|
|
||
| // Only apply `enterkeyhint` in mobile browsers so that the right virtual | ||
| // keyboard shows up. | ||
| if (operatingSystem == OperatingSystem.iOs || | ||
| operatingSystem == OperatingSystem.android || | ||
| enterkeyhintAttribute == EngineInputAction.none.enterkeyhintAttribute) { | ||
| domElement.setAttribute('enterkeyhint', enterkeyhintAttribute!); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// No action specified | ||
| class NoInputAction extends EngineInputAction { | ||
| const NoInputAction(); | ||
|
|
||
| @override | ||
| String? get enterkeyhintAttribute => null; | ||
| } | ||
|
|
||
| /// Typically inserting a new line. | ||
| class EnterInputAction extends EngineInputAction { | ||
| const EnterInputAction(); | ||
|
|
||
| @override | ||
| String? get enterkeyhintAttribute => 'enter'; | ||
| } | ||
|
|
||
| /// Typically meaning there is nothing more to input and the input method editor (IME) will be closed. | ||
| class DoneInputAction extends EngineInputAction { | ||
| const DoneInputAction(); | ||
|
|
||
| @override | ||
| String? get enterkeyhintAttribute => 'done'; | ||
| } | ||
|
|
||
| /// Typically meaning to take the user to the target of the text they typed. | ||
| class GoInputAction extends EngineInputAction { | ||
| const GoInputAction(); | ||
|
|
||
| @override | ||
| String? get enterkeyhintAttribute => 'go'; | ||
| } | ||
|
|
||
| /// Typically taking the user to the next field that will accept text. | ||
| class NextInputAction extends EngineInputAction { | ||
| const NextInputAction(); | ||
|
|
||
| @override | ||
| String? get enterkeyhintAttribute => 'next'; | ||
| } | ||
|
|
||
| /// Typically taking the user to the previous field that will accept text. | ||
| class PreviousInputAction extends EngineInputAction { | ||
| const PreviousInputAction(); | ||
|
|
||
| @override | ||
| String? get enterkeyhintAttribute => 'previous'; | ||
| } | ||
|
|
||
| /// Typically taking the user to the results of searching for the text they have typed. | ||
| class SearchInputAction extends EngineInputAction { | ||
| const SearchInputAction(); | ||
|
|
||
| @override | ||
| String? get enterkeyhintAttribute => 'search'; | ||
| } | ||
|
|
||
| /// Typically delivering the text to its target. | ||
| class SendInputAction extends EngineInputAction { | ||
| const SendInputAction(); | ||
|
|
||
| @override | ||
| String? get enterkeyhintAttribute => 'send'; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.