Skip to content

Commit b13756f

Browse files
committed
fix: time-picker type error #5109
1 parent ad76bb6 commit b13756f

20 files changed

+197
-139
lines changed

components/calendar/generateCalendar.tsx

+20-21
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export interface CalendarProps<DateType> {
6060
mode?: CalendarMode;
6161
fullscreen?: boolean;
6262
onChange?: (date: DateType | string) => void;
63+
'onUpdate:value'?: (date: DateType | string) => void;
6364
onPanelChange?: (date: DateType | string, mode: CalendarMode) => void;
6465
onSelect?: (date: DateType | string) => void;
6566
valueFormat?: string;
@@ -88,7 +89,25 @@ function generateCalendar<
8889
const Calendar = defineComponent<Props>({
8990
name: 'ACalendar',
9091
inheritAttrs: false,
91-
emits: ['change', 'panelChange', 'select', 'update:value'],
92+
props: [
93+
'prefixCls',
94+
'locale',
95+
'validRange',
96+
'disabledDate',
97+
'dateFullCellRender',
98+
'dateCellRender',
99+
'monthFullCellRender',
100+
'monthCellRender',
101+
'headerRender',
102+
'value',
103+
'defaultValue',
104+
'mode',
105+
'fullscreen',
106+
'onChange',
107+
'onPanelChange',
108+
'onSelect',
109+
'valueFormat',
110+
] as any,
92111
slots: [
93112
'dateFullCellRender',
94113
'dateCellRender',
@@ -306,26 +325,6 @@ function generateCalendar<
306325
},
307326
});
308327

309-
Calendar.props = [
310-
'prefixCls',
311-
'locale',
312-
'validRange',
313-
'disabledDate',
314-
'dateFullCellRender',
315-
'dateCellRender',
316-
'monthFullCellRender',
317-
'monthCellRender',
318-
'headerRender',
319-
'value',
320-
'defaultValue',
321-
'mode',
322-
'fullscreen',
323-
'onChange',
324-
'onPanelChange',
325-
'onSelect',
326-
'valueFormat',
327-
];
328-
329328
Calendar.install = function (app: App) {
330329
app.component(Calendar.name, Calendar);
331330
return app;

components/carousel/__tests__/__snapshots__/demo.test.js.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ exports[`renders ./components/carousel/demo/basic.vue correctly 1`] = `
167167
exports[`renders ./components/carousel/demo/customArrows.vue correctly 1`] = `
168168
<div class="ant-carousel">
169169
<div class="slick-slider slick-initialized">
170-
<div class="custom-slick-arrow slick-arrow slick-prev" style="left: 10px; display: block;"><span role="img" aria-label="left-circle" class="anticon anticon-left-circle"><svg focusable="false" class="" data-icon="left-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true" viewBox="64 64 896 896"><path d="M603.3 327.5l-246 178a7.95 7.95 0 000 12.9l246 178c5.3 3.8 12.7 0 12.7-6.5V643c0-10.2-4.9-19.9-13.2-25.9L457.4 512l145.4-105.2c8.3-6 13.2-15.6 13.2-25.9V334c0-6.5-7.4-10.3-12.7-6.5z"></path><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"></path></svg></span></div>
170+
<div class="custom-slick-arrow slick-arrow slick-prev" style="left: 10px; z-index: 1; display: block;"><span role="img" aria-label="left-circle" class="anticon anticon-left-circle"><svg focusable="false" class="" data-icon="left-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true" viewBox="64 64 896 896"><path d="M603.3 327.5l-246 178a7.95 7.95 0 000 12.9l246 178c5.3 3.8 12.7 0 12.7-6.5V643c0-10.2-4.9-19.9-13.2-25.9L457.4 512l145.4-105.2c8.3-6 13.2-15.6 13.2-25.9V334c0-6.5-7.4-10.3-12.7-6.5z"></path><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z"></path></svg></span></div>
171171
<div class="slick-list">
172172
<div class="slick-track" style="opacity: 1; transform: translate3d(0px, 0px, 0px);">
173173
<div class="slick-slide slick-cloned" tabindex="-1" data-index="-1" aria-hidden="true" style="width: 0px;">

components/date-picker/demo/date-render.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default defineComponent({
5151
};
5252
return {
5353
value1: ref<Dayjs>(),
54-
value2: ref<Dayjs[]>([]),
54+
value2: ref<[Dayjs, Dayjs]>(),
5555
value3: ref<Dayjs>(),
5656
getCurrentStyle,
5757
};

components/date-picker/demo/disabled-date.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export default defineComponent({
6868
};
6969
};
7070
71-
const disabledRangeTime = (_: Dayjs[], type: 'start' | 'end') => {
71+
const disabledRangeTime = (_: Dayjs, type: 'start' | 'end') => {
7272
if (type === 'start') {
7373
return {
7474
disabledHours: () => range(0, 60).splice(4, 20),
@@ -87,8 +87,8 @@ export default defineComponent({
8787
dayjs,
8888
value1: ref<Dayjs>(),
8989
value2: ref<Dayjs>(),
90-
value3: ref<Dayjs[]>([]),
91-
value4: ref<Dayjs[]>([]),
90+
value3: ref<[Dayjs, Dayjs]>(),
91+
value4: ref<[Dayjs, Dayjs]>(),
9292
disabledDate,
9393
disabledDateTime,
9494
disabledRangeTime,

components/date-picker/demo/disabled.vue

+8-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,14 @@ export default defineComponent({
3333
return {
3434
value1: ref<Dayjs>(dayjs('2015-06-06', dateFormat)),
3535
value2: ref<Dayjs>(dayjs('2015-06', 'YYYY-MM')),
36-
value3: ref<Dayjs[]>([dayjs('2015-06-06', dateFormat), dayjs('2015-06-06', dateFormat)]),
37-
value4: ref<Dayjs[]>([dayjs('2019-09-03', dateFormat), dayjs('2019-11-22', dateFormat)]),
36+
value3: ref<[Dayjs, Dayjs]>([
37+
dayjs('2015-06-06', dateFormat),
38+
dayjs('2015-06-06', dateFormat),
39+
]),
40+
value4: ref<[Dayjs, Dayjs]>([
41+
dayjs('2019-09-03', dateFormat),
42+
dayjs('2019-11-22', dateFormat),
43+
]),
3844
};
3945
},
4046
});

components/date-picker/demo/format.vue

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ export default defineComponent({
3737
value1: ref<Dayjs>(dayjs('2015/01/01', dateFormat)),
3838
value2: ref<Dayjs>(dayjs('01/01/2015', dateFormatList[0])),
3939
value3: ref<Dayjs>(dayjs('2015/01', monthFormat)),
40-
value4: ref<Dayjs[]>([dayjs('2015/01/01', dateFormat), dayjs('2015/01/01', dateFormat)]),
40+
value4: ref<[Dayjs, Dayjs]>([
41+
dayjs('2015/01/01', dateFormat),
42+
dayjs('2015/01/01', dateFormat),
43+
]),
4144
value5: ref<Dayjs>(dayjs('2015/01/01', dateFormat)),
4245
dateFormat,
4346
monthFormat,

components/date-picker/demo/mode.vue

+6-6
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,25 @@ import { Dayjs } from 'dayjs';
3939
import { defineComponent, ref } from 'vue';
4040
export default defineComponent({
4141
setup() {
42-
const mode1 = ref<string>('time');
43-
const mode2 = ref<string[]>(['month', 'month']);
44-
const value = ref<Dayjs[]>([]);
42+
const mode1 = ref<any>('time');
43+
const mode2 = ref<any>(['month', 'month']);
44+
const value = ref<[Dayjs, Dayjs]>();
4545
4646
const handleOpenChange1 = (open: boolean) => {
4747
if (open) {
4848
mode1.value = 'time';
4949
}
5050
};
5151
52-
const handleChange = (val: Dayjs[]) => {
52+
const handleChange = (val: [Dayjs, Dayjs]) => {
5353
value.value = val;
5454
};
5555
56-
const handlePanelChange1 = (_val: Dayjs[], mode: string) => {
56+
const handlePanelChange1 = (_val: [Dayjs, Dayjs], mode: any) => {
5757
mode1.value = mode;
5858
};
5959
60-
const handlePanelChange2 = (val: Dayjs[], mode: string[]) => {
60+
const handlePanelChange2 = (val: [Dayjs, Dayjs], mode: any[]) => {
6161
value.value = val;
6262
mode2.value = [
6363
mode[0] === 'date' ? 'month' : mode[0],

components/date-picker/demo/presetted-ranges.vue

+7-3
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,16 @@ We can set presetted ranges to RangePicker to improve user experience.
3131
<script lang="ts">
3232
import dayjs, { Dayjs } from 'dayjs';
3333
import { defineComponent, ref } from 'vue';
34+
type RangeValue = [Dayjs, Dayjs];
3435
export default defineComponent({
3536
setup() {
3637
return {
37-
value1: ref<Dayjs[]>([]),
38-
value2: ref<Dayjs[]>([]),
39-
ranges: { Today: [dayjs(), dayjs()], 'This Month': [dayjs(), dayjs().endOf('month')] },
38+
value1: ref<RangeValue>(),
39+
value2: ref<RangeValue>(),
40+
ranges: {
41+
Today: [dayjs(), dayjs()] as RangeValue,
42+
'This Month': [dayjs(), dayjs().endOf('month')] as RangeValue,
43+
},
4044
};
4145
},
4246
});

components/date-picker/demo/range-picker.vue

+6-5
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@ Set range picker type by `picker` prop.
2828
<script lang="ts">
2929
import { defineComponent, ref } from 'vue';
3030
import type { Dayjs } from 'dayjs';
31+
type RangeValue = [Dayjs, Dayjs];
3132
export default defineComponent({
3233
setup() {
3334
return {
34-
value1: ref<Dayjs[]>([]),
35-
value2: ref<Dayjs[]>([]),
36-
value3: ref<Dayjs[]>([]),
37-
value4: ref<Dayjs[]>([]),
38-
value5: ref<Dayjs[]>([]),
35+
value1: ref<RangeValue>(),
36+
value2: ref<RangeValue>(),
37+
value3: ref<RangeValue>(),
38+
value4: ref<RangeValue>(),
39+
value5: ref<RangeValue>(),
3940
};
4041
},
4142
});

components/date-picker/demo/select-in-range.vue

+9-8
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ A example shows how to select a dynamic range by using `onCalendarChange` and `d
2727
<script lang="ts">
2828
import { Dayjs } from 'dayjs';
2929
import { defineComponent, ref } from 'vue';
30+
type RangeValue = [Dayjs, Dayjs];
3031
export default defineComponent({
3132
setup() {
32-
const dates = ref<Dayjs[]>([]);
33-
const value = ref<Dayjs[]>();
34-
const hackValue = ref<Dayjs[]>();
33+
const dates = ref<RangeValue>();
34+
const value = ref<RangeValue>();
35+
const hackValue = ref<RangeValue>();
3536
3637
const disabledDate = (current: Dayjs) => {
37-
if (!dates.value || dates.value.length === 0) {
38+
if (!dates.value) {
3839
return false;
3940
}
4041
const tooLate = dates.value[0] && current.diff(dates.value[0], 'days') > 7;
@@ -44,18 +45,18 @@ export default defineComponent({
4445
4546
const onOpenChange = (open: boolean) => {
4647
if (open) {
47-
dates.value = [];
48-
hackValue.value = [];
48+
dates.value = null;
49+
hackValue.value = null;
4950
} else {
5051
hackValue.value = undefined;
5152
}
5253
};
5354
54-
const onChange = (val: Dayjs[]) => {
55+
const onChange = (val: RangeValue) => {
5556
value.value = val;
5657
};
5758
58-
const onCalendarChange = (val: Dayjs[]) => {
59+
const onCalendarChange = (val: RangeValue) => {
5960
dates.value = val;
6061
};
6162

components/date-picker/demo/size.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { defineComponent, ref } from 'vue';
3434
export default defineComponent({
3535
setup() {
3636
return {
37-
size: ref<string>('default'),
37+
size: ref<any>('default'),
3838
};
3939
},
4040
});

components/date-picker/demo/start-end.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import { Dayjs } from 'dayjs';
4646
import { defineComponent, ref, watch } from 'vue';
4747
export default defineComponent({
4848
setup() {
49-
const startValue = ref<Dayjs | undefined>();
49+
const startValue = ref<Dayjs>();
5050
const endValue = ref<Dayjs>();
5151
const endOpen = ref<boolean>(false);
5252

components/date-picker/demo/suffix.vue

+7-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Customize the suffix icon through `suffixIcon`
2828
<SmileOutlined />
2929
</template>
3030
</a-date-picker>
31-
<a-range-picker @change="onChange">
31+
<a-range-picker @change="onRangeChange">
3232
<template #suffixIcon>
3333
<SmileOutlined />
3434
</template>
@@ -40,7 +40,7 @@ Customize the suffix icon through `suffixIcon`
4040
</a-date-picker>
4141
<a-date-picker suffix-icon="ab" @change="onChange" />
4242
<a-date-picker suffix-icon="ab" placeholder="Select month" picker="month" @change="onChange" />
43-
<a-range-picker suffix-icon="ab" @change="onChange" />
43+
<a-range-picker suffix-icon="ab" @change="onRangeChange" />
4444
<a-date-picker suffix-icon="ab" placeholder="Select week" picker="week" @change="onChange" />
4545
</a-space>
4646
</template>
@@ -53,12 +53,16 @@ export default defineComponent({
5353
SmileOutlined,
5454
},
5555
setup() {
56-
const onChange = (date: Dayjs, dateString: string[]) => {
56+
const onChange = (date: Dayjs | string, dateString: string) => {
5757
console.log(date, dateString);
5858
};
5959
60+
const onRangeChange = (date: [Dayjs, Dayjs], dateString: [string, string]) => {
61+
console.log(date, dateString);
62+
};
6063
return {
6164
onChange,
65+
onRangeChange,
6266
};
6367
},
6468
});

components/date-picker/demo/switchable.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import { defineComponent, ref } from 'vue';
3737
export default defineComponent({
3838
setup() {
3939
return {
40-
type: ref('time'),
40+
type: ref<any>('time'),
4141
};
4242
},
4343
});

components/date-picker/demo/text.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { defineComponent, ref } from 'vue';
3434
export default defineComponent({
3535
setup() {
3636
const time1 = ref<Dayjs>();
37-
const time2 = ref<Dayjs>();
37+
const time2 = ref<[Dayjs, Dayjs]>();
3838
3939
const onOk = (value: Dayjs) => {
4040
console.log('onOk: ', value);

components/date-picker/demo/time.vue

+15-4
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ This property provide an additional time selection. When `showTime` is an Object
2323
:show-time="{ format: 'HH:mm' }"
2424
format="YYYY-MM-DD HH:mm"
2525
:placeholder="['Start Time', 'End Time']"
26-
@change="onChange"
27-
@ok="onOk"
26+
@change="onRangeChange"
27+
@ok="onRangeOk"
2828
/>
2929
</a-space>
3030
</template>
@@ -33,18 +33,29 @@ import { Dayjs } from 'dayjs';
3333
import { defineComponent } from 'vue';
3434
export default defineComponent({
3535
setup() {
36-
const onChange = (value: Dayjs[], dateString: string[]) => {
36+
const onChange = (value: Dayjs, dateString: string) => {
3737
console.log('Selected Time: ', value);
3838
console.log('Formatted Selected Time: ', dateString);
3939
};
4040
41-
const onOk = (value: Dayjs[]) => {
41+
const onOk = (value: Dayjs) => {
42+
console.log('onOk: ', value);
43+
};
44+
45+
const onRangeChange = (value: [Dayjs, Dayjs], dateString: [string, string]) => {
46+
console.log('Selected Time: ', value);
47+
console.log('Formatted Selected Time: ', dateString);
48+
};
49+
50+
const onRangeOk = (value: [Dayjs, Dayjs]) => {
4251
console.log('onOk: ', value);
4352
};
4453
4554
return {
4655
onChange,
4756
onOk,
57+
onRangeChange,
58+
onRangeOk,
4859
};
4960
},
5061
});

components/date-picker/generatePicker/generateRangePicker.tsx

+2-11
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,6 @@ export default function generateRangePicker<DateType, ExtraProps = {}>(
4141
'renderExtraFooter',
4242
// 'separator',
4343
],
44-
emits: [
45-
'change',
46-
'panelChange',
47-
'ok',
48-
'openChange',
49-
'update:value',
50-
'update:open',
51-
'calendarChange',
52-
'focus',
53-
'blur',
54-
],
5544
setup(props, { expose, slots, attrs, emit }) {
5645
const formItemContext = useInjectFormItemContext();
5746
devWarning(
@@ -161,6 +150,8 @@ export default function generateRangePicker<DateType, ExtraProps = {}>(
161150
id = formItemContext.id.value,
162151
...restProps
163152
} = p;
153+
delete restProps['onUpdate:value'];
154+
delete restProps['onUpdate:open'];
164155
const { format, showTime } = p as any;
165156

166157
let additionalOverrideProps: any = {};

0 commit comments

Comments
 (0)