Skip to content

Commit

Permalink
feat: add event panel-change
Browse files Browse the repository at this point in the history
  • Loading branch information
mengxiong10 committed Nov 17, 2020
1 parent 45969a1 commit 3d29b49
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ Set fixed time list to select;
| blur | When input blur | |
| pick | when select date [#429](https://github.com/mengxiong10/vue2-datepicker/issues/429) | date |
| calendar-change | when change the calendar | date, oldDate, type('year'\|'month'\|'last-year'\|'next-year'\|'last-month'\|'next-month'\|'last-decade'\|'next-decade') |
| panel-change | when the calendar panel changes | type('year'\|'month'\|'date'), oldType |

### Slots

Expand Down
1 change: 1 addition & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ data() {
| blur | 当输入框失焦 | |
| pick | 当点击日期时 [#429](https://github.com/mengxiong10/vue2-datepicker/issues/429) | date |
| calendar-change | 当改变年月时 | date, oldDate, type('year'\|'month'\|'last-year'\|'next-year'\|'last-month'\|'next-month'\|'last-decade'\|'next-decade') |
| panel-change | 当日历面板改变时 | type('year'\|'month'\|'date'), oldType |

### Slots

Expand Down
11 changes: 11 additions & 0 deletions __test__/date-picker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,4 +439,15 @@ describe('DatePicker', () => {
expect(wrapper.emitted().input[1]).toBe(undefined);
expect(wrapper.emitted()['input-error'][0][0]).toBe('2020-05-01');
});

it('panel-change event should be emitd', async () => {
wrapper = mount(DatePicker, {
propsData: {
open: true,
},
});
const yearBtn = wrapper.find('.mx-btn-current-year');
await yearBtn.trigger('click');
expect(wrapper.emitted()['panel-change'][0]).toEqual(['year', 'date']);
});
});
2 changes: 2 additions & 0 deletions src/calendar/calendar-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ export default {
this.dispatchDatePicker('calendar-change', calendar, oldCalendar, type);
},
handelPanelChange(panel) {
const oldPanel = this.panel;
this.panel = panel;
this.dispatchDatePicker('panel-change', panel, oldPanel);
},
handleSelectYear(year) {
if (this.type === 'year') {
Expand Down

0 comments on commit 3d29b49

Please sign in to comment.