[ch-popover] Fix issues related with the positioning of the popover
#562
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.
Changes we propose in this PR
Use the viewport size, instead of the whole document size to properly position the popover.
When the document has scrollbars, the
ch-popoverwas not positioned correctly because the entire document size was used instead of the viewport size.Properly calculate the
ch-popover's max size.We were always using the max size of the CSS custom vars if they were defined.
Add support to re-position the
ch-popoverwhen the browser's window is resized.Add support to close the popover if it is no longer visible.
Add support to know the reason of the
popoverClosedevent.The
reasonproperty of the event provides more information about the cause of the closing:"click-outside": The popover is being closed because the user clicked outside the popover when usingcloseOnClickOutside === trueandmode === "manual"."escape-key": The popover is being closed because the user pressed the "Escape" key when usingcloseOnClickOutside === trueandmode === "manual"."popover-no-longer-visible": The popover is being closed because it is no longer visible."toggle": The popover is being closed by the native toggle behavior of popover. It can be produced by the user clicking theactionElement, pressing the "Enter" or "Space" keys on theactionElement, pressing the "Escape" key or other. Used whenmode === "auto".Avoid emitting duplicated
popoverClosedevent.This fixes emitting the duplicated event in the following scenarios:
The "Escape" key is pressed in
mode === "manual".The user clicks outside the popover in
mode === "manual".The
showproperty is changed tofalseexternally.The user scrolls the window and the popover is no longer visible.