-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[Feature Request] NextUI V2, When user opens dropdown/popup, close the another dropdown/popup #1287
Comments
Hey @alibabayev0 could you send a repo/codesandbox/stackblitz ?, I couldn't replicate this issue, on the other hand, we rely on @react-aria overlays implementations which already has a context to control which modals/popovers are visible https://github.com/adobe/react-spectrum/blob/main/packages/%40react-aria/overlays/src/useOverlay.ts#L79-L86 |
Hey, @jrgarciadev, check this out: https://codesandbox.io/p/sandbox/eager-fog-l9smkq. In the simplified version, I noticed we need to place the button within the Dropdown trigger, or it won't work correctly. I believe you've already implemented this, but just in case, it might be good to handle 'div' and other view types as well. |
I found |
I also tried out using I did look into the code and it looks like their using Adobe's React Spectrum, specifically the useOverlay. In the React Spectrum's issue page a fix to this issue has been discussed here. But it appears there is no solution currently. But I currently do not see away to make the click away from a dropdown also be an event to activate a new dropdown. If anyone knows a fix let me know. @alibabayev0 I was unable to replicate the effect where you when you click away, it activates the other popup. How were you able to do this? |
Here is a solution I developed. Honestly, not sure why it works but it does. import { Dropdown as NativeDropdown, DropdownProps } from "@nextui-org/react";
import React from "react";
import { useState } from "react";
export function Dropdown(props:DropdownProps) {
const [visible, setVisible] = useState(false);
return (
<NativeDropdown
{...props}
isOpen={visible}
onOpenChange={(isOpen) => setVisible(isOpen)}
shouldCloseOnInteractOutside={() => {
setVisible(false);
return false;
}}
/>
);
} |
I agree that this part of the API is extremely counter-intuitive. This is a more generic hook version I use to fix it:
defined as:
EDITED: I added an escape key listener, because that doesn't seem to be working correctly either. |
Is your feature request related to a problem? Please describe.
Yes, when a user opens a modal or popup while another modal/popup is already open, it can create confusion or lead to visual clutter. Multiple overlays can be distracting, and the user might not know which modal to focus on. It can also lead to potential UI glitches, especially when z-index values or other styles conflict between multiple modals.
Describe the solution you'd like
I'd like the nextui dropdown/popupover components to have built-in functionality that ensures only one dropdown or popup is visible at a given time for specific key or same labeled.
Can be resolved with: Context || DOM Events etc
Describe alternatives you've considered
.
Screenshots or Videos
No response
The text was updated successfully, but these errors were encountered: