Skip to content

Commit

Permalink
feat(FOROME-1628): close modal by escape key (#944)
Browse files Browse the repository at this point in the history
* feat(FOROME-1628): close modal by escape key

* feat(FOROME-1628): minor
  • Loading branch information
EvgeniySobolev authored Sep 14, 2022
1 parent da361dc commit c485cd9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/ui/modal/modal.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import styles from './modal.module.css'

import React, { ReactElement, useEffect, useRef, useState } from 'react'
import { ReactElement, useEffect, useRef, useState } from 'react'
import ReactDOM from 'react-dom'
import { Transition } from 'react-transition-group'
import cn from 'classnames'

import { useKeydown } from '@core/hooks/use-keydown'
import { Backdrop } from '../backdrop'
import { IModalProps } from './modal.interface'
import {
Expand All @@ -20,12 +21,19 @@ export const Modal = (props: IModalProps): ReactElement => {
isOpen,
isKeepMounted,
isBackdropInvisible,
onClose,
onClose = () => {},
transitionDuration,
} = props
const rootRef = useRef<HTMLDivElement>(null)
const [isMounted, setMounted] = useState(!!isOpen)

useKeydown([
{
eventCode: 'Escape',
callback: onClose,
},
])

useEffect(() => {
if (isOpen) {
window.setTimeout(() => setMounted(true), 0)
Expand Down

0 comments on commit c485cd9

Please sign in to comment.