如何关闭菜单onNewOptionClick?
问题描述:
<Creatable
name="productType"=
options = {this.state.productOptions}
value = {this.state.productType}
onNewOptionClick = {this.createProductType}
onChange = {this.handleProductChange}
/>
createProductType(option) {
var options = this.state.productOptions;
var label = option.label.charAt(0).toUpperCase() + option.label.slice(1);
options.push({
label: label,
value: option.value
})
this.setState({
productOptions: options,
productType: option.value
})
}
之前,我点击新的选择:
我按新的选项后:
期望中的UI状态点击新选项后:
没有是否将此问题作为Github发布,因为我不确定使用onNewOptionClick的确切方式。
答
我能够通过添加ref
ref={input => this.productSelect = input }
,然后调用它,以便
this.productSelect.select.closeMenu();
这(https://github.com/JedWatson/react-select/issues/1262)来解决这个提供的线索,最终这让我解决这个问题。谢谢。
答
不知道是否已经出现了重大更改以来第一个答案库中,但我不得不这样做:
ref={input => {
if (input) this.productSelectMenu = input._selectRef.select
}}
然后:
this.productSelectMenu.closeMenu();