React-Bootstrap Dropdown with Input won't stay open
·
Answer a question
I am using React-Bootstrap DropDown with an Input inside a MenuItem (otherwise the console yells at me Uncaught TypeError: Cannot read property 'focus' of undefined)
Okay so the drop down renders, and the input is inside a menu item (all is well) except when I click inside the input, the dropdown closes.
Here is my JSX
<Bootstrap.DropdownButton title={this.state.callIdTitle} id="callId">
<Bootstrap.MenuItem eventKey='1'>
<input ref="callIdInput" type='text' eventKey='2' placeholder='Enter Call ID' />
</Bootstrap.MenuItem>
</Bootstrap.DropdownButton>
Any pointing in the right direction is very much appreciated, I have been trying to solve this all day.
Thank you.
Answers
After all day...this is what I came up with.
I hope there's a better way.
<Bootstrap.DropdownButton onClick={this.setFocusToCallIdInput} title={this.state.callIdTitle}>
<Bootstrap.MenuItem href="javascript:void(0);" eventKey='1'>
<Bootstrap.Input onClick={this.dontCloseMeBro} ref="callIdInput" type='text' onChange={this.callIdInputSelected} placeholder='Enter Call ID' />
</Bootstrap.MenuItem>
</Bootstrap.DropdownButton>
setFocusToCallIdInput:function(e){
console.log("Call Id clicked");
React.findDOMNode(this.refs.callIdInput).focus();
e.stopPropagation();
e.nativeEvent.stopImmediatePropagation();
},
dontCloseMeBro:function(e){
console.log("menu item clicked");
React.findDOMNode(this.refs.callIdInput).focus();
e.stopPropagation();
e.nativeEvent.stopImmediatePropagation();
},
更多推荐
所有评论(0)