Skip to content

Commit

Permalink
feat: add prop defaultPanel (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
mengxiong10 committed Dec 19, 2019
1 parent a756753 commit 73a1b73
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
11 changes: 11 additions & 0 deletions __test__/calendar-panel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,15 @@ describe('CalendarPanel', () => {
.trigger('click');
expect(wrapper.emitted().select[1][0]).toEqual(new Date(2010, 0, 4));
});

it('prop: defaultPanel', () => {
wrapper = mount(CalendarPanel, {
propsData: {
open: true,
type: 'month',
defaultPanel: 'year',
},
});
expect(wrapper.vm.panel).toBe('year');
});
});
8 changes: 6 additions & 2 deletions src/calendar/calendar-panel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ export default {
return date;
},
},
defaultPanel: {
type: String,
},
disabledDate: {
type: Function,
default: () => false,
Expand Down Expand Up @@ -167,8 +170,9 @@ export default {
},
},
data() {
const panels = ['date', 'year', 'month'];
const panel = panels.indexOf(this.type) !== -1 ? this.type : 'date';
const panels = ['date', 'month', 'year'];
const index = Math.max(panels.indexOf(this.type), panels.indexOf(this.defaultPanel));
const panel = index !== -1 ? panels[index] : 'date';
return {
panel,
innerCalendar: null,
Expand Down

0 comments on commit 73a1b73

Please sign in to comment.