最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to make header and footer of Modal fixed while allowing the Modal content alone to scroll? - Stack Overflow

programmeradmin4浏览0评论

I have been playing around with the Modal ponent and I noticed that long content in a Modal window makes the whole modal body scroll instead of just the content inside the Modal.

Is there any way to make the content alone scroll while keeping the header and footer of the Modal ponent fixed?

I require something similar to how Material-UI Dialog ponent's Paper scroll works.

Check the button labeled scroll=Paper.

I have been playing around with the Modal ponent and I noticed that long content in a Modal window makes the whole modal body scroll instead of just the content inside the Modal.

Is there any way to make the content alone scroll while keeping the header and footer of the Modal ponent fixed?

I require something similar to how Material-UI Dialog ponent's Paper scroll works.

Check the button labeled scroll=Paper.

Share Improve this question edited Jun 23, 2019 at 19:25 Dennis Vash 54k12 gold badges117 silver badges132 bronze badges asked Jun 23, 2019 at 19:09 gameboynintendocolorgameboynintendocolor 352 silver badges5 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

There is no official way to do this, I believe because it's pretty trivial.

You need to define the Modal children scrollable, for example defining a Card with overflow and height.

<Card bordered={false} style={{ overflow: 'auto', height: '50vh' }}>

Material-UI Dialog doing just that behind the scenes.

function FixedModal() {
  return (
    <Modal visible={true} title={'Title'} footer={'Footer'}>
      <Card bordered={false} style={{ overflow: 'auto', height: '50vh' }}>
        {[...new Array(50)]
          .map(
            () => `Cras mattis consectetur purus sit amet fermentum.
Cras justo odio, dapibus ac facilisis in, egestas eget quam.
Morbi leo risus, porta ac consectetur ac, vestibulum at eros.
Praesent modo cursus magna, vel scelerisque nisl consectetur et.`
          )
          .join('\n')}
      </Card>
    </Modal>
  );
}

Demo:

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论