-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Dropdown: closing Dropdown inside a Modal by clicking Escape also closes Modal #3194
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
Comments
👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you've completed all the fields in the issue template so we can best help. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can. |
Hey @vkramskikh , try to add this on modal component: It should work :) |
Sure it will work. But I want it to close on escape, just not when Dropdown is open and users want the Dropdown to close, not the Modal. Same applies to Enter key - users want to choose item in the Dropdown, not to submit the form in Modal |
I think you should handle escape event by props onClose Modal could have any Component, So It can't decide to ignore which escape event come from |
@vkramskikh , I had a similar problem. If a certain input field inside my modal was visible, I wanted to close it with escape. Otherwise I wanted the modal to close as normal with escape.
NewModifierGroup:
|
There has been no activity in this thread for 180 days. While we care about every issue and we’d love to see this fixed, the core team’s time is limited so we have to focus our attention on the issues that are most pressing. Therefore, we will likely not be able to get to this one. However, PRs for this issue will of course be accepted and welcome! If there is no more activity in the next 180 days, this issue will be closed automatically for housekeeping. To prevent this, simply leave a reply here. Thanks! |
I think that adding |
You can solve this by making the dropdown controlled and making const [isDropdownOpen, setIsDropdownOpen] = useState(false);
...
<Modal closeOnEscape={!isDropdownOpen}>
<Dropdown
open={isDropdownOpen}
onOpen={() => setIsDropdownOpen(true)}
onClose={() => setIsDropdownOpen(false)}
/>
</Modal> |
@mattjcl Your solution worked well for me, but... I wouldn't recommend to use Therefore, my working solution is: const [isDropdownOpen, setIsDropdownOpen] = useState(false);
...
<Modal closeOnEscape={!isDropdownOpen}>
<Dropdown
onOpen={() => setIsDropdownOpen(true)}
onClose={() => setIsDropdownOpen(false)}
/>
</Modal> |
Bug Report
There is no way to prevent an event triggered by a Dropdown to affect a Modal containing it. Reproduces with Escape, Enter and other keys/events.
Steps
Expected Result
Dropdown is closed, Modal is open
Actual Result
Modal is closed
Version
0.82.5
Testcase
https://codesandbox.io/s/9y8vzn4nvr
The text was updated successfully, but these errors were encountered: