mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 14:13:43 +01:00
Show tooltip immediately if a tooltip is already open (#28870)
* Memoize delayProps * Refactor Escape key handler * Use useTooltipContext * Remove delay: 0 from tooltips * Only use isTooltipOpen if available * Only show transition for initial tooltip GitOrigin-RevId: 74950ea7e705acb8f42dea552b23ce93c66058c7
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import {
|
||||
createContext,
|
||||
Dispatch,
|
||||
FC,
|
||||
PropsWithChildren,
|
||||
SetStateAction,
|
||||
useContext,
|
||||
useMemo,
|
||||
useState,
|
||||
} from 'react'
|
||||
import useDebounce from '@/shared/hooks/use-debounce'
|
||||
|
||||
const TooltipContext = createContext<
|
||||
| {
|
||||
isTooltipOpen: boolean
|
||||
setIsTooltipOpen: Dispatch<SetStateAction<boolean>>
|
||||
}
|
||||
| undefined
|
||||
>(undefined)
|
||||
|
||||
export const TooltipProvider: FC<PropsWithChildren> = ({ children }) => {
|
||||
const [isTooltipOpen, setIsTooltipOpen] = useState(false)
|
||||
|
||||
const debouncedIsTooltipOpen = useDebounce(isTooltipOpen, 100)
|
||||
|
||||
const value = useMemo(
|
||||
() => ({
|
||||
isTooltipOpen: debouncedIsTooltipOpen,
|
||||
setIsTooltipOpen,
|
||||
}),
|
||||
[debouncedIsTooltipOpen, setIsTooltipOpen]
|
||||
)
|
||||
|
||||
return (
|
||||
<TooltipContext.Provider value={value}>{children}</TooltipContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export const useTooltipContext = () => {
|
||||
return useContext(TooltipContext)
|
||||
}
|
||||
Reference in New Issue
Block a user