当Select isSearchable时,我希望键盘处于数字模式

时间:2019-04-05 10:03:23

标签: react-select

当Select isSearchable且设备可移动时,我希望键盘处于数字模式。这可能吗?谢谢

1 个答案:

答案 0 :(得分:1)

您必须使用components framework覆盖Input组件,并将pattern道具设置为仅在当前设备为移动设备时才允许数字。

输入元素上的pattern道具(或更确切地说是属性)检查输入值以进行输入验证。使用正确的模式,它可以控制您在移动设备上使用的键盘类型。 \d*是一种正则表达式模式,仅允许数字输入。

const Input = (props) => <components.Input {...props} pattern={somehowCheckForMobile() ? "\\d*" : undefined} />;

<Select 
    { ... }
    components={{
        Input
    }}
/>

CodeSandbox example