Skip to content

Commit c23b2b6

Browse files
zbw-zbwzbw01218944
andauthored
fix: add comments and warnings for the deprecated property defaultPic… (#661)
* fix: add comments and warnings for the deprecated property defaultPickerValue * test: add test case --------- Co-authored-by: zbw01218944 <[email protected]>
1 parent a8a33d0 commit c23b2b6

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

src/PickerPanel.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ export type PickerPanelSharedProps<DateType> = {
5858
defaultValue?: DateType;
5959
/** [Legacy] Set default display picker view date */
6060
pickerValue?: DateType;
61-
/** [Legacy] Set default display picker view date */
61+
/**
62+
* @deprecated please use `defaultValue` instead.
63+
* Set default display picker view date
64+
*/
6265
defaultPickerValue?: DateType;
6366

6467
// Date
@@ -170,6 +173,7 @@ function PickerPanel<DateType>(props: PickerPanelProps<DateType>) {
170173
const isMinuteStepValid = 60 % minuteStep === 0;
171174
const isSecondStepValid = 60 % secondStep === 0;
172175

176+
// ============================ Warning ============================
173177
if (process.env.NODE_ENV !== 'production') {
174178
warning(!value || generateConfig.isValidate(value), 'Invalidate date pass to `value`.');
175179
warning(!value || generateConfig.isValidate(value), 'Invalidate date pass to `defaultValue`.');
@@ -182,6 +186,7 @@ function PickerPanel<DateType>(props: PickerPanelProps<DateType>) {
182186
isSecondStepValid,
183187
`\`secondStep\` ${secondStep} is invalid. It should be a factor of 60.`,
184188
);
189+
warning(!defaultPickerValue, `'defaultPickerValue' is deprecated. Please use 'defaultValue' instead.`);
185190
warning(!dateRender, `'dateRender' is deprecated. Please use 'cellRender' instead.`);
186191
warning(!monthCellRender, `'monthCellRender' is deprecated. Please use 'cellRender' instead.`);
187192
}

src/RangePicker.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ export type RangePickerSharedProps<DateType> = {
9898
id?: string;
9999
value?: RangeValue<DateType>;
100100
defaultValue?: RangeValue<DateType>;
101+
/**
102+
* @deprecated please use `defaultValue` instead.
103+
* Set default display picker view date
104+
*/
101105
defaultPickerValue?: [DateType, DateType];
102106
placeholder?: [string, string];
103107
disabled?: boolean | [boolean, boolean];

src/interface.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ export type PanelSharedProps<DateType> = {
7373
generateConfig: GenerateConfig<DateType>;
7474
value?: NullableDateType<DateType>;
7575
viewDate: DateType;
76-
/** [Legacy] Set default display picker view date */
76+
/**
77+
* @deprecated please use `defaultValue` instead.
78+
* Set default display picker view date
79+
*/
7780
defaultPickerValue?: DateType;
7881
locale: Locale;
7982
disabledDate?: (date: DateType) => boolean;

tests/panel.spec.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,24 @@ describe('Picker.Panel', () => {
632632
expect(container).toMatchSnapshot();
633633
});
634634

635+
it('warning with defaultPickerValue', () => {
636+
resetWarned();
637+
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
638+
639+
render(
640+
<MomentPickerPanel
641+
picker={picker as any}
642+
defaultPickerValue={getMoment('2023-07-25')}
643+
/>,
644+
);
645+
646+
expect(errSpy).toHaveBeenCalledWith(
647+
"Warning: 'defaultPickerValue' is deprecated. Please use 'defaultValue' instead.",
648+
);
649+
650+
errSpy.mockRestore();
651+
});
652+
635653
it('warning with dateRender and monthCellRender', () => {
636654
resetWarned();
637655
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});

0 commit comments

Comments
 (0)