[fix] TextInput keyboardType for 'numeric' and 'decimal'

Don't rely on native restrictions and validations for these keyboardType
values, as developers often want custom presentation (e.g., comma separators)
and custom validation.

Fix #1705
Fix #1438
Fix #1280
Close #1709
This commit is contained in:
Richard Lindhout
2020-08-20 13:07:04 +02:00
committed by Nicolas Gallagher
parent 7a8a70b948
commit 9ed0c407a9
2 changed files with 19 additions and 2 deletions
@@ -165,10 +165,22 @@ describe('components/TextInput', () => {
expect(input.type).toEqual('email');
});
test('value "decimal-pad"', () => {
const { container } = render(<TextInput keyboardType="decimal-pad" />);
const input = findInput(container);
expect(input.inputMode).toEqual('decimal');
});
test('value "number-pad"', () => {
const { container } = render(<TextInput keyboardType="number-pad" />);
const input = findInput(container);
expect(input.inputMode).toEqual('numeric');
});
test('value "numeric"', () => {
const { container } = render(<TextInput keyboardType="numeric" />);
const input = findInput(container);
expect(input.type).toEqual('number');
expect(input.inputMode).toEqual('numeric');
});
test('value "phone-pad"', () => {
+6 -1
View File
@@ -155,6 +155,7 @@ const TextInput = forwardRef<TextInputProps, *>((props, forwardedRef) => {
} = props;
let type;
let inputMode;
switch (keyboardType) {
case 'email-address':
@@ -162,7 +163,10 @@ const TextInput = forwardRef<TextInputProps, *>((props, forwardedRef) => {
break;
case 'number-pad':
case 'numeric':
type = 'number';
inputMode = 'numeric';
break;
case 'decimal-pad':
inputMode = 'decimal';
break;
case 'phone-pad':
type = 'tel';
@@ -368,6 +372,7 @@ const TextInput = forwardRef<TextInputProps, *>((props, forwardedRef) => {
supportedProps.spellCheck = spellCheck != null ? spellCheck : autoCorrect;
supportedProps.style = style;
supportedProps.type = multiline ? undefined : type;
supportedProps.inputMode = inputMode;
usePlatformMethods(hostRef, supportedProps);