RFC: Popup more intuitive behavior with multiple `on` events
Bug Report
The problem happens when using multiple events to trigger Popup.
Can be reproduced with <Popup trigger={<button>Show tooltip</button>} content='tooltip' on={['click', 'hover']} but the easiest way is with <Popup trigger={<button>Show tooltip</button>} content='tooltip' on={['click', 'focus']}.
Just try clicking the button. For the first time, it opens the popup and immediately closes it. Following clicks work correctly.
This problem has been mentioned in #2075 by @austinfox here.
Steps
- Go to Semantic UI React Popup demo.
- Edit e.g. first example
Popupcomponent to contain multiple on events i.e.on={['click', 'focus']}. - Click the popup trigger.
Expected Result
Popup is displayed and stays open.
Actual Result
Popup is displayed and closed immediately.
Version
0.80.0
Testcase
Check the steps section above.
👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you've completed all the fields in the issue template so we can best help.
We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.
I'm not sure this is a bug necessarily. The order of events in the browser when clicking a button is click then focus. What is happing is technically correct, though not helpful. The first event, click, opens the popup while the immediate second event, focus, closes it again.
The on prop toggles the popup on the given events. There are a few ways this could be reworked to give more intuitive results.
openOn / closeOn
Splitting or adding these props would allow you to specify which events should open and close the popup. You'd apply focus to the openOn and click to both openOn and closeOn. This way, focus only opens the popup.
Special focus/blur handling
This might be the more desirable solution. Focus could strictly open the popup and blur could strictly close it. This is not technically the correct behavior given the prop config of "toggle on focus", however, it does give a more intuitive behavior. I would think most users would expect focus to open the popup.
I'd like to hear thoughts and feedback on these and any other solutions folks may have.
@levithomason: I agree with latter proposal (special focus/blur handling) as it complies with accessibility guidelines - receiving focus should show the popup or tooltip and blur should hide it.
Agreed! A PR implementing open on focus and close on blur is welcome.
I would like to help but the main problem I see is to determine what triggered the focus. Whether it was the TAB key or mouse click.
- When tabbing it's easy as there is just
focusevent fired. - In case of click, first
focusevent is triggered followed byclickevent. That is at least what happens in Firefox and Chrome, could be different for other browsers. I think in Safari on Mac thefocuswas not fired at all when clicking element, but I can't test it now.
I found the same issue at StackOverflow. It seems that there is no easy and clean solution for this kind of problem.
There has been no activity in this thread for 90 days. While we care about every issue and we’d love to see this fixed, the core team’s time is limited so we have to focus our attention on the issues that are most pressing. Therefore, we will likely not be able to get to this one.
However, PRs for this issue will of course be accepted and welcome!
If there is no more activity in the next 90 days, this issue will be closed automatically for housekeeping. To prevent this, simply leave a reply here. Thanks!
This issue will be closed due to lack of activity for 12 months. If you’d like this to be reopened, just leave a comment; we do monitor them!
This issue will be closed due to lack of activity for 12 months. If you’d like this to be reopened, just leave a comment; we do monitor them!