我有一个自定义模态框,里面有 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/