Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Calendar): add click-overlay event #13312

Merged
merged 1 commit into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/vant/src/calendar/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export default defineComponent({
'update:show',
'clickSubtitle',
'clickDisabledDate',
'clickOverlay',
'panelChange',
],

Expand Down Expand Up @@ -512,6 +513,8 @@ export default defineComponent({
}
};

const onClickOverlay = (event: MouseEvent) => emit('clickOverlay', event);

const updateShow = (value: boolean) => emit('update:show', value);

const renderMonth = (date: Date, index: number) => {
Expand Down Expand Up @@ -654,6 +657,7 @@ export default defineComponent({
closeOnPopstate={props.closeOnPopstate}
safeAreaInsetTop={props.safeAreaInsetTop}
closeOnClickOverlay={props.closeOnClickOverlay}
onClickOverlay={onClickOverlay}
onUpdate:show={updateShow}
/>
);
Expand Down
1 change: 1 addition & 0 deletions packages/vant/src/calendar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ Following props are supported when the type is multiple
| over-range | Emitted when exceeded max range | - |
| click-subtitle | Emitted when clicking the subtitle | _event: MouseEvent_ |
| click-disabled-date `v4.7.0` | Emitted when clicking disabled date | _value: Date \| Date[]_ |
| click-overlay `v4.9.16` | Emitted when overlay is clicked | _event: MouseEvent_ |
| panel-change | Emitted when switching calendar panel (effective when `switch mode` is not `none`) | _{ date: Date }_ |

### Slots
Expand Down
1 change: 1 addition & 0 deletions packages/vant/src/calendar/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ export default {
| over-range | 范围选择超过最多可选天数时触发 | - |
| click-subtitle | 点击日历副标题时触发 | _event: MouseEvent_ |
| click-disabled-date `v4.7.0` | 点击禁用日期时触发 | _value: Date \| Date[]_ |
| click-overlay `v4.9.16` | 点击遮罩层时触发 | _event: MouseEvent_ |
| panel-change | 日历面板切换时触发(`switch-mode` 不为 `none` 时生效) | _{ date: Date }_ |

### Slots
Expand Down
16 changes: 16 additions & 0 deletions packages/vant/src/calendar/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,22 @@ test('popup wrapper', async () => {
expect(wrapper.find('.van-calendar__popup').style.display).toEqual('none');
});

test('should trigger click-overlay event when overlay is clicked', async () => {
const onClickOverlay = vi.fn();
const wrapper = mount(Calendar, {
props: {
minDate,
maxDate,
defaultDate: minDate,
show: true,
onClickOverlay,
},
});

wrapper.find('.van-overlay').trigger('click');
expect(onClickOverlay).toHaveBeenCalled();
});

test('set show-mark prop to false', async () => {
const wrapper = mount(Calendar, {
props: {
Expand Down
Loading