反应输入 - 光标跳到最后



我正在使用这个软件包react-phone-number-input

上下文

我有此电话号码字段

<InputPhone
{...input}
value={input.value || ''}
placeholder={intl.formatMessage(
placeholder ? messages[placeholder] : messages.placeholder,
)}
style={{
borderColor: meta && meta.touched && meta.error && 'red',
}}
tabIndex={index}
size={size}
/>

这是在一个功能组件内部,我不能使用另一个 textInput,因为我们以多种形式使用这个小组件,而且它内部具有特殊功能,例如样式和占位符。

问题

问题与此包react-phone-number-input有关:如果我尝试编辑前两部分中的数字,插入符号会跳到末尾。

有人知道自从禁用react-phone-number-input的智能卡雷特功能以来,我该如何修复它?

看看这个问题 - 听起来像你的问题。

您可以尝试智能插入符号功能 - 文档页面上的最后一项。请记住,它可能对某些Android设备有限制。

import SmartInput from 'react-phone-number-input/smart-input'
<PhoneInput
inputComponent={ SmartInput }
placeholder="Enter phone number"
value={ this.state.value }
onChange={ value => this.setState({ value }) }/>

希望对您有所帮助!


如果这不起作用,一个最小的、可重现的例子会有所帮助,就像杜波卡斯建议的那样。

最新更新