Skip to content

Commit

Permalink
revert: "fix: popover closing on delete dialog" (#1030)
Browse files Browse the repository at this point in the history
  • Loading branch information
amanharwara authored May 17, 2022
1 parent 7f12f93 commit b3f6888
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const AttachedFilesButton: FunctionComponent<Props> = observer(
const buttonRef = useRef<HTMLButtonElement>(null)
const panelRef = useRef<HTMLDivElement>(null)
const containerRef = useRef<HTMLDivElement>(null)
const [closeOnBlur, keepMenuOpen] = useCloseOnBlur(containerRef, setOpen, true)
const [closeOnBlur, keepMenuOpen] = useCloseOnBlur(containerRef, setOpen)

useEffect(() => {
if (appState.filePreviewModal.isOpen) {
Expand Down
12 changes: 4 additions & 8 deletions app/assets/javascripts/Hooks/useCloseOnBlur.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,16 @@ import { StateUpdater, useCallback, useState } from 'preact/hooks'
export function useCloseOnBlur(
container: { current?: HTMLDivElement | null },
setOpen: (open: boolean) => void,
keepOpenOnDialogs = false,
): [(event: { relatedTarget: EventTarget | null }) => void, StateUpdater<boolean>] {
const [locked, setLocked] = useState(false)
return [
useCallback(
function onBlur(event: { relatedTarget: EventTarget | null }) {
setTimeout(() => {
const keepOpen = keepOpenOnDialogs && document.activeElement?.closest('[role="dialog"], .sk-modal')
if (!keepOpen && !locked && !container.current?.contains(event.relatedTarget as Node)) {
setOpen(false)
}
})
if (!locked && !container.current?.contains(event.relatedTarget as Node)) {
setOpen(false)
}
},
[keepOpenOnDialogs, locked, container, setOpen],
[container, setOpen, locked],
),
setLocked,
]
Expand Down

0 comments on commit b3f6888

Please sign in to comment.