Skip to content

Commit a674ec0

Browse files
authored
fix(android): null keyboardType shows the default text keyboard (#11576)
Closes #9194 [skip ci]
1 parent 4764c37 commit a674ec0

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { describe, it, expect, vi } from 'vitest';
2+
3+
vi.hoisted(() => {
4+
const g = globalThis as any;
5+
g.android = {
6+
...g.android,
7+
text: {
8+
...g.android?.text,
9+
InputType: { TYPE_NULL: 0, TYPE_CLASS_TEXT: 1, TYPE_CLASS_NUMBER: 2, TYPE_CLASS_PHONE: 3, TYPE_TEXT_VARIATION_EMAIL_ADDRESS: 32 },
10+
},
11+
};
12+
});
13+
14+
import { EditableTextBase } from './index.android';
15+
import { keyboardTypeProperty } from './editable-text-base-common';
16+
17+
function inputTypeFor(value: unknown): number {
18+
const target = { _setInputType: vi.fn() };
19+
(EditableTextBase.prototype as any)[keyboardTypeProperty.setNative].call(target, value);
20+
return target._setInputType.mock.calls[0][0];
21+
}
22+
23+
describe('EditableTextBase keyboardType (Android)', () => {
24+
const InputType = (globalThis as any).android.text.InputType;
25+
26+
it('uses the text keyboard for null and undefined', () => {
27+
expect(inputTypeFor(null)).toBe(InputType.TYPE_CLASS_TEXT);
28+
expect(inputTypeFor(undefined)).toBe(InputType.TYPE_CLASS_TEXT);
29+
});
30+
31+
it('uses the text keyboard for unknown names', () => {
32+
expect(inputTypeFor('text')).toBe(InputType.TYPE_CLASS_TEXT);
33+
});
34+
35+
it('passes native input type numbers through, including TYPE_NULL', () => {
36+
expect(inputTypeFor(InputType.TYPE_CLASS_PHONE)).toBe(InputType.TYPE_CLASS_PHONE);
37+
expect(inputTypeFor('3')).toBe(InputType.TYPE_CLASS_PHONE);
38+
expect(inputTypeFor(0)).toBe(InputType.TYPE_NULL);
39+
});
40+
41+
it('maps named keyboard types', () => {
42+
expect(inputTypeFor('integer')).toBe(InputType.TYPE_CLASS_NUMBER);
43+
});
44+
});

‎packages/core/ui/editable-text-base/index.android.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
237237
break;
238238

239239
default: {
240-
const inputType = +value;
240+
// +null is 0, which is InputType.TYPE_NULL and hides the soft keyboard.
241+
const inputType = value == null ? NaN : +value;
241242
if (!isNaN(inputType)) {
242243
newInputType = inputType;
243244
} else {

0 commit comments

Comments
 (0)