Skip to content

Commit

Permalink
fix: prevent button triggering external form submit (mengxiong10#389)
Browse files Browse the repository at this point in the history
  • Loading branch information
mengxiong10 authored and lleizh committed Dec 6, 2019
1 parent cf4139b commit 664d829
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
15 changes: 15 additions & 0 deletions __test__/__snapshots__/calendar-panel.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ exports[`CalendarPanel prop: type=date 1`] = `
>
<button
class="mx-btn mx-btn-text mx-btn-icon-double-left"
type="button"
>
<i
class="mx-icon-double-left"
Expand All @@ -17,6 +18,7 @@ exports[`CalendarPanel prop: type=date 1`] = `
<button
class="mx-btn mx-btn-text mx-btn-icon-left"
type="button"
>
<i
class="mx-icon-left"
Expand All @@ -25,6 +27,7 @@ exports[`CalendarPanel prop: type=date 1`] = `
<button
class="mx-btn mx-btn-text mx-btn-icon-double-right"
type="button"
>
<i
class="mx-icon-double-right"
Expand All @@ -33,6 +36,7 @@ exports[`CalendarPanel prop: type=date 1`] = `
<button
class="mx-btn mx-btn-text mx-btn-icon-right"
type="button"
>
<i
class="mx-icon-right"
Expand All @@ -44,13 +48,15 @@ exports[`CalendarPanel prop: type=date 1`] = `
>
<button
class="mx-btn mx-btn-text mx-btn-current-month"
type="button"
>
Oct
</button>
<button
class="mx-btn mx-btn-text mx-btn-current-year"
type="button"
>
2019
Expand Down Expand Up @@ -93,6 +99,7 @@ exports[`CalendarPanel prop: type=month 1`] = `
>
<button
class="mx-btn mx-btn-text mx-btn-icon-double-left"
type="button"
>
<i
class="mx-icon-double-left"
Expand All @@ -102,6 +109,7 @@ exports[`CalendarPanel prop: type=month 1`] = `
<button
class="mx-btn mx-btn-text mx-btn-icon-left"
style="display: none;"
type="button"
>
<i
class="mx-icon-left"
Expand All @@ -110,6 +118,7 @@ exports[`CalendarPanel prop: type=month 1`] = `
<button
class="mx-btn mx-btn-text mx-btn-icon-double-right"
type="button"
>
<i
class="mx-icon-double-right"
Expand All @@ -119,6 +128,7 @@ exports[`CalendarPanel prop: type=month 1`] = `
<button
class="mx-btn mx-btn-text mx-btn-icon-right"
style="display: none;"
type="button"
>
<i
class="mx-icon-right"
Expand All @@ -130,6 +140,7 @@ exports[`CalendarPanel prop: type=month 1`] = `
>
<button
class="mx-btn mx-btn-text"
type="button"
>
2019
Expand Down Expand Up @@ -165,6 +176,7 @@ exports[`CalendarPanel prop: type=year 1`] = `
>
<button
class="mx-btn mx-btn-text mx-btn-icon-double-left"
type="button"
>
<i
class="mx-icon-double-left"
Expand All @@ -174,6 +186,7 @@ exports[`CalendarPanel prop: type=year 1`] = `
<button
class="mx-btn mx-btn-text mx-btn-icon-left"
style="display: none;"
type="button"
>
<i
class="mx-icon-left"
Expand All @@ -182,6 +195,7 @@ exports[`CalendarPanel prop: type=year 1`] = `
<button
class="mx-btn mx-btn-text mx-btn-icon-double-right"
type="button"
>
<i
class="mx-icon-double-right"
Expand All @@ -191,6 +205,7 @@ exports[`CalendarPanel prop: type=year 1`] = `
<button
class="mx-btn mx-btn-text mx-btn-icon-right"
style="display: none;"
type="button"
>
<i
class="mx-icon-right"
Expand Down
14 changes: 14 additions & 0 deletions __test__/date-picker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,4 +325,18 @@ describe('DatePicker', () => {
el.trigger('click');
expect(wrapper.emitted().close).toBeTruthy();
});

// present the button submit form
it('the type of all buttons should be button', () => {
wrapper = mount(DatePicker, {
propsData: {
open: true,
showTimePanel: true,
},
});
const els = wrapper.findAll('button');
els.wrappers.forEach(v => {
expect(v.element.type).toBe('button');
});
});
});
6 changes: 6 additions & 0 deletions src/calendar/calendar-panel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,31 @@
<div class="mx-calendar-header">
<button
v-show="showIconDoubleArrow"
type="button"
class="mx-btn mx-btn-text mx-btn-icon-double-left"
@click="handleIconDoubleLeftClick"
>
<i class="mx-icon-double-left"></i>
</button>
<button
v-show="showIconArrow"
type="button"
class="mx-btn mx-btn-text mx-btn-icon-left"
@click="handleIconLeftClick"
>
<i class="mx-icon-left"></i>
</button>
<button
v-show="showIconDoubleArrow"
type="button"
class="mx-btn mx-btn-text mx-btn-icon-double-right"
@click="handleIconDoubleRightClick"
>
<i class="mx-icon-double-right"></i>
</button>
<button
v-show="showIconArrow"
type="button"
class="mx-btn mx-btn-text mx-btn-icon-right"
@click="handleIconRightClick"
>
Expand All @@ -43,6 +47,7 @@
</template>
<button
v-else-if="panel === 'month'"
type="button"
class="mx-btn mx-btn-text"
@click="handelPanelChange('year')"
>
Expand All @@ -52,6 +57,7 @@
<button
v-for="item in dateHeader"
:key="item.panel"
type="button"
:class="`mx-btn mx-btn-text mx-btn-current-${item.panel}`"
@click="handelPanelChange(item.panel)"
>
Expand Down
6 changes: 5 additions & 1 deletion src/time/time-panel.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<template>
<div class="mx-time">
<div v-if="showTimeHeader" class="mx-time-header">
<button class="mx-btn mx-btn-text mx-time-header-title" @click="handleClickTitle">
<button
type="button"
class="mx-btn mx-btn-text mx-time-header-title"
@click="handleClickTitle"
>
{{ title }}
</button>
</div>
Expand Down

0 comments on commit 664d829

Please sign in to comment.