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

Commit 1e02bfd

Browse files
author
nturgut
authored
Support decimal information on the TextInputType (#19664)
* adding decimal inoutmode * change intentation
1 parent 0532227 commit 1e02bfd

File tree

3 files changed

+59
-27
lines changed

3 files changed

+59
-27
lines changed

lib/web_ui/lib/src/engine/text_editing/input_type.dart

+18-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
65
part of engine;
76

87
/// Various types of inputs used in text fields.
@@ -14,10 +13,10 @@ part of engine;
1413
abstract class EngineInputType {
1514
const EngineInputType();
1615

17-
static EngineInputType fromName(String name) {
16+
static EngineInputType fromName(String name, {bool isDecimal = false}) {
1817
switch (name) {
1918
case 'TextInputType.number':
20-
return number;
19+
return isDecimal ? decimal : number;
2120
case 'TextInputType.phone':
2221
return phone;
2322
case 'TextInputType.emailAddress':
@@ -38,6 +37,9 @@ abstract class EngineInputType {
3837
/// Numeric input type.
3938
static const NumberInputType number = NumberInputType();
4039

40+
/// Decimal input type.
41+
static const DecimalInputType decimal = DecimalInputType();
42+
4143
/// Phone number input type.
4244
static const PhoneInputType phone = PhoneInputType();
4345

@@ -89,13 +91,26 @@ class TextInputType extends EngineInputType {
8991
}
9092

9193
/// Numeric input type.
94+
///
95+
/// Input keyboard with only the digits 0–9.
9296
class NumberInputType extends EngineInputType {
9397
const NumberInputType();
9498

9599
@override
96100
final String inputmodeAttribute = 'numeric';
97101
}
98102

103+
/// Decimal input type.
104+
///
105+
/// Input keyboard with containing the digits 0–9 and a decimal separator.
106+
/// Seperator can be `.`, `,` depending on the locale.
107+
class DecimalInputType extends EngineInputType {
108+
const DecimalInputType();
109+
110+
@override
111+
final String inputmodeAttribute = 'decimal';
112+
}
113+
99114
/// Phone number input type.
100115
class PhoneInputType extends EngineInputType {
101116
const PhoneInputType();

lib/web_ui/lib/src/engine/text_editing/text_editing.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,9 @@ class InputConfiguration {
435435
InputConfiguration.fromFrameworkMessage(
436436
Map<String, dynamic> flutterInputConfiguration)
437437
: inputType = EngineInputType.fromName(
438-
flutterInputConfiguration['inputType']['name']),
438+
flutterInputConfiguration['inputType']['name'],
439+
isDecimal:
440+
flutterInputConfiguration['inputType']['decimal'] ?? false),
439441
inputAction = flutterInputConfiguration['inputAction'],
440442
obscureText = flutterInputConfiguration['obscureText'],
441443
autocorrect = flutterInputConfiguration['autocorrect'],

lib/web_ui/test/text_editing_test.dart

+38-23
Original file line numberDiff line numberDiff line change
@@ -572,12 +572,14 @@ void main() {
572572
/// the keyboard.
573573
///
574574
/// Returns the `clientId` used in the platform message.
575-
int showKeyboard({String inputType, String inputAction}) {
575+
int showKeyboard(
576+
{String inputType, String inputAction, bool decimal = false}) {
576577
final MethodCall setClient = MethodCall(
577578
'TextInput.setClient',
578579
<dynamic>[
579580
++clientId,
580-
createFlutterConfig(inputType, inputAction: inputAction),
581+
createFlutterConfig(inputType,
582+
inputAction: inputAction, decimal: decimal),
581583
],
582584
);
583585
sendFrameworkMessage(codec.encodeMethodCall(setClient));
@@ -867,8 +869,7 @@ void main() {
867869
expect(document.getElementsByTagName('form'), isEmpty);
868870
});
869871

870-
test(
871-
'No capitilization: setClient, setEditingState, show', () {
872+
test('No capitilization: setClient, setEditingState, show', () {
872873
// Create a configuration with an AutofillGroup of four text fields.
873874
final Map<String, dynamic> capitilizeWordsConfig = createFlutterConfig(
874875
'text',
@@ -908,8 +909,7 @@ void main() {
908909
hideKeyboard();
909910
});
910911

911-
test(
912-
'All characters capitilization: setClient, setEditingState, show', () {
912+
test('All characters capitilization: setClient, setEditingState, show', () {
913913
// Create a configuration with an AutofillGroup of four text fields.
914914
final Map<String, dynamic> capitilizeWordsConfig = createFlutterConfig(
915915
'text',
@@ -1356,6 +1356,12 @@ void main() {
13561356
showKeyboard(inputType: 'number');
13571357
expect(getEditingInputMode(), 'numeric');
13581358

1359+
showKeyboard(inputType: 'number', decimal: false);
1360+
expect(getEditingInputMode(), 'numeric');
1361+
1362+
showKeyboard(inputType: 'number', decimal: true);
1363+
expect(getEditingInputMode(), 'decimal');
1364+
13591365
showKeyboard(inputType: 'phone');
13601366
expect(getEditingInputMode(), 'tel');
13611367

@@ -1369,29 +1375,36 @@ void main() {
13691375
});
13701376

13711377
test('sets correct input type in iOS', () {
1372-
debugOperatingSystemOverride = OperatingSystem.iOs;
1373-
debugBrowserEngineOverride = BrowserEngine.webkit;
1378+
// Test on ios-safari only.
1379+
if (browserEngine == BrowserEngine.webkit &&
1380+
operatingSystem == OperatingSystem.iOs) {
1381+
/// During initialization [HybridTextEditing] will pick the correct
1382+
/// text editing strategy for [OperatingSystem.iOs].
1383+
textEditing = HybridTextEditing();
13741384

1375-
/// During initialization [HybridTextEditing] will pick the correct
1376-
/// text editing strategy for [OperatingSystem.iOs].
1377-
textEditing = HybridTextEditing();
1385+
showKeyboard(inputType: 'text');
1386+
expect(getEditingInputMode(), 'text');
13781387

1379-
showKeyboard(inputType: 'text');
1380-
expect(getEditingInputMode(), 'text');
1388+
showKeyboard(inputType: 'number');
1389+
expect(getEditingInputMode(), 'numeric');
13811390

1382-
showKeyboard(inputType: 'number');
1383-
expect(getEditingInputMode(), 'numeric');
1391+
showKeyboard(inputType: 'number', decimal: false);
1392+
expect(getEditingInputMode(), 'numeric');
13841393

1385-
showKeyboard(inputType: 'phone');
1386-
expect(getEditingInputMode(), 'tel');
1394+
showKeyboard(inputType: 'number', decimal: true);
1395+
expect(getEditingInputMode(), 'decimal');
13871396

1388-
showKeyboard(inputType: 'emailAddress');
1389-
expect(getEditingInputMode(), 'email');
1397+
showKeyboard(inputType: 'phone');
1398+
expect(getEditingInputMode(), 'tel');
13901399

1391-
showKeyboard(inputType: 'url');
1392-
expect(getEditingInputMode(), 'url');
1400+
showKeyboard(inputType: 'emailAddress');
1401+
expect(getEditingInputMode(), 'email');
13931402

1394-
hideKeyboard();
1403+
showKeyboard(inputType: 'url');
1404+
expect(getEditingInputMode(), 'url');
1405+
1406+
hideKeyboard();
1407+
}
13951408
});
13961409

13971410
test('sends the correct input action as a platform message', () {
@@ -1798,10 +1811,12 @@ Map<String, dynamic> createFlutterConfig(
17981811
String inputAction,
17991812
String autofillHint,
18001813
List<String> autofillHintsForFields,
1814+
bool decimal = false,
18011815
}) {
18021816
return <String, dynamic>{
1803-
'inputType': <String, String>{
1817+
'inputType': <String, dynamic>{
18041818
'name': 'TextInputType.$inputType',
1819+
if (decimal) 'decimal': true,
18051820
},
18061821
'obscureText': obscureText,
18071822
'autocorrect': autocorrect,

0 commit comments

Comments
 (0)