React-phone-input-2:选择国家/地区代码后自动对焦不起作用

问题描述 投票:0回答:1

您能解释一下,选择代码国家后如何集中输入吗?在演示中它按预期工作,但我的不起作用......

有PhoneInput组件的代码:

<PhoneInput
   inputProps={{
       autoFocus: true
   }}
   onChange={(e, action) => phoneChange(e, action)}
   localization={i18n.language === 'ru' && ru}
   placeholder={placeholder}
   value={phoneNumber}
   buttonClass={styles.phoneButton}
   inputClass={styles.phoneInput}
   dropdownClass={styles.phoneDropdown}
   searchClass={styles.phoneSearch}
   searchPlaceholder={searchHolder}
   searchNotFound={searchFind}
   country={country}
   disableSearchIcon={true}
   enableSearch={true}
   autocompleteSearch={true}
   jumpCursorToEnd={true}
/>

我尝试将 inputProps 传递给 PhoneInput 组件,但它将输入集中在第一个挂载上;(

javascript reactjs input focus react-phone-input-2
1个回答
0
投票

我想您的项目中安装了最新版本的react-phone-input-2(

2.15.1
2.15.0
)。

低于

2.14.0
的版本将为您完成这项工作。

您可以卸载当前版本:

npm uninstall react-phone-input-2

并安装

2.14.0
版本,当您更改国家/地区时,可与
autoFocus
配合使用:

npm install [email protected]
© www.soinside.com 2019 - 2024. All rights reserved.