当使用react-select
时它不是按选项值自动调整大小,而是使用 width:100%
正如您在图片中看到的:
选项很短:
getOptions() {
return [
{ value: 'AND', label: 'AND' },
{ value: 'OR', label: 'OR' }
]
}
以及生成它的代码:
<Select
options={this.getOptions()}
value={value}
autosize={true}
clearable={false}
simpleValue
/>
有什么办法可以制作react-select
要使用自动调整大小来显示这些值,因此选择框将与选项长度相同,例如,我可以将此选择框居中于 <div>
?
更新于2017年11月14日 完整的例子可以在这个jsFiddle中看到。
最佳答案
内联样式对我不起作用。 我只是将 Select 组件包装在一个 div 中,并为该 div 提供了我想要的宽度。
<div style={{width: '300px'}}>
<Select
menuPlacement="auto"
menuPosition="fixed"
etc, etc..
/>
</div>
关于reactjs - React 选择自动调整宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46571811/