How can I access the custom target attribute within material UI select options in React js

Viewed 324

Here is my select element

<Select
    native 
    onChange={this.handleDepChange}
  >  
     {
      departments.map((dep, index) => (
        <option key={'dep-ind - ' + index} value={dep.id} depCode={dep.code}>
          {dep.name}
        </option>
       ))
     }                                    
</Select>

I defined custom attribute within option element named depCode.

Here is my onChange event

handleDepChange = (e) => {
   console.log(e.target.value)   //it give the intended value
   console.log(e.target.depCode) //it is undefined
}

Can someone please guide me, how I can access depCode. I am using MaterialUI library.

2 Answers

Try this

e.nativeEvent.target.getAttribute("depcode")

Live Demo

Edit 64160047/how-can-i-access-the-custom-target-attribute-within-material-ui-select-options-i

Related