Skip to content

Commit 73a1b73

Browse files
committed
feat: add prop defaultPanel (#394)
1 parent a756753 commit 73a1b73

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

__test__/calendar-panel.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,15 @@ describe('CalendarPanel', () => {
187187
.trigger('click');
188188
expect(wrapper.emitted().select[1][0]).toEqual(new Date(2010, 0, 4));
189189
});
190+
191+
it('prop: defaultPanel', () => {
192+
wrapper = mount(CalendarPanel, {
193+
propsData: {
194+
open: true,
195+
type: 'month',
196+
defaultPanel: 'year',
197+
},
198+
});
199+
expect(wrapper.vm.panel).toBe('year');
200+
});
190201
});

src/calendar/calendar-panel.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ export default {
139139
return date;
140140
},
141141
},
142+
defaultPanel: {
143+
type: String,
144+
},
142145
disabledDate: {
143146
type: Function,
144147
default: () => false,
@@ -167,8 +170,9 @@ export default {
167170
},
168171
},
169172
data() {
170-
const panels = ['date', 'year', 'month'];
171-
const panel = panels.indexOf(this.type) !== -1 ? this.type : 'date';
173+
const panels = ['date', 'month', 'year'];
174+
const index = Math.max(panels.indexOf(this.type), panels.indexOf(this.defaultPanel));
175+
const panel = index !== -1 ? panels[index] : 'date';
172176
return {
173177
panel,
174178
innerCalendar: null,

0 commit comments

Comments
 (0)