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
Support keyboard types on mobile browsers #13044
Merged
Merged
Changes from all commits
Commits
Show all changes
2 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| // 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. | ||
|
|
||
| part of engine; | ||
|
|
||
| /// Various types of inputs used in text fields. | ||
| /// | ||
| /// These types are coming from Flutter's [TextInputType]. Currently, we don't | ||
| /// support all the types. We fallback to [EngineInputType.text] when Flutter | ||
| /// sends a type that isn't supported. | ||
| // TODO(flutter_web): Support more types. | ||
| abstract class EngineInputType { | ||
| const EngineInputType(); | ||
|
|
||
| static EngineInputType fromName(String name) { | ||
| switch (name) { | ||
| case 'TextInputType.number': | ||
| return number; | ||
| case 'TextInputType.phone': | ||
| return phone; | ||
| case 'TextInputType.emailAddress': | ||
| return emailAddress; | ||
| case 'TextInputType.url': | ||
| return url; | ||
| case 'TextInputType.multiline': | ||
| return multiline; | ||
|
|
||
| case 'TextInputType.text': | ||
| default: | ||
| return text; | ||
| } | ||
| } | ||
|
|
||
| /// Single-line text input type. | ||
| static const TextInputType text = TextInputType(); | ||
|
|
||
| /// Numeric input type. | ||
| static const NumberInputType number = NumberInputType(); | ||
|
|
||
| /// Phone number input type. | ||
| static const PhoneInputType phone = PhoneInputType(); | ||
|
|
||
| /// Email address input type. | ||
| static const EmailInputType emailAddress = EmailInputType(); | ||
|
|
||
| /// URL input type. | ||
| static const UrlInputType url = UrlInputType(); | ||
|
|
||
| /// Multi-line text input type. | ||
| static const MultilineInputType multiline = MultilineInputType(); | ||
|
|
||
| /// The HTML `inputmode` attribute to be set on the DOM element. | ||
| /// | ||
| /// This HTML attribute helps the browser decide what kind of keyboard works | ||
| /// best for this text field. | ||
| /// | ||
| /// For various `inputmode` values supported by browsers, see: | ||
| /// <https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inputmode>. | ||
| String get inputmodeAttribute; | ||
|
|
||
| /// Create the appropriate DOM element for this input type. | ||
| html.HtmlElement createDomElement() => html.InputElement(); | ||
|
|
||
| /// Given a [domElement], set attributes that are specific to this input type. | ||
| void configureDomElement(html.HtmlElement domElement) { | ||
| if (inputmodeAttribute == null) { | ||
| return; | ||
| } | ||
|
|
||
| // Only apply `inputmode` in mobile browsers so that the right virtual | ||
| // keyboard shows up. | ||
| if (operatingSystem == OperatingSystem.iOs || | ||
| operatingSystem == OperatingSystem.android) { | ||
| domElement.setAttribute('inputmode', inputmodeAttribute); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Single-line text input type. | ||
| class TextInputType extends EngineInputType { | ||
| const TextInputType(); | ||
|
|
||
| @override | ||
| final String inputmodeAttribute = 'text'; | ||
| } | ||
|
|
||
| /// Numeric input type. | ||
| class NumberInputType extends EngineInputType { | ||
| const NumberInputType(); | ||
|
|
||
| @override | ||
| final String inputmodeAttribute = 'numeric'; | ||
| } | ||
|
|
||
| /// Phone number input type. | ||
| class PhoneInputType extends EngineInputType { | ||
| const PhoneInputType(); | ||
|
|
||
| @override | ||
| final String inputmodeAttribute = 'tel'; | ||
| } | ||
|
|
||
| /// Email address input type. | ||
| class EmailInputType extends EngineInputType { | ||
| const EmailInputType(); | ||
|
|
||
| @override | ||
| final String inputmodeAttribute = 'email'; | ||
| } | ||
|
|
||
| /// URL input type. | ||
| class UrlInputType extends EngineInputType { | ||
| const UrlInputType(); | ||
|
|
||
| @override | ||
| final String inputmodeAttribute = 'url'; | ||
| } | ||
|
|
||
| /// Multi-line text input type. | ||
| class MultilineInputType extends EngineInputType { | ||
| const MultilineInputType(); | ||
|
|
||
| @override | ||
| final String inputmodeAttribute = null; | ||
|
|
||
| @override | ||
| html.HtmlElement createDomElement() => html.TextAreaElement(); | ||
| } | ||
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
Oops, something went wrong.
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.