fix(#1511) fix click outside popover #2344
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before (the change)
Dropdown uses Popover to show the list of options. Popovers had an invisible background behind them that user could click to close the popover. This prevented a user from clicking on anything behind the invisible background, like a hyperlink for example, until they clicked once to close the popover. This does not happen with a regular select. This problem affected Popover, Dropdown, AppHeader, AppHeaderMenu, and DatePicker.
After (the change)
Popover no longer has an invisible background and the component now handles a
focusout
event to decide if popover should be closed. Now it is possible to click outside of a popover to immediately interact with other elements, which is how a native select behaves:1211-fix-click-outside-popover.mp4
Technical info
Popover no longer has an invisible background and the component now handles a
focusout
event for the same behavior. If the popover container or any element within that container loses focus, thenfocusout
event bubbles up. It bubbles up from slotted children. When handlingfocusout
it checks if the now active element is contained within the popover container by recursively looking down within nested slots. Whenever a popover open it also checks in the default slot used for content to see if any immediate children do not have tabindex set and if not then it adds tabindex="-1" which allows thefocusout
event to bubble up from these non-focusable elements. Another key change that was made is to always render popover contents to the DOM that are hidden when popover is closed.. previously it would not render those contents to the DOM, which was fine most of the time but causes edge case problems. This change makes the page more accessible, making it an additional fix. Take dropdown for example: the contents of a dropdown's options are now always part of the DOM just like how a native select options are always part of the DOM, so I think this is a positive change, and fwiw this change was needed to make Datepicker work well. Previously in DatePicker when you had one of its Month or Year dropdowns expanded, then if you click outside the calendar to collapse the entire Calendar popover, that dropdown will remain expanded next time the Calendar popover opens. This no longer happens.Make sure that you've checked the boxes below before you submit the PR
Steps needed to test
Try this out with Dropdown, DatePicker, or the dropdown navigation within the App Header Menu. While any dropdown, datepicker, or sub-navigation is expanded, try clicking anywhere inside of the expanded content and it should not collapse. Then try clicking outside of the expanded content and it should collapse. This is all demonstrated in the video.