Skip to content

Commit 85606b4

Browse files
authored
fix: week picker not need cell select logic (#589)
1 parent 98ead31 commit 85606b4

File tree

4 files changed

+27
-19
lines changed

4 files changed

+27
-19
lines changed

src/panels/DatePanel/DateBody.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import * as React from 'react';
22
import type { GenerateConfig } from '../../generate';
3+
import useCellClassName from '../../hooks/useCellClassName';
4+
import type { Locale } from '../../interface';
5+
import RangeContext from '../../RangeContext';
36
import {
4-
WEEK_DAY_COUNT,
7+
formatValue,
58
getWeekStartDate,
69
isSameDate,
710
isSameMonth,
8-
formatValue,
11+
WEEK_DAY_COUNT,
912
} from '../../utils/dateUtil';
10-
import type { Locale } from '../../interface';
11-
import RangeContext from '../../RangeContext';
12-
import useCellClassName from '../../hooks/useCellClassName';
1313
import PanelBody from '../PanelBody';
1414

1515
export type DateRender<DateType> = (currentDate: DateType, today: DateType) => React.ReactNode;
@@ -21,6 +21,7 @@ export type DateBodyPassProps<DateType> = {
2121
// Used for week panel
2222
prefixColumn?: (date: DateType) => React.ReactNode;
2323
rowClassName?: (date: DateType) => string;
24+
isSameCell?: (current: DateType, target: DateType) => boolean;
2425
};
2526

2627
export type DateBodyProps<DateType> = {
@@ -43,6 +44,7 @@ function DateBody<DateType>(props: DateBodyProps<DateType>) {
4344
viewDate,
4445
value,
4546
dateRender,
47+
isSameCell,
4648
} = props;
4749

4850
const { rangedValue, hoverRangedValue } = React.useContext(RangeContext);
@@ -75,8 +77,8 @@ function DateBody<DateType>(props: DateBodyProps<DateType>) {
7577
generateConfig,
7678
rangedValue: prefixColumn ? null : rangedValue,
7779
hoverRangedValue: prefixColumn ? null : hoverRangedValue,
78-
isSameCell: (current, target) => isSameDate(generateConfig, current, target),
79-
isInView: date => isSameMonth(generateConfig, date, viewDate),
80+
isSameCell: isSameCell || ((current, target) => isSameDate(generateConfig, current, target)),
81+
isInView: (date) => isSameMonth(generateConfig, date, viewDate),
8082
offsetCell: (date, offset) => generateConfig.addDate(date, offset),
8183
});
8284

@@ -92,7 +94,7 @@ function DateBody<DateType>(props: DateBodyProps<DateType>) {
9294
getCellText={generateConfig.getDate}
9395
getCellClassName={getCellClassName}
9496
getCellDate={generateConfig.addDate}
95-
titleCell={date =>
97+
titleCell={(date) =>
9698
formatValue(date, {
9799
locale,
98100
format: 'YYYY-MM-DD',

src/panels/DatePanel/index.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import * as React from 'react';
21
import classNames from 'classnames';
3-
import type { DateBodyPassProps, DateRender } from './DateBody';
4-
import DateBody from './DateBody';
5-
import DateHeader from './DateHeader';
2+
import * as React from 'react';
63
import type { PanelSharedProps } from '../../interface';
74
import { WEEK_DAY_COUNT } from '../../utils/dateUtil';
85
import type { KeyboardConfig } from '../../utils/uiUtil';
96
import { createKeyDownHandler } from '../../utils/uiUtil';
7+
import type { DateBodyPassProps, DateRender } from './DateBody';
8+
import DateBody from './DateBody';
9+
import DateHeader from './DateHeader';
1010

1111
const DATE_ROW_COUNT = 6;
1212

@@ -17,7 +17,8 @@ export type DatePanelProps<DateType> = {
1717
// Used for week panel
1818
panelName?: string;
1919
keyboardConfig?: KeyboardConfig;
20-
} & PanelSharedProps<DateType> & DateBodyPassProps<DateType>;
20+
} & PanelSharedProps<DateType> &
21+
DateBodyPassProps<DateType>;
2122

2223
function DatePanel<DateType>(props: DatePanelProps<DateType>) {
2324
const {
@@ -37,18 +38,18 @@ function DatePanel<DateType>(props: DatePanelProps<DateType>) {
3738

3839
// ======================= Keyboard =======================
3940
operationRef.current = {
40-
onKeyDown: event =>
41+
onKeyDown: (event) =>
4142
createKeyDownHandler(event, {
42-
onLeftRight: diff => {
43+
onLeftRight: (diff) => {
4344
onSelect(generateConfig.addDate(value || viewDate, diff), 'key');
4445
},
45-
onCtrlLeftRight: diff => {
46+
onCtrlLeftRight: (diff) => {
4647
onSelect(generateConfig.addYear(value || viewDate, diff), 'key');
4748
},
48-
onUpDown: diff => {
49+
onUpDown: (diff) => {
4950
onSelect(generateConfig.addDate(value || viewDate, diff * WEEK_DAY_COUNT), 'key');
5051
},
51-
onPageUpDown: diff => {
52+
onPageUpDown: (diff) => {
5253
onSelect(generateConfig.addMonth(value || viewDate, diff), 'key');
5354
},
5455
...keyboardConfig,
@@ -100,7 +101,7 @@ function DatePanel<DateType>(props: DatePanelProps<DateType>) {
100101
/>
101102
<DateBody
102103
{...props}
103-
onSelect={date => onSelect(date, 'mouse')}
104+
onSelect={(date) => onSelect(date, 'mouse')}
104105
prefixCls={prefixCls}
105106
value={value}
106107
viewDate={viewDate}

src/panels/WeekPanel/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ function WeekPanel<DateType>(props: WeekPanelProps<DateType>) {
8484
keyboardConfig={{
8585
onLeftRight: null,
8686
}}
87+
// No need check cell level
88+
isSameCell={() => false}
8789
/>
8890
);
8991
}

tests/range.spec.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,5 +1772,8 @@ describe('Picker.Range', () => {
17721772
fireEvent.mouseLeave(findWeekCell('37'));
17731773

17741774
expect(findWeekCell('37').parentElement).toHaveClass('rc-picker-week-panel-row-range-end');
1775+
1776+
// No selected cell
1777+
expect(document.querySelector('.rc-picker-cell-selected')).toBeFalsy();
17751778
});
17761779
});

0 commit comments

Comments
 (0)