-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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 #4878
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ This pull request was sent to the PullRequest network for review. Expert reviewers are now being matched to your request based on the code's requirements. Stay tuned!
What to expect from this code review:
- Comments posted to any areas of potential concern or improvement.
- Detailed feedback or actions needed to resolve issues that are found.
- Turnaround times vary, but we aim to be swift.
@balajis-qb you can click here to see the review status or cancel the code review job.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PullRequest Breakdown
Reviewable lines of change
+ 91
- 1
55% TSX (tests)
45% TSX
Type of change
Fix - These changes are likely to be fixing a bug or issue.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #4878 +/- ##
==========================================
+ Coverage 96.72% 96.73% +0.01%
==========================================
Files 28 28
Lines 2990 3004 +14
Branches 1293 1293
==========================================
+ Hits 2892 2906 +14
Misses 98 98 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The updates here look good and are aligned with the description of the problem and change. As long as the testing of retrieval from the document are working as expected this appears to be good to go.
Reviewed with ❤️ by PullRequest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes look good overall, however I added a comment about a non-null assertion that may be preferable to handle without that assertion for safer coding practices.
Reviewed with ❤️ by PullRequest
test/datepicker_test.test.tsx
Outdated
@@ -73,6 +73,41 @@ describe("DatePicker", () => { | |||
jest.resetAllMocks(); | |||
}); | |||
|
|||
it("should retain the calendar open status when the document visibility change", () => { | |||
const { container } = render(<DatePicker />); | |||
const input = container.querySelector("input")!; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ISSUE: @typescript-eslint/no-non-null-assertion (Severity: Low)
Forbidden non-null assertion.
Remediation:
The suggestion is to change the function to not rely on the non-null assertion:
it("should retain the calendar open status when the document visibility changes", () => {
const { container } = render(<DatePicker />);
const input = container.querySelector("input");
if (input) {
fireEvent.click(input);
expect(container.querySelector(".react-datepicker")).toBeTruthy();
jest.spyOn(document, "visibilityState", "get").mockReturnValue("hidden");
fireEvent(document, new Event("visibilitychange"));
jest.spyOn(document, "visibilityState", "get").mockReturnValue("visible");
fireEvent(document, new Event("visibilitychange"));
expect(container.querySelector(".react-datepicker")).toBeTruthy();
} else {
throw new Error("Input element not found");
}
});
🤖 powered by PullRequest Automation 👋 verified by Jonah
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you Jonah for your review. I updated the code as per your suggestion.
a393ec2
to
59a42e3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Closes #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