Skip to content

HoverPopover does not close with fast mouse movements #67

Closed
@Stromij

Description

@Stromij

Hello everyone,

I'm trying to use the HoverPopover on several components. To do so I used the Popover-Example from the docs and adapted it to render more than one button:

import * as React from 'react'
import Button from '@material-ui/core/Button'
import { usePopupState, bindHover, bindPopover } from 'material-ui-popup-state/hooks'
import { Typography } from '@material-ui/core'
import Popover from 'material-ui-popup-state/HoverPopover'

const PopoverText = () => {
    const popupState = usePopupState({
        variant: 'popover',
        popupId: 'demoPopover',
    })

    return (
        <div>
            <Button variant="contained" {...bindHover(popupState)}>
                Open Popover
            </Button>
            <Popover
                {...bindPopover(popupState)}
                anchorOrigin={{
                    vertical: 'bottom',
                    horizontal: 'center',
                }}
                transformOrigin={{
                    vertical: 'top',
                    horizontal: 'center',
                }}
            >
                <Typography>
                    The content of the Popover.
                </Typography>
            </Popover>
        </div>
    )
}

export const TwoTablesNoCollapse = ({ ...args }) => (
    <>
        <PopoverText />
        <PopoverText />
        <PopoverText />
        <PopoverText />
        <PopoverText />
        <PopoverText />
        <PopoverText />
        <PopoverText />
        <PopoverText />
        <PopoverText />
    </>

);

Everything works fine, except with fast mouse movements. The showing popover does not disappear anymore. To get an idea of what I mean I add a small video:

Peek 2021-06-28 13-01

This is a problem because the Popover itself blocks any scroll events as mentioned in another issue (#37). This way, the page is not scrollable until the user closes the Popover by revisiting the corresponding element with the mouse.

I found the following as a workaround in this particular case

    return (
        <div onMouseLeave={popupState.close}>
            <Button variant="contained" {...bindHover(popupState)}>
                Open Popover
            </Button>

but since this is just a toy-example and I need to use this in a table on each table cell, I cannot wrap every table cell in a div (or something similar) without effecting the layout.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions