Skip to content

Commit 843c454

Browse files
uyarnRylanBot
andauthored
chore: release 1.11.8-patch.8 (#4072)
* fix(DateRangePicker): enhance panel synchronization for preset selection (#3818) * fix(DatePicker): fix year mode panel in range picker (#3744) * fix(DatePicker): fix year mode panel in range picker * chore: optimize * chore: release 1.11.8-patch.8 --------- Co-authored-by: Rylan <rylanbot@qq.com>
1 parent a9a12dd commit 843c454

File tree

9 files changed

+79
-36
lines changed

9 files changed

+79
-36
lines changed

packages/components/date-picker/DateRangePicker.tsx

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,24 @@ const DateRangePicker = forwardRef<HTMLDivElement, DateRangePickerProps>((origin
8080
// 记录面板是否选中过
8181
const [isSelected, setIsSelected] = useState(false);
8282

83+
const handleSyncPanelValue = (value: DateRangeValue) => {
84+
// 同年同月时,确保右侧面板月份比左侧大 避免两侧面板月份一致
85+
const nextMonth = value.map((v: string) => parseToDayjs(v, format).month());
86+
const nextYear = value.map((v: string) => parseToDayjs(v, format).year());
87+
if (nextYear[0] === nextYear[1] && nextMonth[0] === nextMonth[1]) {
88+
nextMonth[0] === 11 ? (nextMonth[0] -= 1) : (nextMonth[1] += 1);
89+
}
90+
setMonth(nextMonth);
91+
setYear(nextYear);
92+
};
93+
8394
const handlePopupInvisible = () => {
8495
setPopupVisible(false);
8596
props.popupProps?.onVisibleChange?.(false, {});
8697
};
8798

8899
useEffect(() => {
100+
if (value === cacheValue) return;
89101
// 面板展开重置数据
90102
if (popupVisible) {
91103
setIsSelected(false);
@@ -105,13 +117,7 @@ const DateRangePicker = forwardRef<HTMLDivElement, DateRangePickerProps>((origin
105117
setYear(defaultYear);
106118
setMonth(defaultMonth);
107119
} else if (value.length === 2 && !enableTimePicker) {
108-
// 确保右侧面板月份比左侧大 避免两侧面板月份一致
109-
const nextMonth = value.map((v: string) => parseToDayjs(v, format).month());
110-
if (year[0] === year[1] && nextMonth[0] === nextMonth[1]) {
111-
nextMonth[0] === 11 ? (nextMonth[0] -= 1) : (nextMonth[1] += 1);
112-
}
113-
setYear(value.map((v: string) => parseToDayjs(v, format).year()));
114-
setMonth(nextMonth);
120+
handleSyncPanelValue(value);
115121
} else {
116122
setYear(value.map((v: string) => parseToDayjs(v, format).year()));
117123
setMonth(value.map((v: string) => parseToDayjs(v, format).month()));
@@ -282,10 +288,17 @@ const DateRangePicker = forwardRef<HTMLDivElement, DateRangePickerProps>((origin
282288
if (!Array.isArray(presetValue)) {
283289
log.error('DateRangePicker', `preset: ${preset} must be Array!`);
284290
} else {
285-
onChange(formatDate(presetValue, { format, targetFormat: valueType, autoSwap: true }), {
286-
dayjsValue: presetValue.map((p) => parseToDayjs(p, format)),
287-
trigger: 'preset',
288-
});
291+
const formattedPreset = formatDate(presetValue, { format, targetFormat: valueType });
292+
setInputValue(formattedPreset);
293+
setCacheValue(formattedPreset);
294+
setTime(formatTime(formattedPreset, format, timeFormat, props.defaultTime));
295+
296+
setIsSelected(true);
297+
setIsFirstValueSelected(true);
298+
299+
handleSyncPanelValue(formattedPreset);
300+
handlePopupInvisible();
301+
onChange(formattedPreset, { dayjsValue: formattedPreset.map((p) => parseToDayjs(p, format)), trigger: 'preset' });
289302
props.onPresetClick?.(context);
290303
handlePopupInvisible();
291304
}

packages/components/date-picker/DateRangePickerPanel.tsx

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
import React, { forwardRef, useState, useMemo } from 'react';
1+
import React, { forwardRef, useMemo, useState } from 'react';
22
import dayjs from 'dayjs';
3-
import { formatDate, getDefaultFormat, parseToDayjs } from '@tdesign/common-js/date-picker/format';
4-
import { subtractMonth, addMonth, extractTimeObj } from '@tdesign/common-js/date-picker/utils';
3+
import { formatDate, formatTime, getDefaultFormat, parseToDayjs } from '@tdesign/common-js/date-picker/format';
4+
import { addMonth, extractTimeObj, subtractMonth } from '@tdesign/common-js/date-picker/utils';
55
import log from '@tdesign/common-js/log/index';
6-
import { StyledProps } from '../common';
7-
import {
8-
TdDateRangePickerPanelProps,
9-
DatePickerYearChangeTrigger,
6+
import useDefaultProps from '../hooks/useDefaultProps';
7+
import useRangeValue from './hooks/useRangeValue';
8+
import RangePanel from './panel/RangePanel';
9+
import { dateCorrection } from './utils';
10+
11+
import type { StyledProps } from '../common';
12+
import type {
1013
DatePickerMonthChangeTrigger,
1114
DatePickerTimeChangeTrigger,
15+
DatePickerYearChangeTrigger,
16+
DateRangeValue,
1217
PresetDate,
18+
TdDateRangePickerPanelProps,
1319
} from './type';
14-
import RangePanel from './panel/RangePanel';
15-
import useRangeValue from './hooks/useRangeValue';
16-
import useDefaultProps from '../hooks/useDefaultProps';
17-
import { dateCorrection } from './utils';
1820

1921
export interface DateRangePickerPanelProps extends TdDateRangePickerPanelProps, StyledProps {}
2022

@@ -50,7 +52,7 @@ const DateRangePickerPanel = forwardRef<HTMLDivElement, DateRangePickerPanelProp
5052
setCacheValue,
5153
} = useRangeValue(props);
5254

53-
const { format } = getDefaultFormat({
55+
const { format, timeFormat } = getDefaultFormat({
5456
mode,
5557
enableTimePicker,
5658
format: props.format,
@@ -62,6 +64,18 @@ const DateRangePickerPanel = forwardRef<HTMLDivElement, DateRangePickerPanelProp
6264
const [hoverValue, setHoverValue] = useState([]);
6365
const activeIndex = useMemo(() => (isFirstValueSelected ? 1 : 0), [isFirstValueSelected]);
6466

67+
const handleSyncPanelValue = (value: DateRangeValue) => {
68+
// 同年同月时,确保右侧面板月份比左侧大,避免两侧面板月份一致
69+
const nextMonth = value.map((v: string) => parseToDayjs(v, format).month());
70+
const nextYear = value.map((v: string) => parseToDayjs(v, format).year());
71+
if (nextYear[0] === nextYear[1] && nextMonth[0] === nextMonth[1]) {
72+
nextMonth[0] === 11 ? (nextMonth[0] -= 1) : (nextMonth[1] += 1);
73+
}
74+
setMonth(nextMonth);
75+
setYear(nextYear);
76+
setTime(formatTime(value, format, timeFormat, props.defaultTime));
77+
};
78+
6579
// 日期 hover
6680
function onCellMouseEnter(date: Date) {
6781
setIsHoverCell(true);
@@ -223,7 +237,12 @@ const DateRangePickerPanel = forwardRef<HTMLDivElement, DateRangePickerPanelProp
223237
if (!Array.isArray(presetVal)) {
224238
log.error('DateRangePickerPanel', `preset: ${presetValue} must be Array!`);
225239
} else {
226-
onChange(formatDate(presetVal, { format, autoSwap: true }), {
240+
const formattedPreset = formatDate(presetVal, { format });
241+
setCacheValue(formattedPreset);
242+
setIsFirstValueSelected(true);
243+
setIsSelected(true);
244+
handleSyncPanelValue(formattedPreset);
245+
onChange(formattedPreset, {
227246
dayjsValue: presetVal.map((p) => parseToDayjs(p, format)),
228247
trigger: 'preset',
229248
});

packages/components/date-picker/base/Header.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { PaginationMini, TdPaginationMiniProps } from '../../pagination';
88
export interface DatePickerHeaderProps extends Pick<TdDatePickerProps, 'mode'> {
99
year?: number;
1010
month?: number;
11+
internalYear: Array<number>;
12+
partial: 'start' | 'end';
1113
onMonthChange?: Function;
1214
onYearChange?: Function;
1315
onJumperClick?: TdPaginationMiniProps['onChange'];
@@ -31,7 +33,7 @@ const useDatePickerLocalConfig = () => {
3133
const DatePickerHeader = (props: DatePickerHeaderProps) => {
3234
const { classPrefix } = useConfig();
3335

34-
const { mode, year, month, onMonthChange, onYearChange, onJumperClick } = props;
36+
const { mode, year, month, onMonthChange, onYearChange, onJumperClick, partial, internalYear = [] } = props;
3537

3638
const { now, months, preMonth, preYear, nextMonth, nextYear, preDecade, nextDecade } = useDatePickerLocalConfig();
3739

@@ -66,10 +68,14 @@ const DatePickerHeader = (props: DatePickerHeaderProps) => {
6668
const [yearOptions, setYearOptions] = useState(() => initOptions(year));
6769

6870
// 年份选择展示区间
69-
const nearestYear: number = useMemo(
70-
() => yearOptions.find((option) => option.value - year <= 9 && option.value - year >= 0)?.value || year,
71-
[yearOptions, year],
72-
);
71+
const nearestYear: number = useMemo(() => {
72+
// 右侧面板年份选择需要保持大于左侧面板年份选择
73+
const extraYear = partial === 'end' && mode === 'year' && internalYear[1] - internalYear[0] <= 9 ? 9 : 0;
74+
return (
75+
yearOptions.find((option) => option.value - (year + extraYear) <= 9 && option.value - (year + extraYear) >= 0)
76+
?.value || year
77+
);
78+
}, [yearOptions, year, mode, partial, internalYear]);
7379

7480
useEffect(() => {
7581
const yearRange = initOptions(year);

packages/components/date-picker/panel/PanelContent.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface PanelContentProps {
2222
multiple?: SinglePanelProps['multiple'];
2323
popupVisible?: boolean;
2424
tableData: any[];
25+
internalYear?: Array<number>;
2526
onMonthChange: SinglePanelProps['onMonthChange'] | RangePanelProps['onMonthChange'];
2627
onYearChange: SinglePanelProps['onYearChange'] | RangePanelProps['onYearChange'];
2728
onJumperClick: SinglePanelProps['onJumperClick'] | RangePanelProps['onJumperClick'];
@@ -48,6 +49,7 @@ export default function PanelContent(props: PanelContentProps) {
4849
partial = 'start',
4950
time,
5051
tableData,
52+
internalYear,
5153
onJumperClick,
5254
onCellClick,
5355
onCellMouseEnter,
@@ -92,6 +94,8 @@ export default function PanelContent(props: PanelContentProps) {
9294
mode={mode}
9395
year={year}
9496
month={month}
97+
internalYear={internalYear}
98+
partial={partial}
9599
onMonthChange={onMonthChangeInner}
96100
onYearChange={onYearChangeInner}
97101
onJumperClick={onJumperClickInner}

packages/components/date-picker/panel/RangePanel.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ const RangePanel = forwardRef<HTMLDivElement, RangePanelProps>((originalProps, r
128128
end: value[1] ? parseToDayjs(value[1], format).toDate() : undefined,
129129
hoverStart: !hidePreselection && hoverValue[0] ? parseToDayjs(hoverValue[0], format).toDate() : undefined,
130130
hoverEnd: !hidePreselection && hoverValue[1] ? parseToDayjs(hoverValue[1], format).toDate() : undefined,
131-
year: endYear,
131+
year: mode === 'year' && endYear - startYear <= 9 ? endYear + 9 : endYear,
132132
month: endMonth,
133133
mode,
134134
firstDayOfWeek,
@@ -197,6 +197,7 @@ const RangePanel = forwardRef<HTMLDivElement, RangePanelProps>((originalProps, r
197197
time={time[activeIndex]}
198198
value={value}
199199
tableData={endTableData}
200+
internalYear={year}
200201
{...panelContentProps}
201202
/>,
202203
]

packages/components/menu/SubMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ const SubTitleMenu: FC<SubMenuWithCustomizeProps> = (props) => {
201201

202202
useRipple(subMenuDom);
203203

204-
// pupup 导航
204+
// popup 导航
205205
const isPopUp = expandType === 'popup';
206206
// 当前二级导航激活
207207
const isActive = checkSubMenuChildrenActive(children, active) || active === value;

packages/components/table/_example/filter-controlled.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ const columns: TableProps['columns'] = [
102102
// eslint-disable-next-line
103103
// function IconText(props = {}) {
104104
// // 根据不同的 Props,允许定义不同的筛选图标(col, colIndex 在 Table 组件内部已经注入)
105-
// const { col, colIndx } = props;
106-
// console.log(col, colIndx);
105+
// const { col, colIndex } = props;
106+
// console.log(col, colIndex);
107107
// if (col.colKey === 'email') return <div>EmailIcon</div>;
108108
// return <i>Icon</i>;
109109
// }

packages/components/tree/__tests__/tree.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ describe('Tree test', () => {
246246
],
247247
},
248248
];
249-
it('wehen props.line is customized, it works fine', async () => {
249+
it('when props.line is customized, it works fine', async () => {
250250
const { container } = await renderTreeWithProps({
251251
data,
252252
expandAll: true,
@@ -256,7 +256,7 @@ describe('Tree test', () => {
256256
expect(container.querySelectorAll('.custom-line').length).toBe(6);
257257
});
258258

259-
it('wehen props.line is a customized function, it works fine', async () => {
259+
it('when props.line is a customized function, it works fine', async () => {
260260
const line: any = () => <span className="custom-line"></span>;
261261
const { container } = await renderTreeWithProps({
262262
data,

packages/tdesign-react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tdesign-react",
3-
"version": "1.11.8-patch.7",
3+
"version": "1.11.8-patch.8",
44
"title": "tdesign-react",
55
"description": "TDesign Component for React",
66
"main": "lib/index.js",

0 commit comments

Comments
 (0)