Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

menuPortalTarget doesn't not work if react-select dropdown opens inside modal

Tags:

react-select

I have a problem react-select dropdown opens inside modal

Below is my coding:

<Select                
styles={{
  menu: provided => ({ ...provided, zIndex: 9999 })
}}
options={optionsHour}
value={{ label: durationHour, value: durationHour }}
onChange={(e) => { setDurationHour(e.value) }}
>
</Select>

This one is the current result, it cannot show react_select dropdown over modal.

img1

I tried the below code with using menuPortalTarget, but it also cannot work.

<Select                
styles={{
  menu: provided => ({ ...provided, zIndex: 9999 })
}}
menuPortalTarget={document.body}
options={optionsHour}
value={{ label: durationHour, value: durationHour }}
onChange={(e) => { setDurationHour(e.value) }}
>
</Select>

Below result is what I've tried:

img2

Actually, I want the result like below the picture:

img3

Hope someone can guide me on how to solve it. Thanks.

like image 238
Fatt Sky Avatar asked Aug 15 '26 16:08

Fatt Sky


1 Answers

Give your modal a class (for example, dialog-base) and then reference it in menuPortalTarget:

  menuPortalTarget={document.getElementsByClassName('dialog-base')[0] as HTMLElement}

Then add the following prop as well:

  menuPosition="fixed"
like image 80
TylerJB Avatar answered Aug 24 '26 13:08

TylerJB



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!