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 #5200: Fix the unnecessary highlight on the Week Number when the first day of the week is selected using Keyboard #5232

Merged

Conversation

balajis-qb
Copy link

Closes #5200

Description

As mentioned in the ticket, when showWeekNumbers is enabled in a datepicker, the keyboard select on the first day of the week alone highlights the week number. When we select any other week days it's not highlighting. This issue is not occuring in the mouse hover of any week days.

Why the issue occurs?

image

As I shared in the above screenshot, we passed the start of the week to each corresponding week number and in the <WeekNumber /> component we apply a class react-datepicker__week-number--keyboard-selected when the date prop (which is start of the week) is selected.

Changes

  • As a fix, I removed the setting of react-datepicker__week-number--keyboard-selected to . The reason is because we are not applying any class to it when we hover the first day of the week using mouse. Also if we plan to highlight the week number it should enabled for all week days and not just the start date and it should be applied to the mouse hover aswell. But I don't think that's necessary as the week number we're displaying is just looks like a read-only kind of view, as it's grayed out currently. Hence I feel removing the class react-datepicker__week-number--keyboard-selected would be a better way to fix the issue.
  • I also updated the existing test cases

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.

Copy link

@pullrequest pullrequest bot left a 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.

Copy link

@pullrequest pullrequest bot left a 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

+ 37
- 50

69% SCSS
29% TSX (tests)
2% TSX

Type of change

Fix - These changes are likely to be fixing a bug or issue.

Copy link

codecov bot commented Nov 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.89%. Comparing base (30babb9) to head (9f86dd4).
Report is 18 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5232   +/-   ##
=======================================
  Coverage   96.89%   96.89%           
=======================================
  Files          29       29           
  Lines        3381     3381           
  Branches     1401     1414   +13     
=======================================
  Hits         3276     3276           
  Misses        105      105           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code change looks good, there may be some opportunities to improve test coverage and remove dead code

Image of Tyler A Tyler A


Reviewed with ❤️ by PullRequest

@@ -383,59 +368,6 @@ describe("WeekNumber", () => {
),
).toBe(false);
});

it("should have the class 'react-datepicker__week-number--selected' if selected is not current week and preselected is current week", () => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we salvage parts of this test that are still relevant?

🔸 Improve Test Coverage (Important)

Image of Tyler A Tyler A

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this catch. As per your suggestion, I retained test cases of react-datepicker__week-number--selected.

@@ -120,8 +120,6 @@ export default class WeekNumber extends Component<WeekNumberProps> {
"react-datepicker__week-number--clickable": !!onClick,
"react-datepicker__week-number--selected":
!!onClick && isSameDay(this.props.date, this.props.selected),
"react-datepicker__week-number--keyboard-selected":
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also remove the css corresponding to this class?

🔹 Dead Code (Nice to have)

Image of Tyler A Tyler A

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the CSS part of react-datepicker__week-number--keyboard-selected.

@balajis-qb balajis-qb force-pushed the issue-5200/fix/week-number-highlight branch from ce8508f to ceebc36 Compare November 18, 2024 08:07
… for the <WeekNumber /> component

- Removed as highlighting the first day of the week alone highlights the week number - Because we set the date prop of the <WeekNumber /> to first date of the week.  As a result this highlight will work only for the first day of week
@balajis-qb balajis-qb force-pushed the issue-5200/fix/week-number-highlight branch from ceebc36 to 9f86dd4 Compare November 18, 2024 08:22
@balajis-qb
Copy link
Author

Hi,
I updated the code as per your suggestions. Can you please confirm the changes I made? So that it'll be ready for merging.

@martijnrusschen martijnrusschen merged commit e479fc3 into Hacker0x01:main Nov 24, 2024
6 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.

Week number is highlighted when on first day of the week navigating using arrow keys
2 participants