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: #4489 Disable weekNumber highlighting when no click handler is assigned. #4608

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/week_number.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,8 @@ export default class WeekNumber extends React.Component {
const weekNumberClasses = {
"react-datepicker__week-number": true,
"react-datepicker__week-number--clickable": !!onClick,
"react-datepicker__week-number--selected": isSameDay(
this.props.date,
this.props.selected,
),
"react-datepicker__week-number--selected":
!!onClick && isSameDay(this.props.date, this.props.selected),
"react-datepicker__week-number--keyboard-selected":
this.isKeyboardSelected(),
};
Expand Down
41 changes: 39 additions & 2 deletions test/week_number_test.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,15 @@ describe("WeekNumber", () => {
).toBe(true);
});

it("should have the class 'react-datepicker__week-number--selected' if selected is current week and preselected is also current week", () => {
it("should have the class 'react-datepicker__week-number--selected' if selected is current week and preselected is also current week and has the onClick Props", () => {
const currentWeekNumber = utils.newDate("2023-10-22T13:09:53+02:00");
const { container } = render(
<WeekNumber
weekNumber={1}
date={currentWeekNumber}
selected={currentWeekNumber}
preSelection={currentWeekNumber}
onClick={() => {}}
/>,
);
expect(
Expand All @@ -265,7 +266,24 @@ describe("WeekNumber", () => {
).toBe(true);
});

it("should have the class 'react-datepicker__week-number--selected' if selected is current week and preselected is not current week", () => {
it("should not have the class 'react-datepicker__week-number--selected' if selected is current week and preselected is also current week and doesn't have the onClick Props", () => {
const currentWeekNumber = utils.newDate("2023-10-22T13:09:53+02:00");
const { container } = render(
<WeekNumber
weekNumber={1}
date={currentWeekNumber}
selected={currentWeekNumber}
preSelection={currentWeekNumber}
/>,
);
expect(
container
.querySelector(".react-datepicker__week-number")
.classList.contains("react-datepicker__week-number--selected"),
).toBe(false);
});

it("should have the class 'react-datepicker__week-number--selected' if selected is current week and preselected is not current week and has the onClick Props", () => {
const currentWeekNumber = utils.newDate("2023-10-22T13:09:53+02:00");
const preSelection = utils.addWeeks(currentWeekNumber, 1);
const { container } = render(
Expand All @@ -274,6 +292,7 @@ describe("WeekNumber", () => {
date={currentWeekNumber}
selected={currentWeekNumber}
preSelection={preSelection}
onClick={() => {}}
/>,
);
expect(
Expand All @@ -283,6 +302,24 @@ describe("WeekNumber", () => {
).toBe(true);
});

it("should not have the class 'react-datepicker__week-number--selected' if selected is current week and preselected is not current week and doesn't have onClick Props", () => {
const currentWeekNumber = utils.newDate("2023-10-22T13:09:53+02:00");
const preSelection = utils.addWeeks(currentWeekNumber, 1);
const { container } = render(
<WeekNumber
weekNumber={1}
date={currentWeekNumber}
selected={currentWeekNumber}
preSelection={preSelection}
/>,
);
expect(
container
.querySelector(".react-datepicker__week-number")
.classList.contains("react-datepicker__week-number--selected"),
).toBe(false);
});

it("should have the class 'react-datepicker__week-number--selected' if selected is not current week and preselected is current week", () => {
const currentWeekNumber = utils.newDate("2023-10-22T13:09:53+02:00");
const selected = utils.addWeeks(currentWeekNumber, 1);
Expand Down
Loading