简体   繁体   English

当我单击其中一项(输入元素)时,如何阻止 Select 组件关闭 - 反应 antd

[英]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.

相关问题 单击复选框时如何停止关闭可折叠的手风琴 - How can I stop the accordion(collapsible) from closing when checkboxes are clicked (react,antd,card) 如何使用 antd 卡组件阻止 onclick function 操作按钮? - (react,antd,card) How can I block the onclick function from action buttons with antd card component? 在 React js 中单击项目后如何显示组件? - How can I show a component after item clicked in react js? 单击 SpeedDialAction 按钮时,我可以阻止 Material-UI SpeedDial 关闭吗 - Can I stop Material-UI SpeedDial from closing when a SpeedDialAction button is clicked 如何在单击子项时停止为父元素触发onclick事件? - How can I stop an onclick event from firing for parent element when child is clicked? 我怎样才能让每次输出的项目在输入字段中输出,如果它被点击 - How can I make so that every time outputted-item is outputted in the input field if its clicked jQuery如何停止选择元素的下拉? - Jquery how can i stop the select element from dropping down? 如何使用 $() 通过索引选择元素? - How can I select an element by its index with $()? #Antd#如何将自制组件与Form.item绑定 - #Antd# How can I bind self-made component with Form.item 我如何从reactjs中的组件获取输入元素 - How can i get an input element from a component in reactjs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM