-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delay Before Popover Appears #85
Comments
sorry for the delay. I'm busy with work stuff so it will take me awhile to look into this. I'd be open to a PR if I don't get to it first |
Did this ever get implemented? |
+1 for this |
+1 |
I wonder has anyone found a work around to achieve this? |
+1.
A workaround might be to wrap the event handlers returned from export function bindDelayedHover(popupState: PopupState, delayMs = 200) {
const { onTouchStart, onMouseOver, onMouseLeave, ...hoverAriaProps } =
bindHover(popupState);
const timeout = useRef<NodeJS.Timeout | null>(null);
const delayedMouseOver = useCallback(
(e: React.MouseEvent) => {
if (timeout.current) clearTimeout(timeout.current);
// material-ui-popup-state's event handler uses currentTarget to set the anchorEl, but
// currentTarget is only defined while the initial event is firing. Save the original
// and set it again before calling the delayed event handler
const { currentTarget } = e;
timeout.current = setTimeout(() => {
e.currentTarget = currentTarget;
onMouseOver(e);
}, delayMs);
},
[onMouseOver]
);
const handleMouseLeave = useCallback(
(e: React.MouseEvent) => {
if (timeout.current) clearTimeout(timeout.current);
onMouseLeave(e);
},
[onMouseLeave]
);
return {
onTouchStart,
onMouseOver: delayedMouseOver,
onMouseLeave: handleMouseLeave,
...hoverAriaProps,
};
} Sample usage: const popupState = usePopupState({
variant: "popover",
popupId: "example"
});
return (
<>
<span {...bindDelayedHover(popupState, 500)}>
Example Hover
</span>
<HoverMenu
{...bindMenu(popupState)}
... |
This comment was marked as off-topic.
This comment was marked as off-topic.
this works for me with some adjustment based on @mfen answer const timeout = useRef<NodeJS.Timeout | null>(null);
const handleOnMouseEnter = (
e: React.MouseEvent<HTMLElement>,
onMouseOver: (e: React.MouseEvent<HTMLElement>) => void
) => {
if (timeout.current) {
clearTimeout(timeout.current);
}
const currentTarget = e.currentTarget;
timeout.current = setTimeout(() => {
e.currentTarget = currentTarget;
onMouseOver(e);
}, 500);
};
const handleMouseLeave = (e: React.MouseEvent, onMouseLeave: (event: React.MouseEvent) => void) => {
if (timeout.current) {
clearTimeout(timeout.current);
}
onMouseLeave(e);
};
<PopupState variant="popover" popupId="demo-popup-popover">
{popupState => {
const { onMouseLeave, onMouseOver, ...rest } = bindHover(popupState);
return (
<div>
<Box
{...rest}
onMouseOver={e => handleOnMouseEnter(e, onMouseOver)}
onMouseLeave={e => handleMouseLeave(e, onMouseLeave)}
>
{label}
</Box>
...
</div>
);
}}
</PopupState>
|
I'm trying to do the reverse of this issue where there is a delay before disappearing, especially for a cascading menu use case. if anyone has any ideas, let me know #149 |
for the Mouse Over Interaction is it possible to have a delay (for debounce purposes) before the popover appears? i.e. Instead of the content showing up immediately, a user has to hover for about 800ms before the popover shows up.
Transition duration doesn't work because that just delays the animation, an 800ms transitionDuration just makes the fade come in over 800ms.
The text was updated successfully, but these errors were encountered: