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

javascript - How to Enable Scroll Bar iside Ant Design Modal Component Body? - Stack Overflow

programmeradmin3浏览0评论

I am having a modal with long content. I need to have an internal scroll bar inside the modal but there is no information about that in the documentation

 <Modal
        title={<Typography style={{color:'#2e186a'}}>FAQ</Typography>}
        centered
        visible={openFaq}
        onOk={() => setopenFaq(false)}
        onCancel={() => setopenFaq(false)}
        width={1000}
        footer={false}
        
      >
       {Content}
      </Modal>  

Any help is welcome.Thanks

I am having a modal with long content. I need to have an internal scroll bar inside the modal but there is no information about that in the documentation

 <Modal
        title={<Typography style={{color:'#2e186a'}}>FAQ</Typography>}
        centered
        visible={openFaq}
        onOk={() => setopenFaq(false)}
        onCancel={() => setopenFaq(false)}
        width={1000}
        footer={false}
        
      >
       {Content}
      </Modal>  

Any help is welcome.Thanks

Share Improve this question asked May 21, 2021 at 6:41 AnonymousAnonymous 911 gold badge2 silver badges8 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 9

You need to provide the maxHeight option inside bodyStyle prop along with overFlow set to auto

<Modal
   bodyStyle={{ overflowY: 'auto', maxHeight: 'calc(100vh - 200px)' }}
>
{content}
</Modal>

A suggestion by using CSS

<Modal
  bodyStyle={{overflowX: 'scroll'}}
>
  {Content}
</Modal>

You can achieve this as following:

  • Modify .ant-modal-content class
.ant-modal-content {
  height: 100%;
  display: flex;
  flex-direction: column;
}
  • Add fixed height and overflowY: scroll to the Modal
<Modal
  style={{ height: 'calc(100vh - 200px)' }}
  bodyStyle={{ overflowY: 'scroll' }}
>
  Your content
</Modal>
发布评论

评论列表(0)

  1. 暂无评论