Material ui select onchange is not bubbling

Viewed 9494

I have a div which has a material ui Select, material ui TextField and a plain html select. This div has an onchange event which simply console logs the event.target.value. When ever the onchange of material ui TextField or the select is triggered, event.target.value is logged to the console. But not for the onchange of material ui select.

sample code: https://codesandbox.io/s/material-demo-03495?file=/demo.tsx

What am i missing here?

Thanks.

3 Answers

You can use native attribute. You will get UI as Material but functionality as native select and thus bubbles too.

      <Select
        native
        value={muiSelectValue}
        onChange={handleMuiSelectOnChange}
        autoWidth
      >
        <option value="one">One</option>
        <option value="two">Two</option>
        <option value="three">Three</option>
      </Select>

You are not missing anything. If you add console.log(event) in your handle change functions, you will get to know that events of native elements are syntheticEvents where event you'll get in MUI's handle change will be a class as object. Hence whenever you change the value it will not get reflected to your actual div.

Related