From 419a8e4f0e6454b9aac30d5800318deabec099cb Mon Sep 17 00:00:00 2001 From: Alan Wang Date: Mon, 4 Jul 2022 20:34:20 +0800 Subject: [PATCH] feat(Calendar): expose getSelectedDate method --- packages/vant/src/calendar/Calendar.tsx | 3 +++ packages/vant/src/calendar/README.md | 1 + packages/vant/src/calendar/README.zh-CN.md | 1 + packages/vant/src/calendar/types.ts | 1 + 4 files changed, 6 insertions(+) diff --git a/packages/vant/src/calendar/Calendar.tsx b/packages/vant/src/calendar/Calendar.tsx index 05f4ee973..4cc859925 100644 --- a/packages/vant/src/calendar/Calendar.tsx +++ b/packages/vant/src/calendar/Calendar.tsx @@ -214,6 +214,8 @@ export default defineComponent({ return !currentDate.value; }); + const getSelectedDate = () => currentDate.value; + // calculate the position of the elements // and find the elements that needs to be rendered const onScroll = () => { @@ -554,6 +556,7 @@ export default defineComponent({ useExpose({ reset, scrollToDate, + getSelectedDate, }); onMountedOrActivated(init); diff --git a/packages/vant/src/calendar/README.md b/packages/vant/src/calendar/README.md index 89e9b0af2..964920756 100644 --- a/packages/vant/src/calendar/README.md +++ b/packages/vant/src/calendar/README.md @@ -348,6 +348,7 @@ Use [ref](https://v3.vuejs.org/guide/component-template-refs.html) to get Calend | --- | --- | --- | --- | | reset | Reset selected date, will reset to default date when no params passed | _date?: Date \| Date[]_ | - | | scrollToDate | Scroll to date | _date: Date_ | - | +| getSelectedDate | get selected date | - | _Date \| Date[] \| null_ | ### Types diff --git a/packages/vant/src/calendar/README.zh-CN.md b/packages/vant/src/calendar/README.zh-CN.md index 9e498ec6f..ed397d9b1 100644 --- a/packages/vant/src/calendar/README.zh-CN.md +++ b/packages/vant/src/calendar/README.zh-CN.md @@ -354,6 +354,7 @@ export default { | --- | --- | --- | --- | | reset | 将选中的日期重置到指定日期,未传参时会重置到默认日期 | _date?: Date \| Date[]_ | - | | scrollToDate | 滚动到某个日期 | _date: Date_ | - | +| getSelectedDate | 获取选中的日期 | - | _Date \| Date[] \| null_ | ### 类型定义 diff --git a/packages/vant/src/calendar/types.ts b/packages/vant/src/calendar/types.ts index 2310b07ca..43f5e7e6e 100644 --- a/packages/vant/src/calendar/types.ts +++ b/packages/vant/src/calendar/types.ts @@ -29,6 +29,7 @@ export type CalendarDayItem = { export type CalendarExpose = { reset: (date?: Date | Date[]) => void; scrollToDate: (targetDate: Date) => void; + getSelectedDate: () => Date | Date[] | null; }; export type CalendarInstance = ComponentPublicInstance<