Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding custom components into Material-ui Select

So, I'm trying to add <Button /> inside Material-ui <Select /> component (it should close the drop-down dialog when I click on the button) but the problem is that the button behaves as a <MenuItem /> component and i can`t set behavior i need.

Is anyone tried to customize select like so? Any ideas?

like image 849
SqrtMe Avatar asked Apr 23 '26 03:04

SqrtMe


1 Answers

It works when you wrap the buttons in a <div> under <MenuItem/>s. For example,

<Select>
  <MenuItem>1</MenuItem>
  <MenuItem>2</MenuItem>
  <div>
    <button onClick={()=>console.log('close button clicked')}>close</button>
  </div>
</Select>

I've created a codesandbox

like image 88
Christina Yun Avatar answered Apr 24 '26 18:04

Christina Yun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!