Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkg/lib: fix context menu component popdown
f9b0166 changed the popdown behaviour of the context menu. Before that commit, the previous code was wrong. It was: const wasOutside = !(event.target.contains === root.current); if (wasOutside) setVisible(false); but because `event.target.contains` is a function, the comparison was always false and wasOutside would always be true. This meant that any left click would always pop the menu down. The replacement code was: const wasOutside = !event.target.contains(root.current); which at least looks like it does something meaningful. Unfortunately this is also wrong, but in the other direction: this means that the menu will only pop down if it's not contained inside of the item you've clicked on. If you click on a large top-level <div> (ie: something which effectively contains "most things") then the menu will remain shown. That's definitely wrong. We seemed to be happy with the behaviour before the original change, but the code has a purpose: it allows clicking on content of the menu (like on a divider, for example) without dismissing it. Let's try to implement the intended original behaviour: we should dismiss the menu only if the element that we clicked on is outside of the menu: const wasOutside = root.current && !root.current.contains(event.target); Fixes #20649
- Loading branch information