Skip to content

Commit

Permalink
fix: bug with onMouseLeave/onBlur
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards1211 committed Dec 12, 2022
1 parent ae8c286 commit 438f507
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,16 @@ export function usePopupState({
})
})

const close = useCallback(
const doClose = (state: CoreState): CoreState => {
const { _childPopupState } = state
setTimeout(() => {
_childPopupState?.close()
parentPopupState?._setChildPopupState(null)
})
return { ...state, isOpen: false, hovered: false, focused: false }
}

const close = useEvent(
(eventOrAnchorEl?: SyntheticEvent | Element | null) => {
const event =
eventOrAnchorEl instanceof Element ? undefined : eventOrAnchorEl
Expand All @@ -197,14 +206,6 @@ export function usePopupState({
return
}

const doClose = (state: CoreState): CoreState => {
const { _childPopupState } = state
setTimeout(() => {
_childPopupState?.close()
parentPopupState?._setChildPopupState(null)
})
return { ...state, isOpen: false, hovered: false, focused: false }
}
setState((state: CoreState): CoreState => {
if (state._deferNextClose) {
setTimeout(() => setState(doClose), 0)
Expand All @@ -213,8 +214,7 @@ export function usePopupState({
return doClose(state)
}
})
},
[]
}
)

const setOpen = useCallback(
Expand Down Expand Up @@ -244,7 +244,7 @@ export function usePopupState({
if (state.focused) {
return { ...state, hovered: false }
} else {
close(event)
return doClose(state)
}
}
return state
Expand All @@ -265,7 +265,7 @@ export function usePopupState({
if (state.hovered) {
return { ...state, focused: false }
} else {
close(event)
return doClose(state)
}
}
return state
Expand Down

0 comments on commit 438f507

Please sign in to comment.