选择反应中的文本

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

我可以通过编程将react-select聚焦,但是我无法在输入字段中选择文本。

我正在像这样引用react-select

const selectRef = useRef()
...
<Select
  ref={selectRef}
  // other props
</Select>

然后:

selectRef.current.focus()
selectRef.current.select()

[Select]成功聚焦,但是对于第二行(我相信should work on an input element),我得到:

input

如何在TypeError: selectRef.current.select is not a function react-select字段内选择文本?

reactjs react-select
1个回答
0
投票

仅几处更改-:

input

而且我们可以这样访问<Select ref={(n) => this.selectRef = n} // other props </Select> -> inputValue

工作小提琴-> this.selectRef.select.props.inputValue

© www.soinside.com 2019 - 2024. All rights reserved.