react-contexify
react-contexify copied to clipboard
Open menu without clicking
I want to programmatically open the menu on component load. I can call contextMenu.show(), but it requires an event. Right, I am trying something like this, for a menu to open at the right bottom corner of my element:
const {bottom, right} = element.getBoundingClientRect()
const event = new MouseEvent('click', {
clientX: bottom,
clientY: right,
})
contextMenu.show({
...
event,
...
})
but the menu opens at unexpected places on the screen. Is there a way to omit passing the event altogether and instead pass coordinates? Do you have any tips for this use case? Thank you!
In the end, only a small change was necessary:
const {x, y, width, height} = element.getBoundingClientRect()
const event = new MouseEvent('click', {
clientX: x + width,
clientY: y + height,
})
contextMenu.show({
...
event,
...
})