Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-select dropdown opens inside modal

I have a custom modal where I have 2 react-select components inside. The modal body is ready to auto scroll in case the content exceeds its size, but the react-select components dropdown open inside the modal with this overflow, which is what i am not looking for. Without overflow, it works fine.

I'm working with CSS Modules.

<div className={styles.modalBody}>
    {this.props.children}
</div>

.modalBody {
    padding: padding;
    flex: 1 1 auto;
    height: 45vh;
    max-height: 100%;
    overflow: auto;
}

<Select
    id={this.props.id}
    className={styles[this.props.selectType ? this.props.selectType : 'selectWhite']}
    classNamePrefix="select"
    name={this.props.name}
    value={selectedOption ? selectedOption : this.props.value}
    placeholder={this.props.placeholder}
    onChange={this.onChange}
    options={this.props.options}
    isDisabled={this.props.disabled}
    isSearchable={false}/>

How can I fix this? Thank you! :)

like image 628
RCohen Avatar asked Feb 26 '19 17:02

RCohen


1 Answers

You want to look at the menuPortalTarget prop. There's a topic on this in the Advanced documentation, specifically with a modal example provided. Something like:

  <Select
    {...otherProps}
    menuPortalTarget={document.body} />
like image 191
Steve -Cutter- Blades Avatar answered Oct 24 '22 09:10

Steve -Cutter- Blades