唯一应用样式的道具是:
className 类字符串和带有样式的 style 对象。
请记住,这些应用于根元素(Modal 组件)。
DocsSourceCode(如果您使用的是 v1-beta)。你可以在sources中看到剩余的props被传递给了Modal组件
const {
anchorEl,
anchorReference,
anchorPosition,
anchorOrigin,
children,
classes,
elevation,
getContentAnchorEl,
marginThreshold,
onEnter,
onEntering,
onEntered,
onExit,
onExiting,
onExited,
open,
PaperProps,
role,
transformOrigin,
transitionClasses,
transitionDuration,
...other
} = this.props;
<Modal show={open} BackdropInvisible {...other}>
您可以在源代码中看到,MaterialUI 使用来自 react-jss 的 withStyles HoC,并且具有用于 Paper 组件的样式对象
export const styles = {
paper: {
position: 'absolute',
overflowY: 'auto',
overflowX: 'hidden',
// So we see the popover when it's empty.
// It's most likely on issue on userland.
minWidth: 16,
minHeight: 16,
maxWidth: 'calc(100vw - 32px)',
maxHeight: 'calc(100vh - 32px)'
maxHeight: 'calc(100vh - 32px)'
这绑定到一个类 paper,然后传递给 classes 属性并应用于 Paper 组件。
解决方案:
在带有嵌套选择器的根元素上使用 className 属性,该选择器以 Paper 组件为目标(检查并查看它将类应用于哪个元素)。
可能的选择器示例(绝对应该使用更好的选择器,检查元素)
.rootElement > * { max-height: '375px' }
然后你会做<Popover className='rootElement' />