Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions packages/core/ui/editable-text-base/index.android.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { describe, it, expect, vi } from 'vitest';

vi.hoisted(() => {
const g = globalThis as any;
g.android = {
...g.android,
text: {
...g.android?.text,
InputType: { TYPE_NULL: 0, TYPE_CLASS_TEXT: 1, TYPE_CLASS_NUMBER: 2, TYPE_CLASS_PHONE: 3, TYPE_TEXT_VARIATION_EMAIL_ADDRESS: 32 },
},
};
});

import { EditableTextBase } from './index.android';
import { keyboardTypeProperty } from './editable-text-base-common';

function inputTypeFor(value: unknown): number {
const target = { _setInputType: vi.fn() };
(EditableTextBase.prototype as any)[keyboardTypeProperty.setNative].call(target, value);
return target._setInputType.mock.calls[0][0];
}

describe('EditableTextBase keyboardType (Android)', () => {
const InputType = (globalThis as any).android.text.InputType;

it('uses the text keyboard for null and undefined', () => {
expect(inputTypeFor(null)).toBe(InputType.TYPE_CLASS_TEXT);
expect(inputTypeFor(undefined)).toBe(InputType.TYPE_CLASS_TEXT);
});

it('uses the text keyboard for unknown names', () => {
expect(inputTypeFor('text')).toBe(InputType.TYPE_CLASS_TEXT);
});

it('passes native input type numbers through, including TYPE_NULL', () => {
expect(inputTypeFor(InputType.TYPE_CLASS_PHONE)).toBe(InputType.TYPE_CLASS_PHONE);
expect(inputTypeFor('3')).toBe(InputType.TYPE_CLASS_PHONE);
expect(inputTypeFor(0)).toBe(InputType.TYPE_NULL);
});

it('maps named keyboard types', () => {
expect(inputTypeFor('integer')).toBe(InputType.TYPE_CLASS_NUMBER);
});
});
3 changes: 2 additions & 1 deletion packages/core/ui/editable-text-base/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
break;

default: {
const inputType = +value;
// +null is 0, which is InputType.TYPE_NULL and hides the soft keyboard.
const inputType = value == null ? NaN : +value;
if (!isNaN(inputType)) {
newInputType = inputType;
} else {
Expand Down
Loading