Skip to content

Commit

Permalink
fix: shows current week as selected in correct year (#313)
Browse files Browse the repository at this point in the history
* fix: shows current week as selected in correct year

* test: add test case

---------

Co-authored-by: 二货机器人 <smith3816@gmail.com>
  • Loading branch information
NgChiKin and zombieJ committed Jul 25, 2023
1 parent c377ca0 commit ec9c4ad
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/utils/dateUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export function isSameWeek<DateType>(
}

return (
isSameYear(generateConfig, date1!, date2!) &&
generateConfig.locale.getWeek(locale, date1!) === generateConfig.locale.getWeek(locale, date2!)
);
}
Expand Down
14 changes: 14 additions & 0 deletions tests/panel.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -682,4 +682,18 @@ describe('Picker.Panel', () => {
expect(container).toMatchSnapshot();
});
});

it('week picker current should check year', () => {
const { container } = render(
<MomentPickerPanel picker="week" value={getMoment('1990-09-03')} />,
);
expect(
container.querySelector('.rc-picker-week-panel-row-selected td[title="1990-09-03"]'),
).toBeTruthy();

// Diff year
fireEvent.click(container.querySelector('.rc-picker-header-super-next-btn'));
expect(container.querySelector('td[title="1991-09-03"]')).toBeTruthy();
expect(container.querySelector('.rc-picker-week-panel-row-selected')).toBeFalsy();
});
});

1 comment on commit ec9c4ad

@vercel
Copy link

@vercel vercel bot commented on ec9c4ad Jul 25, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.