mirror of
https://gitee.com/vant-contrib/vant.git
synced 2026-07-11 08:41:05 +08:00
Compare commits
No commits in common. "b5ea1cd3ad1b87863c1ddbd8d4ca003b1b0c6af3" and "8bc924ea624b1a5216a23cc0c19f74748b4065a6" have entirely different histories.
b5ea1cd3ad
...
8bc924ea62
@ -115,9 +115,8 @@ export default defineComponent({
|
||||
'confirm',
|
||||
'unselect',
|
||||
'month-show',
|
||||
'over-range',
|
||||
'update:show',
|
||||
'click-subtitle',
|
||||
'over-range',
|
||||
],
|
||||
|
||||
setup(props, { emit, slots }) {
|
||||
@ -490,15 +489,12 @@ export default defineComponent({
|
||||
const renderCalendar = () => (
|
||||
<div class={bem()}>
|
||||
<CalendarHeader
|
||||
v-slots={pick(slots, ['title', 'subtitle'])}
|
||||
v-slots={{ title: slots.title }}
|
||||
title={props.title}
|
||||
subtitle={state.subtitle}
|
||||
showTitle={props.showTitle}
|
||||
subtitle={state.subtitle}
|
||||
showSubtitle={props.showSubtitle}
|
||||
firstDayOfWeek={dayOffset.value}
|
||||
onClick-subtitle={(event: MouseEvent) => {
|
||||
emit('click-subtitle', event);
|
||||
}}
|
||||
/>
|
||||
<div ref={bodyRef} class={bem('body')} onScroll={onScroll}>
|
||||
{months.value.map(renderMonth)}
|
||||
|
||||
@ -15,9 +15,7 @@ export default defineComponent({
|
||||
firstDayOfWeek: Number,
|
||||
},
|
||||
|
||||
emits: ['click-subtitle'],
|
||||
|
||||
setup(props, { slots, emit }) {
|
||||
setup(props, { slots }) {
|
||||
const renderTitle = () => {
|
||||
if (props.showTitle) {
|
||||
const text = props.title || t('title');
|
||||
@ -26,18 +24,9 @@ export default defineComponent({
|
||||
}
|
||||
};
|
||||
|
||||
const onClickSubtitle = (event: MouseEvent) => {
|
||||
emit('click-subtitle', event);
|
||||
};
|
||||
|
||||
const renderSubtitle = () => {
|
||||
if (props.showSubtitle) {
|
||||
const title = slots.subtitle ? slots.subtitle() : props.subtitle;
|
||||
return (
|
||||
<div class={bem('header-subtitle')} onClick={onClickSubtitle}>
|
||||
{title}
|
||||
</div>
|
||||
);
|
||||
return <div class={bem('header-subtitle')}>{props.subtitle}</div>;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -326,14 +326,12 @@ Following props are supported when the type is multiple
|
||||
| unselect | Emitted when unselect date when type is multiple | _value: Date_ |
|
||||
| month-show | Emitted when a month enters the visible area | _{ date: Date, title: string }_ |
|
||||
| over-range | Emitted when exceeded max range | - |
|
||||
| click-subtitle `v3.1.3` | Emitted when clicking the subtitle | _event: MouseEvent_ |
|
||||
|
||||
### Slots
|
||||
|
||||
| Name | Description | SlotProps |
|
||||
| --------------------- | ------------------------- | ---------- |
|
||||
| title | Custom title | - |
|
||||
| subtitle `v3.1.3` | Custom subtitle | - |
|
||||
| footer | Custom footer | - |
|
||||
| top-info `v3.0.17` | Custom top info of day | _day: Day_ |
|
||||
| bottom-info `v3.0.17` | Custom bottom info of day | _day: Day_ |
|
||||
|
||||
@ -332,14 +332,12 @@ export default {
|
||||
| unselect | 当日历组件的 `type` 为 `multiple` 时,取消选中日期时触发 | _value: Date_ |
|
||||
| month-show | 当某个月份进入可视区域时触发 | _{ date: Date, title: string }_ |
|
||||
| over-range | 范围选择超过最多可选天数时触发 | - |
|
||||
| click-subtitle `v3.1.3` | 点击日历副标题时触发 | _event: MouseEvent_ |
|
||||
|
||||
### Slots
|
||||
|
||||
| 名称 | 说明 | 参数 |
|
||||
| --------------------- | ------------------------ | ---------- |
|
||||
| title | 自定义标题 | - |
|
||||
| subtitle `v3.1.3` | 自定义日历副标题 | - |
|
||||
| footer | 自定义底部区域内容 | - |
|
||||
| top-info `v3.0.17` | 自定义日期上方的提示信息 | _day: Day_ |
|
||||
| bottom-info `v3.0.17` | 自定义日期下方的提示信息 | _day: Day_ |
|
||||
|
||||
@ -900,14 +900,28 @@ exports[`row-height prop 1`] = `
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`should render title、footer、subtitle slot correctly 1`] = `
|
||||
exports[`should render top-info and bottom-info slot correctly 1`] = `
|
||||
<div role="gridcell"
|
||||
style="margin-left: 71.42857142857143%;"
|
||||
class="van-calendar__day van-calendar__day--disabled"
|
||||
>
|
||||
<div class="van-calendar__top-info">
|
||||
top: 1
|
||||
</div>
|
||||
1
|
||||
<div class="van-calendar__bottom-info">
|
||||
bottom: 1
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`title & footer slot 1`] = `
|
||||
<div class="van-calendar">
|
||||
<div class="van-calendar__header">
|
||||
<div class="van-calendar__header-title">
|
||||
Custom Title
|
||||
</div>
|
||||
<div class="van-calendar__header-subtitle">
|
||||
Custom Subtitle
|
||||
</div>
|
||||
<div class="van-calendar__weekdays">
|
||||
<span class="van-calendar__weekday">
|
||||
@ -1118,18 +1132,3 @@ exports[`should render title、footer、subtitle slot correctly 1`] = `
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`should render top-info and bottom-info slot correctly 1`] = `
|
||||
<div role="gridcell"
|
||||
style="margin-left: 71.42857142857143%;"
|
||||
class="van-calendar__day van-calendar__day--disabled"
|
||||
>
|
||||
<div class="van-calendar__top-info">
|
||||
top: 1
|
||||
</div>
|
||||
1
|
||||
<div class="van-calendar__bottom-info">
|
||||
bottom: 1
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
@ -344,7 +344,7 @@ test('formatter prop', async () => {
|
||||
expect(wrapper.html()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('should render title、footer、subtitle slot correctly', async () => {
|
||||
test('title & footer slot', async () => {
|
||||
const wrapper = mount(Calendar, {
|
||||
props: {
|
||||
minDate,
|
||||
@ -356,7 +356,6 @@ test('should render title、footer、subtitle slot correctly', async () => {
|
||||
slots: {
|
||||
title: () => 'Custom Title',
|
||||
footer: () => 'Custom Footer',
|
||||
subtitle: () => 'Custom Subtitle',
|
||||
},
|
||||
});
|
||||
|
||||
@ -554,18 +553,3 @@ test('should render top-info and bottom-info slot correctly', async () => {
|
||||
|
||||
expect(wrapper.find('.van-calendar__day').html()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('should emit click-subtitle event when clicking the subtitle', async () => {
|
||||
const wrapper = mount(Calendar, {
|
||||
props: {
|
||||
minDate,
|
||||
maxDate,
|
||||
poppable: false,
|
||||
lazyRender: false,
|
||||
},
|
||||
});
|
||||
|
||||
await later();
|
||||
wrapper.find('.van-calendar__header-subtitle').trigger('click');
|
||||
expect(wrapper.emitted('click-subtitle')).toBeTruthy();
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user