【发布时间】:2019-05-25 03:22:42
【问题描述】:
我创建了一个Modal 并在其中放置了一些文本来描述我的应用程序以及如何使用它,但是文本溢出了Modal,因此文本的顶部和底部不可见。我想让组件可滚动,这样我的文本就不会超出页面的末端。
// The styling for the modal
const styles = theme => ({
paper: {
position: 'absolute',
width: theme.spacing.unit * 130,
backgroundColor: theme.palette.background.paper,
boxShadow: theme.shadows[5],
padding: theme.spacing.unit * 4,
},
});
function getModalStyle() {
const top = 50
const left = 50
return {
top: `${top}%`,
left: `${left}%`,
transform: `translate(-${top}%, -${left}%)`,
overflow: "scroll"
};
}
// The actual modal
<Modal
aria-labelledby="simple-modal-title"
aria-describedby="simple-modal-description"
open={this.state.modalOpen}
onClose={this.handleModalClose}
>
<div style={getModalStyle()} className={classes.paper}>
<MyLongTextComponent/>
</div>
</Modal>
我希望它具有独立于其背后的实际页面的滚动功能。我在互联网上没有找到太多帮助,所以任何指针都会非常有帮助!此外,如果 Modal 是在这种情况下使用的错误组件,请告诉我。我对 React 和 material-ui 比较陌生,所以如果有更好的方法,我很想学习。
【问题讨论】:
-
如果能制作stackblitz demo就更好了
标签: javascript reactjs material-ui