You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to open a Menu programatically by passing a ref to MenuButton and calling ref.current.click(). This does not seem to work anymore with React 19.
functionMyComponent(){constmenuButtonRef=useRef(null);// Open the menu with the cmd-K shortcutuseEffect(()=>{constonKeydown=(e: KeyboardEvent)=>{if((e.key==='k'||e.key==='K')&&(e.metaKey||e.ctrlKey)){e.preventDefault();console.log('cmd-K');// This logs as expectedmenuButtonRef.current?.click();// This does nothing}};document.addEventListener('keydown',onKeydown);return()=>document.removeEventListener('keydown',onKeydown);},[]);return(<Menu><MenuButtonref={menuButtonRef}>
Button
</MenuButton><MenuItemsanchor={{to: 'bottom start',gap: 4}}modal={false}>
...
</MenuItems></Menu>}
This discussion was converted from issue #3705 on April 25, 2025 09:18.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
What package within Headless UI are you using?
@headlessui/react
What version of that package are you using?
v2.2.2
What browser are you using?
For example: Chrome
Describe your issue
I'm trying to open a Menu programatically by passing a ref to MenuButton and calling
ref.current.click()
. This does not seem to work anymore with React 19.Beta Was this translation helpful? Give feedback.
All reactions