【发布时间】:2021-09-25 06:09:25
【问题描述】:
编辑:
沙盒:https://codesandbox.io/s/clever-leftpad-dkjh7?file=/index.js:0-1748
我正在使用 React,evergreen-ui SelectMenu 组件。
使用组件的titleView 属性的问题是,当标题高度较高时,某些选择菜单项无法正确呈现(隐藏)。
假设在上图中,“hhhhhhh”应该显示但被隐藏了。
public render() {
const { children } = this.props;
let options = [];
options.push({ label: '00000000', value: '00000000' });
options.push({ label: '11111111', value: '11111111' });
options.push({ label: '22222222', value: '22222222' });
options.push({ label: 'aaaaaaaa', value: 'aaaaaaaa' });
options.push({ label: 'bbbbbbbb', value: 'bbbbbbbb' });
options.push({ label: 'cccccccc', value: 'cccccccc' });
options.push({ label: 'dddddddd', value: 'dddddddd' });
options.push({ label: 'eeeeeeee', value: 'eeeeeeee' });
options.push({ label: 'ffffffff', value: 'ffffffff' });
options.push({ label: 'gggggggg', value: 'gggggggg' });
options.push({ label: 'hhhhhhhh', value: 'hhhhhhhh' });
return (
<SelectMenu
className={'someClassName'}
filterPlaceholder={'Filter by name...'}
isMultiSelect={true}
titleView={this.getCustomTitleView}
hasTitle={true}
hasFilter={true}
options={...options}
onSelect={this.onDeviceSelectHandler}
onDeselect={this.onDeviceDeselectHandler}
>
{children}
</SelectMenu>
);
}
private getCustomTitleView() {
return (
<Pane
display="flex"
flexDirection="column"
borderBottom="default"
padding={8}
boxSizing="border-box"
>
<Heading size={400}>{this.props.title}</Heading>
<Pane marginTop={5}>
<Button width={'100%'} justifyContent="center">
Clear all selections
</Button>
</Pane>
</Pane>
);
}
我尝试向组件添加className 属性以使用以下CSS(见下文),希望它会动态地将高度增加到此值,但到目前为止它不起作用。
.someClassName:nth-of-type(1) {
height: 285px;
}
通过控制台手动添加它是可行的:
【问题讨论】:
-
你能分享一个codeandbox的例子吗?
-
嗨@gionic,我添加了一个沙盒链接。请看上面,谢谢!
-
最好的形式是使用此处呈现的相关 HTML 和 CSS 来说明和重现这个问题,甚至可以作为 sn-p。
标签: css reactjs css-selectors react-component