From 08cdae973ad0d77ff6daa3bbc789d713c64d2265 Mon Sep 17 00:00:00 2001 From: Balaji Sridharan Date: Thu, 18 Jul 2024 16:31:37 +0530 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=F0=9F=8E=A8=20Update=20the=20h?= =?UTF-8?q?over=20style=20to=20be=20applied=20only=20to=20the=20non-disabl?= =?UTF-8?q?ed=20calendar=20items?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #4986 --- src/stylesheets/datepicker.scss | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/stylesheets/datepicker.scss b/src/stylesheets/datepicker.scss index 83b2be6a2..54ce483aa 100644 --- a/src/stylesheets/datepicker.scss +++ b/src/stylesheets/datepicker.scss @@ -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; } @@ -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%); } @@ -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%); } @@ -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%); } } @@ -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%); } } @@ -500,10 +500,6 @@ h2.react-datepicker__current-month { cursor: default; color: $datepicker__muted-color; - &:hover { - background-color: transparent; - } - .overlay { position: absolute; bottom: 70%; From 68a38d25f24e1697bf4a70b6750510de11e9b99e Mon Sep 17 00:00:00 2001 From: Balaji Sridharan Date: Thu, 18 Jul 2024 18:11:24 +0530 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=85=20Update=20the=20test=20case=20of?= =?UTF-8?q?=20WeekNumber=20component's=20onKeyDown=20event=20to=20improve?= =?UTF-8?q?=20the=20coverage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/week_number_test.test.tsx | 57 +++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/src/test/week_number_test.test.tsx b/src/test/week_number_test.test.tsx index a802877d3..ab2d33f6f 100644 --- a/src/test/week_number_test.test.tsx +++ b/src/test/week_number_test.test.tsx @@ -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, + }), + ); }); }); });