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

In nested popovers with ListView, closing nested popover from ListView's onSelectionChange causes both popovers to close #4027

Closed
richiepreece opened this issue Feb 7, 2023 · 4 comments

Comments

@richiepreece
Copy link

🐛 Bug Report

In nested popovers with ListView, closing nested popover from ListView onSelectionChange causes both popovers to close

🤔 Expected Behavior

Only the 2nd popover should close

😯 Current Behavior

It appears as though closing the popover from onSelectionChange does not stop the Overlay's onInteractionOutside from firing. But since the popover closed, the next available popover to check is the original (non-closing) popover. This means that both popovers end up closing.

Weirdly enough, if you click the ListVIew Item's checkbox, the behavior does not exhibit. You have to click the label.

💁 Possible Solution

n/a

🔦 Context

While opening popovers from popovers may be advised against. It does (and will) happen. This issue was mitigated by adding a 0-length timeout before the close method to get the close after the onInteractionOutside method.

i.e.

// Broken:
close();
// Mitigated:
setTimeout(() => close());

💻 Code Sample

Code sandbox example

🌍 Your Environment

Software Version(s)
react-spectrum 3.24.1
Browser Chrome
Operating System MacOS

🧢 Your Company/Team

Adobe Analytics (Workspace Analysis)

@snowystinger
Copy link
Member

Could you perhaps not close on selection change? That happens on pointer down. Usually, actions in modals are taken on pointer up. For example, clicking a menu item.

You could attach an onPointerUp to the document after a selection change? Or you could add a close/confirm button.

@richiepreece
Copy link
Author

richiepreece commented Feb 7, 2023

That feels pretty clunky to keep track of. An action on selection (which is a UX requirement rather than a button) is going to be far more common than doing the selection, keeping track of if one just occurred, and then determining if it should close based on if a selection was made, and then doing the action after that.

@snowystinger
Copy link
Member

I don't disagree, however, I'm fairly sure that what you're running into is actually a browser bug. See this issue for more information #1513

We haven't determined a way to solve it generically in RSP.

I think the delay of 0 before closing is fine. Otherwise, there are suggestions in my previous comment.

@richiepreece
Copy link
Author

Ah. Yeah that does seem related. I’ll probably stick with the timeout for ease of readability. Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants