Fix #4844: 🔨 Retain the open state of the calendar popup on document visibility change #23
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.
Closes Hacker0x01#4844
Description
Retain the open state of the calendar popup on document visibility change.
Problem
As mentioned in the issue description, the calendar gets auto-reopen whenever we switch the browser tab and switch back to the original tab in any of the below 2 cases
In any of the above cases the input is focused while switching the browser tab and when we switch back to the original tab, the browser refocus the calendar input, which will trigger our
handleFocus
handler in our code and we open the calendar popup regardless of it's previous open stateChanges
As a fix, I listened for the
visibilitychange
event and note whenever the tab gots hidden. Whenever the input gets refocused, if it gets auto re-focused because of the browservisibilitychange
, I used the previous open state to decide whether to re-open the calendar popup or not.Basically the solution I suggested helps to retain the previous open state of the calendar popup whenever the browser gets re-opened.
Contribution checklist