Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add scroll into react-bootstrap Modal.Body

I'm using react-bootstrap modal.

How can I make only body to scroll and not all the page?

  <Modal.Dialog>
    <Modal.Header>
      <Modal.Title>Modal title</Modal.Title>
    </Modal.Header>

    <Modal.Body>One fine body...</Modal.Body>

    <Modal.Footer>
      <Button>Close</Button>
      <Button bsStyle="primary">Save changes</Button>
    </Modal.Footer>
  </Modal.Dialog>
like image 993
Hemã Vidal Avatar asked Feb 20 '18 13:02

Hemã Vidal


People also ask

How do you add a scroll to a modal body?

Bootstrap 4.3 added new built-in scroll feature to modals. This makes only the modal-body content scroll if the size of the content would otherwise make the page scroll. To use it, just add the class modal-dialog-scrollable to the same div that has the modal-dialog class.

How do you make a popup scroll in react JS?

To implement scrolling in the Popup component, do the following: Wrap the content in the ScrollView component and place it in the Popup container. Set the height and width of the ScrollView to 100% of the popup content area.

How do I add a scroll bar in react?

You can apply it by placing the overflow-y:scroll in the id growth inside the style tag. Notice the scroll bar on the right side of the div .


2 Answers

Thanks to Amit answer.

The first solution using only styles would be the following:

  <Modal.Dialog>
    <Modal.Header>
      <Modal.Title>Modal title</Modal.Title>
    </Modal.Header>

    <Modal.Body style={{
      maxHeight: 'calc(100vh - 210px)',
      overflowY: 'auto'
     }}
    >
     One fine body...
    </Modal.Body>

    <Modal.Footer>
      <Button>Close</Button>
      <Button bsStyle="primary">Save changes</Button>
    </Modal.Footer>
  </Modal.Dialog>

There is a new way to implement that behavior using the react-bootstrap itself:

<Modal
  scrollable={true}
  ....
>
  ....
</Modal>

Modal Documentation

like image 110
Hemã Vidal Avatar answered Oct 21 '22 01:10

Hemã Vidal


you can add scrollable to the Modal:

<Modal scrollable={true}>
</Modal>

You can get details from the Modal docs

like image 15
Kavya Avatar answered Oct 20 '22 23:10

Kavya