What is the best way to set/override a custom width for a modal?
It seems ng-bootstrap currently supports
size: 'sm' | 'lg'
but Bootstrap 4 supports sm, md and lg.
Ideally I would like the modal to be responsive and adjust similar to container sizes. And on mobile have it go full screen.
EDIT: Bootstrap 4 _variables.scss seems to have a $modal-md setting but appears to be unused.
$modal-lg: 800px !default; $modal-md: 500px !default; $modal-sm: 300px !default;
Change the size of the modal by adding the . modal-sm class for small modals, . modal-lg class for large modals, or . modal-xl for extra large modals.
modal max-height is 100vh . Then for . modal-body use calc() function to calculate desired height. In above case we want to occupy 80vh of the viewport, reduced by the size of header + footer in pixels.
The cleanest solution that I could find is to use the windowClass property.
I.e.:
this.modalService.open(MyModalComponent, { windowClass : "myCustomModalClass"});
Then add the following to your global CSS styles. This is important as the style won't be picked up from your components CSS.
.myCustomModalClass .modal-dialog { max-width: 565px; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With