fkhadra / fkhadra/react-contexify

A small note on close event listeners

Open
#228 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
1.2k
Forks
132
PR merge metrics
No merged PRs in 30d

Description

Currently all the event listeners that handle close are set to be handled at bubbling phase.
```js
if (state.visible) {
window.addEventListener('keydown', handleKeyboard);

for (const ev of hideOnEvents) window.addEventListener(ev, hide);
}
```

**Will there be any unintended consequences if we take the approach mentioned below?**
Change all the events to be handled during capture phase, this offers us the following advantages:
- scroll: the behavior gets inline with the browser's default context menu
- works with any scroll action (even when there is no scroll bar). This should fix #161.
- works even when scroll happens anywhere on the screen. Consider a two column layout where the right one has the context menu and the left one has a scroll. The menu will close when the scroll happens in the left column(browser's default context menu works like this).
- other events: there might be few elements on the screen which might do stopPropagation and prevent the context menu from closing. capturing the event fixes this issue.

Also adding a mousedown event would be helpful in cases where we have elements that are draggable.

I would be happy to work on this if you are okay with this.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.