Skip to content

Commit

Permalink
fix(CModal): remove click outside listener when the modal is not visi…
Browse files Browse the repository at this point in the history
…ble; fire `handleClickOutside` method on `mouseup` event not `click`
  • Loading branch information
mrholek committed Jul 12, 2023
1 parent 7dd7f20 commit 140e285
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/coreui-react/src/components/modal/CModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,13 @@ export const CModal = forwardRef<HTMLDivElement, CModalProps>(
}, [visible])

useEffect(() => {
document.addEventListener('click', handleClickOutside)
document.addEventListener('keydown', handleKeyDown)
if (_visible) {
document.addEventListener('mouseup', handleClickOutside)
document.addEventListener('keydown', handleKeyDown)
}

return () => {
document.removeEventListener('click', handleClickOutside)
document.removeEventListener('mouseup', handleClickOutside)
document.removeEventListener('keydown', handleKeyDown)
}
}, [_visible])
Expand Down

0 comments on commit 140e285

Please sign in to comment.