react-modal icon indicating copy to clipboard operation
react-modal copied to clipboard

How do I change the width of the modal?

Open phongyewtong opened this issue 3 years ago • 4 comments

Summary:

How do I change the width?

<div style={{minWidth: '600px', width: '600px', maxWidth: '600px'}} >
    <Modal open={open} onClose={this.onCloseModal} closeOnOverlayClick={true}>
          <CreateSubmenu onFormSubmit={this.onSubmenuFormSubmit} editData={editSubmenuData}/>
     </Modal>
</div>

phongyewtong avatar Jul 27 '20 15:07 phongyewtong

you should be able to apply custom styles to the modal via the 'style' prop. Via the npm docs: const customStyles = { content : { top : '50%', left : '50%', right : 'auto', bottom : 'auto', marginRight : '-50%', transform : 'translate(-50%, -50%)' } };

<Modal isOpen={modalIsOpen} onAfterOpen={afterOpenModal} onRequestClose={closeModal} style={customStyles} contentLabel="Example Modal" >

you can just replace the position styling shown above with 'width: 600px' or whatever width you desire

namnguyen21 avatar Jul 27 '20 18:07 namnguyen21

Thanks, @namnguyen21!

@phongyewtong Did this solve your problem?

diasbruno avatar Aug 18 '20 23:08 diasbruno

I tried this solution with only partial success. The custom styles appear in ReactModal__Content but I still need to update modal-dialog as this has max-width:500px. I believe this is an attempt to change that but not sure if it works https://stackoverflow.com/a/52951219/4288232

TimSC avatar Aug 09 '22 05:08 TimSC

This seemed to work (together with using customStyles as discussed above):

@media screen and (min-width: 992px) { 
    .modal-dialog {
        max-width: 900px;
        max-height: 80%;
    }
}

@media screen and (min-width: 426px) and (max-width: 991) { 
    .modal-dialog {
        max-width: 80%;
        max-height: 80%;
    }
}

@media screen and (max-width: 425px) { 
    .modal-dialog {
        max-width: 100%;
        max-height: 100%;
    }
}

TimSC avatar Aug 09 '22 05:08 TimSC