Skip to content

Commit de1b611

Browse files
committed
🐛 Fix the Selected Year Picker style when no date is selected
Closes #5573
1 parent cc30861 commit de1b611

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/test/year_picker_test.test.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,20 @@ describe("YearPicker", () => {
148148
expect(yearElements.length).toBe(0);
149149
});
150150

151+
it("should not has selected class where there is no selectedDates", () => {
152+
const { container } = render(
153+
<Year
154+
date={new Date()}
155+
onYearMouseEnter={() => {}}
156+
onYearMouseLeave={() => {}}
157+
/>,
158+
);
159+
const yearElements = Array.from(
160+
container.querySelectorAll(".react-datepicker__year-text--selected"),
161+
);
162+
expect(yearElements.length).toBe(0);
163+
});
164+
151165
it("should have current year class when element of array equal of current year", () => {
152166
const date = new Date();
153167
const { container } = render(

src/year.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ export default class Year extends Component<YearProps> {
248248
if (selectsMultiple) {
249249
return selectedDates?.some((date) => year === getYear(date));
250250
}
251-
return !selected || year === getYear(selected);
251+
return !!selected && year === getYear(selected);
252252
};
253253

254254
onYearClick = (

0 commit comments

Comments
 (0)