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

标签 javascript reactjs react-select css-modules

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

我正在使用 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 Prop 。有一个 topic on this in the Advanced documentation ,特别是提供了模态示例。像这样的东西:

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

关于javascript - react-select 下拉菜单在模态内打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54890660/

相关文章:

javascript - 划分React.js组件

javascript - 使用自定义组件时如何在 React-Select 中设置所选项目的样式?

javascript - 异步未处理的PromiseRejectionWarning

javascript - jQuery 追加延迟

javascript - React-Router - 链接到同一页面不触发页面卸载

reactjs - react 选择中的 onKeydown 事件

javascript - React-Select - 替换自定义选项内容的组件

javascript - 与 HTML 中的按钮关联的功能 - 未按预期工作

javascript - Angularjs 无法输入 Controller

reactjs - defaultProps 应该在类体之外声明