Skip to content

Commit

Permalink
fix: Year Panel super prev disabled logic (#893)
Browse files Browse the repository at this point in the history
* fix: year lock

* test: add test case
  • Loading branch information
zombieJ authored Nov 13, 2024
1 parent b2ca430 commit e5df38a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
8 changes: 7 additions & 1 deletion docs/examples/debug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ export default () => {
// }}
/>

<RangePicker {...sharedLocale} style={{ width: 400 }} allowEmpty />
<RangePicker
{...sharedLocale}
style={{ width: 400 }}
minDate={dayjs('2024')}
open
mode={['year', 'year']}
/>
{/* <SinglePicker
{...dateFnsSharedLocale}
style={{ width: 400 }}
Expand Down
2 changes: 1 addition & 1 deletion src/PickerPanel/DecadePanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function DecadePanel<DateType extends object = any>(
const [info] = useInfo(props, 'decade');

const getStartYear = (date: DateType) => {
const startYear = Math.floor(generateConfig.getYear(pickerValue) / 100) * 100;
const startYear = Math.floor(generateConfig.getYear(date) / 100) * 100;
return generateConfig.setYear(date, startYear);
};
const getEndYear = (date: DateType) => {
Expand Down
2 changes: 1 addition & 1 deletion src/PickerPanel/YearPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function YearPanel<DateType extends object = any>(
// ========================== Base ==========================
const [info] = useInfo(props, 'year');
const getStartYear = (date: DateType) => {
const startYear = Math.floor(generateConfig.getYear(pickerValue) / 10) * 10;
const startYear = Math.floor(generateConfig.getYear(date) / 10) * 10;
return generateConfig.setYear(date, startYear);
};
const getEndYear = (date: DateType) => {
Expand Down
9 changes: 8 additions & 1 deletion tests/new-range.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ describe('NewPicker.Range', () => {
it('pass tabIndex', () => {
const { container } = render(
<div>
<DayRangePicker tabIndex={-1}/>
<DayRangePicker tabIndex={-1} />
</div>,
);

Expand Down Expand Up @@ -1255,6 +1255,13 @@ describe('NewPicker.Range', () => {
});
expect(onChange).toHaveBeenCalled();
});

it('should disabled super prev correctly', () => {
render(<DayRangePicker minDate={dayjs()} picker="year" open />);

// Expect super prev disabled
expect(document.querySelector('.rc-picker-header-super-prev-btn-disabled')).toBeDisabled();
});
});

it('double click now button', () => {
Expand Down

0 comments on commit e5df38a

Please sign in to comment.