diff --git a/lib/web_ui/lib/src/engine/text_editing/input_type.dart b/lib/web_ui/lib/src/engine/text_editing/input_type.dart index f4a84b3c65551..28d81f19f995b 100644 --- a/lib/web_ui/lib/src/engine/text_editing/input_type.dart +++ b/lib/web_ui/lib/src/engine/text_editing/input_type.dart @@ -2,7 +2,6 @@ // 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. @@ -14,10 +13,10 @@ part of engine; abstract class EngineInputType { const EngineInputType(); - static EngineInputType fromName(String name) { + static EngineInputType fromName(String name, {bool isDecimal = false}) { switch (name) { case 'TextInputType.number': - return number; + return isDecimal ? decimal : number; case 'TextInputType.phone': return phone; case 'TextInputType.emailAddress': @@ -38,6 +37,9 @@ abstract class EngineInputType { /// Numeric input type. static const NumberInputType number = NumberInputType(); + /// Decimal input type. + static const DecimalInputType decimal = DecimalInputType(); + /// Phone number input type. static const PhoneInputType phone = PhoneInputType(); @@ -89,6 +91,8 @@ class TextInputType extends EngineInputType { } /// Numeric input type. +/// +/// Input keyboard with only the digits 0–9. class NumberInputType extends EngineInputType { const NumberInputType(); @@ -96,6 +100,17 @@ class NumberInputType extends EngineInputType { final String inputmodeAttribute = 'numeric'; } +/// Decimal input type. +/// +/// Input keyboard with containing the digits 0–9 and a decimal separator. +/// Seperator can be `.`, `,` depending on the locale. +class DecimalInputType extends EngineInputType { + const DecimalInputType(); + + @override + final String inputmodeAttribute = 'decimal'; +} + /// Phone number input type. class PhoneInputType extends EngineInputType { const PhoneInputType(); diff --git a/lib/web_ui/lib/src/engine/text_editing/text_editing.dart b/lib/web_ui/lib/src/engine/text_editing/text_editing.dart index fdda61bc8cd27..d1aea5da5bc94 100644 --- a/lib/web_ui/lib/src/engine/text_editing/text_editing.dart +++ b/lib/web_ui/lib/src/engine/text_editing/text_editing.dart @@ -435,7 +435,9 @@ class InputConfiguration { InputConfiguration.fromFrameworkMessage( Map flutterInputConfiguration) : inputType = EngineInputType.fromName( - flutterInputConfiguration['inputType']['name']), + flutterInputConfiguration['inputType']['name'], + isDecimal: + flutterInputConfiguration['inputType']['decimal'] ?? false), inputAction = flutterInputConfiguration['inputAction'], obscureText = flutterInputConfiguration['obscureText'], autocorrect = flutterInputConfiguration['autocorrect'], diff --git a/lib/web_ui/test/text_editing_test.dart b/lib/web_ui/test/text_editing_test.dart index a45fa836dfbe5..dfe51f28e90a5 100644 --- a/lib/web_ui/test/text_editing_test.dart +++ b/lib/web_ui/test/text_editing_test.dart @@ -572,12 +572,14 @@ void main() { /// the keyboard. /// /// Returns the `clientId` used in the platform message. - int showKeyboard({String inputType, String inputAction}) { + int showKeyboard( + {String inputType, String inputAction, bool decimal = false}) { final MethodCall setClient = MethodCall( 'TextInput.setClient', [ ++clientId, - createFlutterConfig(inputType, inputAction: inputAction), + createFlutterConfig(inputType, + inputAction: inputAction, decimal: decimal), ], ); sendFrameworkMessage(codec.encodeMethodCall(setClient)); @@ -867,8 +869,7 @@ void main() { expect(document.getElementsByTagName('form'), isEmpty); }); - test( - 'No capitilization: setClient, setEditingState, show', () { + test('No capitilization: setClient, setEditingState, show', () { // Create a configuration with an AutofillGroup of four text fields. final Map capitilizeWordsConfig = createFlutterConfig( 'text', @@ -908,8 +909,7 @@ void main() { hideKeyboard(); }); - test( - 'All characters capitilization: setClient, setEditingState, show', () { + test('All characters capitilization: setClient, setEditingState, show', () { // Create a configuration with an AutofillGroup of four text fields. final Map capitilizeWordsConfig = createFlutterConfig( 'text', @@ -1356,6 +1356,12 @@ void main() { showKeyboard(inputType: 'number'); expect(getEditingInputMode(), 'numeric'); + showKeyboard(inputType: 'number', decimal: false); + expect(getEditingInputMode(), 'numeric'); + + showKeyboard(inputType: 'number', decimal: true); + expect(getEditingInputMode(), 'decimal'); + showKeyboard(inputType: 'phone'); expect(getEditingInputMode(), 'tel'); @@ -1369,29 +1375,36 @@ void main() { }); test('sets correct input type in iOS', () { - debugOperatingSystemOverride = OperatingSystem.iOs; - debugBrowserEngineOverride = BrowserEngine.webkit; + // Test on ios-safari only. + if (browserEngine == BrowserEngine.webkit && + operatingSystem == OperatingSystem.iOs) { + /// During initialization [HybridTextEditing] will pick the correct + /// text editing strategy for [OperatingSystem.iOs]. + textEditing = HybridTextEditing(); - /// During initialization [HybridTextEditing] will pick the correct - /// text editing strategy for [OperatingSystem.iOs]. - textEditing = HybridTextEditing(); + showKeyboard(inputType: 'text'); + expect(getEditingInputMode(), 'text'); - showKeyboard(inputType: 'text'); - expect(getEditingInputMode(), 'text'); + showKeyboard(inputType: 'number'); + expect(getEditingInputMode(), 'numeric'); - showKeyboard(inputType: 'number'); - expect(getEditingInputMode(), 'numeric'); + showKeyboard(inputType: 'number', decimal: false); + expect(getEditingInputMode(), 'numeric'); - showKeyboard(inputType: 'phone'); - expect(getEditingInputMode(), 'tel'); + showKeyboard(inputType: 'number', decimal: true); + expect(getEditingInputMode(), 'decimal'); - showKeyboard(inputType: 'emailAddress'); - expect(getEditingInputMode(), 'email'); + showKeyboard(inputType: 'phone'); + expect(getEditingInputMode(), 'tel'); - showKeyboard(inputType: 'url'); - expect(getEditingInputMode(), 'url'); + showKeyboard(inputType: 'emailAddress'); + expect(getEditingInputMode(), 'email'); - hideKeyboard(); + showKeyboard(inputType: 'url'); + expect(getEditingInputMode(), 'url'); + + hideKeyboard(); + } }); test('sends the correct input action as a platform message', () { @@ -1798,10 +1811,12 @@ Map createFlutterConfig( String inputAction, String autofillHint, List autofillHintsForFields, + bool decimal = false, }) { return { - 'inputType': { + 'inputType': { 'name': 'TextInputType.$inputType', + if (decimal) 'decimal': true, }, 'obscureText': obscureText, 'autocorrect': autocorrect,