Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #4844: 🔨 Retain the open state of the calendar popup on document visibility change #23

Conversation

balajis-qb
Copy link
Collaborator

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

  1. Switching the browser tab after we enter the date manually into the calendar input by dismissing the calendar popup
  2. Switching the tab immediately after selecting any date via calendar popup (In this case, we could have blurred focus from the input, but when I inspect the code, we intentionally refocus the calendar input, upon selection of any date from the calendar popup as a fix for the issue Calendar pop-up window does not close if using Macbook touchpad Hacker0x01/react-datepicker#628)

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 state

Changes
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 browser visibilitychange, I used the previous open state to decide whether to re-open the calendar popup or not.

  • This fix helps us to keep the calendar open, when it was opened before the browser tab switch
  • This fix also helps us to avoid re-open the calendar popup unnecessarily when it doesn't get opened before the browser tab switch

Basically the solution I suggested helps to retain the previous open state of the calendar popup whenever the browser gets re-opened.

Contribution checklist

  • I have followed the contributing guidelines.
  • I have added sufficient test coverage for my changes.
  • I have formatted my code with Prettier and checked for linting issues with ESLint for code readability.

@balajis-qb balajis-qb force-pushed the issue-4844/fix/retain-calendar-open-state-on-document-visibility-toggle branch from a393ec2 to 59a42e3 Compare June 7, 2024 18:40
@balajis-qb balajis-qb merged commit 186c289 into main Jun 17, 2024
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Input blur after date select
1 participant