On click of a button I open a dropdown where I want to shift the focus to the dropdown from the button. I need to access the dom element to do this. I read about ref and how to use it but it does not work.
constructor(){
this.changeFocus = this.changeFocus.bind(this)
}
changeFocus() {
this.test1.focus();
}
render(){
let menu = (
<Menu>
<MenuItem ref={(input) => { this.test1 = input; }} label="Test1"/>
<MenuItem ref={(input) => { this.test2 = input; }} label="Test2"/>
</Menu>
);
return (
<i onClick={this.changeFocus}</i>
{menu}
)
}
But I get undefined. what is the correct way to get the dom element ?Please assume that changeFocus toggles the menu dropdown ie when user clicks on the icon it open the dropdown but focus remains on icon. I want it to go on the dropdown items