diff --git a/src/components/modal/modal.scss b/src/components/modal/modal.scss index f7902c35..42cebc14 100644 --- a/src/components/modal/modal.scss +++ b/src/components/modal/modal.scss @@ -43,6 +43,7 @@ > .mykn-card { border-top-right-radius: 0; border-bottom-right-radius: 0; + height: 100%; } // TODO: Investiage improvement. @@ -64,8 +65,4 @@ &--size-s { width: 280px; } - - .mykn-card { - height: 100%; - } } diff --git a/src/components/modal/modal.tsx b/src/components/modal/modal.tsx index 14550284..a28c9212 100644 --- a/src/components/modal/modal.tsx +++ b/src/components/modal/modal.tsx @@ -41,11 +41,26 @@ export const Modal: React.FC = ({ [open], ); + /** + * Gets called when to modal is closed. + * @param e + */ const handleClose: React.ReactEventHandler = (e) => { setOpenState(false); onClose?.(e); }; + /** + * Get called when a key is pressed, prevents the default action if key is "Escape" and closing is not allowed. + * @param e + */ + const handleKeyDown: React.KeyboardEventHandler = (e) => { + if (allowClose || e.key !== "Escape") { + return; + } + e.preventDefault(); + }; + const context = { open: Boolean(openState), }; @@ -82,6 +97,7 @@ export const Modal: React.FC = ({ [`mykn-modal--position-${position}`]: position, })} onClose={handleClose} + onKeyDown={handleKeyDown} {...props} >