[英]How can I stop the Select component from closing when I clicked one of its item(Input element) - react antd
I am using antd(3.23.4)
.我正在使用antd(3.23.4)
。 I have a Select
component and I want to avoid it to close when I click one of its Option(Input element).我有一个Select
组件,当我单击其中一个选项(输入元素)时,我想避免它关闭。 Had been successful avoiding to close it however, cannot focus on the Input element when I clicked it.然而,已经成功避免关闭它,当我单击它时无法专注于 Input 元素。 I think this is because I wrapped it on a div and used a preventDefault()
on the div - which stops immediately when I clicked the Input element.我认为这是因为我将它包装在一个 div 上并在 div 上使用了preventDefault()
- 当我单击 Input 元素时它立即停止。 I've searched some of the issues on the antd's github but no luck.我搜索了antd的github上的一些问题,但没有运气。 Here is a sample of my code:这是我的代码示例:
<Select
dropdownRender={menu => (
<React.Fragment>
{menu}
<div onMouseDown={e => e.preventDefault()}>
<Input type="number" key="others" addonBefore="Others: " />
</div>
</React.Fragment>
)} >
<Option key="bar" value="bar">
bar
</Option>
</Select>
The problem here is that I can't click/focus the input.这里的问题是我无法单击/聚焦输入。 So that I can type in it.这样我就可以输入了。
Need help.需要帮忙。 Please advise.请指教。 Thank you in advance for those who will answer:)提前谢谢那些会回答的人:)
We have a size=""
attribute in select component(tag) in html Select Attributes .我们在 html Select属性中的 select 组件(标签)中有一个size=""
属性。 This make sure how many options inside the selectbox is visible at a time so u may do it like this....这可以确保选择框内的选项一次可见,所以你可以这样做......
<select
id="select"
name="catagory"
onChange={(e) => handleChange(e)}
onClick={() => addSize()}
>
*.....Your Options....*
</select>
const addSize = () => {
const selectBox = document.getElementById("select");
selectBox.addEventListener("click", selectBox.setAttribute("size", 10));
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.