react-select 下拉菜单在模态内打开

react-select dropdown opens inside modal

我有一个自定义模态框,里面有 2 个 react-select 组件。模态主体已准备好自动滚动,以防内容超出其大小,但 react-select 组件下拉列表在模态内部打开并出现此溢出,这是我不想要的。没有溢出,它工作正常。

我正在使用 CSS 模块。

<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}/>

我该如何解决这个问题? 谢谢! :)

您想查看 menuPortalTarget 道具。有一个 topic on this in the Advanced documentation,特别是提供了一个模态示例。类似于:

  <Select
    {...otherProps}
    menuPortalTarget={document.body} />