[Dropdown] How to call the "close" function by hand? #1811
-
Hello, In a project, I have a Dropdown which only displays on my mobile version. I've started to write some code: const isLargeScreen = useMediaQuery(`(min-width: ${getBreakpoint('lg')}px)`);
const handleOpenChange = (opened: boolean) => setIsMenuOpen(opened);
// * ... (1)
useEffect(() => {
if (isLargeScreen) setIsMenuOpen(false);
}, [isLargeScreen]);
return (
<Dropdown
showArrow={true}
backdrop="blur"
closeOnSelect={false}
onOpenChange={handleOpenChange}
// * ... I would like to know what I should append to the (1) useEffect. ^^' |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
EDIT: The standard way is to append the <Dropdown
isOpen={isOpened} // * ... Here!
// * ... I hacked it like this for now: <Dropdown
showArrow={true}
closeOnSelect={false}
onOpenChange={handleOpenChange}
className="py-1 px-1 border dark:border-black dark:bg-slate-950"
classNames={{ arrow: 'dark:bg-slate-800' }}
key={`dropdown-hack-in-the-matrix-${isLargeScreen}`}
> Here, the Btw: thanks to this magic, the Even if it is absolutely not standard, I will select this message as answer for now. Note: this answer has been inspired from a discussion with the kapa.ai instance of the NextUI Discord server. A good resource to understand why this hack works so good (even if it has the drawback to trigger a full re-mount...): (11:32) |
Beta Was this translation helpful? Give feedback.
-
Hey @gustaveWPM the Dropdown component is based on the Popover, which means that you can control the open state by using the |
Beta Was this translation helpful? Give feedback.
Hey @gustaveWPM the Dropdown component is based on the Popover, which means that you can control the open state by using the
isOpen
property https://nextui.org/docs/components/popover#controlled