2017-08-31 78 views
0

我已实施react-select以允许根据自动填写建议输入标签和/或插入新标签。选择其中一个建议选项后,提示文字不会消失

我实现如下:

import Select from 'react-select'; 
...  
<Select.AsyncCreatable 
    className='add-tags' 
    clearable={!!selectionTags} 
    placeholder={'add more'} 
    name="form-field-name" 
    value={selectionTags} 
    onChange={setSelectionTags} 
    loadOptions={loadOptions} 
    promptTextCreator={(label)=>`add new tag: ${label}`} 
    inputProps={inputProps} 
    multi 
/> 

selectionTags是已经选定的标签列表,setSelectionTags是增加了一个新的选择的项目到该列表的功能,并loadOptions持有名单自动填充建议。

问题是,如果我输入“TA”,我有“标签1”为可落成的一个,然后选择它会清空的建议列表,但留下的“添加新标签:TA”显示条目。

任何想法为什么它不被删除?

谢谢!

回答

0

在此之后线程React-Select github上:
https://github.com/JedWatson/react-select/issues/1663

我结束了通过添加下列选项工作围着它

ref={s => (selectRef = s)} // store a reference to the select instance 

onChange={tags => { 
       selectRef.select.closeMenu(); // close the entire menu 
       selectRef.select.setState({ 
        isFocused: false,   // remove focus from new tag option 
       }); 
       setSelectionTags(tags);  // call the add tags method with the new set of tags 
      }} 
相关问题