Skip to content

Commit

Permalink
Merge pull request #423 from devtron-labs/fix/tippy-customized-onesc
Browse files Browse the repository at this point in the history
fix: remove keydown listener on tippy customized unmount
  • Loading branch information
arunjaindev authored Nov 26, 2024
2 parents 86d0b81 + 791c3e9 commit 03d5296
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/Common/TippyCustomized.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import React, { useRef, useState } from 'react'
import { useEffect, useRef, useState } from 'react'
import Tippy from '@tippyjs/react'
import { ReactComponent as CloseIcon } from '../Assets/Icon/ic-cross.svg'
import { ReactComponent as Help } from '../Assets/Icon/ic-help.svg'
Expand All @@ -33,7 +33,6 @@ export const TippyCustomized = (props: TippyCustomizedProps) => {

const onTippyMount = (tippyInstance) => {
tippyRef.current = tippyInstance
document.addEventListener('keydown', closeOnEsc)
}

const closeTippy = (e) => {
Expand All @@ -49,11 +48,21 @@ export const TippyCustomized = (props: TippyCustomizedProps) => {
setShowHeadingInfo(false)
}

const closeOnEsc = (e) => {
if (e.keyCode === 27) {
closeTippy(e)
useEffect(() => {
const closeOnEsc = (e) => {
if (e.keyCode === 27) {
closeTippy(e)
}
}
}

document.addEventListener('keydown', closeOnEsc)

return () => {
document.removeEventListener('keydown', closeOnEsc)
}
}, [])



const toggleHeadingInfo = (e) => {
setShowHeadingInfo(not)
Expand Down

0 comments on commit 03d5296

Please sign in to comment.