Skip to content
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

[docs] Demo VirtualElementPopper crashes #34450

Closed
1 task
jakekh opened this issue Sep 23, 2022 · 5 comments
Closed
1 task

[docs] Demo VirtualElementPopper crashes #34450

jakekh opened this issue Sep 23, 2022 · 5 comments
Assignees
Labels
component: Popper The React component. See <Popup> for the latest version. docs Improvements or additions to the documentation duplicate This issue or pull request already exists

Comments

@jakekh
Copy link

jakekh commented Sep 23, 2022

Steps to Reproduce

  1. Visit https://mui.com/material-ui/react-popper/
  2. highlight some text and open the popper
  3. click outside the typography component before the popper is hidden by the onMouseLeave event runs
  4. or just run the demo with out that onMouseLeave event attached and click anywhere other than the text while the popper is open
  5. demo VirtualElementPopper crashes

Your Environment

Tech Version
MUI v5.10.6
Netlify deploy https://63287dcb7cfef00009bcbe8a--material-ui-docs.netlify.app
Browser Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36
@mnajdova mnajdova added docs Improvements or additions to the documentation component: Popper The React component. See <Popup> for the latest version. status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Sep 26, 2022
@mnajdova mnajdova self-assigned this Sep 26, 2022
@mnajdova
Copy link
Member

I couldn't reproduce this on Chrome, Mozilla nor Edge. I've used both Light and Dark mode. Could you maybe share more info about your interactions with the docs before the demo crashed?

@mnajdova mnajdova added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Sep 26, 2022
@jakekh
Copy link
Author

jakekh commented Sep 26, 2022

Did you remove the mouse leave event and try clicking outside the typography component while the popper is open?

Anyways, I was able to figure out a workaround, it appears the demo uses a mouse leave event to close the popper because there is a conflict when the popper is open and the "selection.getRangeAt(0).getBoundingClientRect()" is still running in the popper.

So I added a "setTimeout, 0" to make it run faster, then I added the clickAway thing to close the popper because it doesn't have this functionality built in and without the mouse leave event it will not close when you click anywhere else. I also changed the "getBoundingClientRect" to be a value instead of passing a function to the popper so it will stop trying to run on its own.

Here's my code:

const handleClose = () => {
	setOpen(false);
};
const checkSelection = () => {
	setTimeout(() => {
		const selection = window.getSelection();

		if(!selection || selection.anchorOffset === selection.focusOffset) {
			handleClose();
			return;
		}

		const rect = selection.getRangeAt(0).getBoundingClientRect();

		const getBoundingClientRect = () => rect;

		setOpen(true);
		setAnchorEl({getBoundingClientRect});
	}, 0);
};

return (
	<Container
		maxWidth={false}
		sx={{bgcolor: "background.paper", minHeight: 100}}
	>
		<ClickAwayListener onClickAway={handleClose}>
			<div>
				<div onMouseUp={checkSelection} style={{padding: 16}}>
					<Typography>{content}</Typography>
				</div>
				<Popper
					open={open}
					anchorEl={anchorEl}
					transition
					placement="bottom"
					sx={{zIndex: 1}}
				>
					{({ TransitionProps  }) => (
						<Fade {...TransitionProps } timeout={350}>
							<ButtonGroup onMouseDown={(e) => e.preventDefault()}>
								{buttons}
							</ButtonGroup>
						</Fade>
					)}
				</Popper>
			</div>
		</ClickAwayListener>
	</Container>
);

Let me know what you think!

@github-actions github-actions bot removed the status: waiting for author Issue with insufficient information label Sep 26, 2022
@michaldudak
Copy link
Member

This looks like a duplicate of #32106.

@jakekh
Copy link
Author

jakekh commented Oct 13, 2022 via email

@michaldudak
Copy link
Member

Duplicate of #32106

@michaldudak michaldudak marked this as a duplicate of #32106 Oct 28, 2022
@michaldudak michaldudak closed this as not planned Won't fix, can't repro, duplicate, stale Oct 28, 2022
@github-actions github-actions bot added the duplicate This issue or pull request already exists label Oct 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: Popper The React component. See <Popup> for the latest version. docs Improvements or additions to the documentation duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants