Closed chawes13 closed 2 years ago
On second thought, I don't really love that UX. What if we encapsulated the broader concept of preventing close, i.e., preventClose
?
// Proposed implementation
function Modal({ onClose, preventClose=false, children, ...rest }) {
return (
<ReactModal
isOpen
onRequestClose={onClose}
portalClassName="modal"
className="modal-inner"
overlayClassName="modal-fade-screen"
bodyOpenClassName="modal-open"
appElement={getRootElement()}
ariaHideApp={isServer()} // Opt out of setting appElement on the server.
shouldCloseOnEsc={!preventClose}
shouldCloseOnOverlayClick={!preventClose}
{...rest}
>
<div className="modal-content">{children}</div>
{!preventClose && (
<>
<button
onClick={onClose}
className="modal-close"
aria-label="Close Modal"
>
×
</button>
</>
)}
</ReactModal>
)
}
Instead of having to pass in a function and several related props, derive the props from the lack of having a close function supplied. It's common for
hideCloseButton
to be the only prop that is considered, which can lead to defects with the user still being able to close a modal via the keyboard or pressing the overlay.