Skip to content

Commit

Permalink
Merge pull request #4987 from qburst/issue-4986/fix/disabled-item-hov…
Browse files Browse the repository at this point in the history
…er-style

Fix #4986: 🐛🎨 Update the hover style to be applied only to the non-disabled calendar items
  • Loading branch information
martijnrusschen authored Jul 19, 2024
2 parents c36ad14 + 68a38d2 commit 84c072f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 26 deletions.
14 changes: 5 additions & 9 deletions src/stylesheets/datepicker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ h2.react-datepicker__current-month {
.react-datepicker__year-text {
cursor: pointer;

&:hover {
&:not([aria-disabled="true"]):hover {
border-radius: $datepicker__border-radius;
background-color: $datepicker__background-color;
}
Expand All @@ -416,7 +416,7 @@ h2.react-datepicker__current-month {
background-color: $datepicker__highlighted-color;
color: #fff;

&:hover {
&:not([aria-disabled="true"]):hover {
background-color: darken($datepicker__highlighted-color, 5%);
}

Expand Down Expand Up @@ -452,7 +452,7 @@ h2.react-datepicker__current-month {
opacity 0.3s ease-in-out;
}

&:hover {
&:not([aria-disabled="true"]):hover {
background-color: darken($datepicker__holidays-color, 10%);
}

Expand All @@ -469,7 +469,7 @@ h2.react-datepicker__current-month {
background-color: $datepicker__selected-color;
color: #fff;

&:hover {
&:not([aria-disabled="true"]):hover {
background-color: darken($datepicker__selected-color, 5%);
}
}
Expand All @@ -479,7 +479,7 @@ h2.react-datepicker__current-month {
background-color: lighten($datepicker__selected-color, 45%);
color: rgb(0, 0, 0);

&:hover {
&:not([aria-disabled="true"]):hover {
background-color: darken($datepicker__selected-color, 5%);
}
}
Expand All @@ -500,10 +500,6 @@ h2.react-datepicker__current-month {
cursor: default;
color: $datepicker__muted-color;

&:hover {
background-color: transparent;
}

.overlay {
position: absolute;
bottom: 70%;
Expand Down
57 changes: 40 additions & 17 deletions src/test/week_number_test.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,29 +113,52 @@ describe("WeekNumber", () => {
});

describe("handleOnKeyDown", () => {
const handleOnKeyDownMock = jest.fn((event) => {
if (event.key === KeyType.Space) {
event.preventDefault();
event.key = KeyType.Enter;
}
it("should not change any other key", () => {
const onKeyDownMock = jest.fn();

const container = renderWeekNumber(1, {
handleOnKeyDown: onKeyDownMock,
});

const weekNumberElement = container.querySelector(
".react-datepicker__week-number",
)!;

fireEvent.keyDown(weekNumberElement, {
key: KeyType.Enter,
preventDefault: jest.fn(),
});

expect(onKeyDownMock).toHaveBeenCalledTimes(1);
expect(onKeyDownMock).toHaveBeenCalledWith(
expect.objectContaining({
key: KeyType.Enter,
}),
);
});

it("should change space key to Enter", () => {
const eventSpace = {
const onKeyDownMock = jest.fn();

const container = renderWeekNumber(1, {
handleOnKeyDown: onKeyDownMock,
});

const weekNumberElement = container.querySelector(
".react-datepicker__week-number",
)!;

fireEvent.keyDown(weekNumberElement, {
key: KeyType.Space,
preventDefault: jest.fn(),
};
handleOnKeyDownMock(eventSpace);
expect(eventSpace.preventDefault).toHaveBeenCalled();
expect(eventSpace.key).toBe(KeyType.Enter);
});
});

it("should not change any other key", () => {
const eventA = {
key: "a",
};
handleOnKeyDownMock(eventA);
expect(eventA.key).toBe("a");
expect(onKeyDownMock).toHaveBeenCalledTimes(1);
expect(onKeyDownMock).toHaveBeenCalledWith(
expect.objectContaining({
key: KeyType.Enter,
}),
);
});
});
});
Expand Down

0 comments on commit 84c072f

Please sign in to comment.