Skip to content

Commit abdf5cc

Browse files
author
Nathan Reyes
committed
Fix event collision (Closes #82). Fix date formatting bug in Safari.
1 parent 3426089 commit abdf5cc

File tree

9 files changed

+70
-22
lines changed

9 files changed

+70
-22
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# v0.7.2
2+
## Bug Fixes
3+
* Fix event collision when using render functions. Closes #82.
4+
* Fix date formatting bug in Safari.
5+
16
# v0.7.1
27
## Bug Fixes
38
* Fix setup crash when not manually specifying a locale

docs/components/date-picker/examples/ExDatePicker.vue

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
:popover-visibility='popoverVisibility'
1717
:popover-direction='popoverDirection'
1818
:popover-align='popoverAlign'
19-
v-model='selectedValue'>
19+
v-model='selectedValue'
20+
@drag='dragValue = $event'
21+
:available-dates='availableDates'
22+
@input='input'
23+
>
2024
</v-date-picker>
2125
</template>
2226

@@ -37,6 +41,8 @@ export default {
3741
},
3842
data() {
3943
return {
44+
dragValue: null,
45+
availableDates: null,
4046
fromPage: null,
4147
toPage: null,
4248
selectedValue: new Date(),
@@ -46,6 +52,28 @@ export default {
4652
},
4753
};
4854
},
55+
watch: {
56+
dragValue(val, oldVal) {
57+
if (!val) {
58+
this.availableDates = null;
59+
} else if (val && !oldVal) {
60+
this.availableDates = {
61+
start: this.addDays(val.start, -2),
62+
end: this.addDays(val.start, 2)
63+
}
64+
}
65+
}
66+
},
67+
methods: {
68+
addDays(date, days) {
69+
const result = new Date(date);
70+
result.setDate(result.getDate() + days);
71+
return result;
72+
},
73+
input() {
74+
alert('input');
75+
}
76+
}
4977
};
5078
</script>
5179

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "v-calendar",
3-
"version": "0.7.1",
3+
"version": "0.7.2",
44
"description": "A clean and extendable plugin for building simple attributed calendars in Vue.js.",
55
"keywords": [
66
"vue",

src/components/Calendar.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import CalendarPane from './CalendarPane';
33
import Tag from './Tag';
44
import AttributeStore from '../utils/attributeStore';
55
import defaults from '../utils/defaults';
6+
import { mergeListeners } from '@/mixins';
67
import {
78
todayComps,
89
pageIsEqualToPage,
@@ -16,25 +17,25 @@ import {
1617
import '../styles/lib.sass';
1718
1819
export default {
20+
mixins: [mergeListeners],
1921
render(h) {
2022
const getPaneComponent = position => h(CalendarPane, {
2123
attrs: {
24+
...this.$attrs,
2225
position,
2326
page: position < 2 ? this.fromPage_ : this.toPage_,
2427
minPage: position < 2 ? this.minPage : this.minToPage,
2528
maxPage: position < 2 ? this.maxFromPage : this.maxPage,
2629
styles: this.themeStyles_,
2730
attributes: this.attributes_,
28-
...this.$attrs,
2931
},
30-
on: {
32+
on: this.mergeListeners({
3133
titleclick: this.titleClick,
3234
'update:page': (val) => {
3335
if (position < 2) this.fromPage_ = val;
3436
else this.toPage_ = val;
3537
},
36-
...this.$listeners,
37-
},
38+
}),
3839
slots: this.$slots,
3940
scopedSlots: this.$scopedSlots,
4041
});

src/components/DatePicker.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ import { addDays } from '@/utils/dateInfo';
1111
import { pageIsBetweenPages } from '@/utils/helpers';
1212
import { isString, isFunction, isObject, isArray } from '@/utils/typeCheckers';
1313
import { format, parse } from '@/utils/fecha';
14+
import { mergeListeners } from '@/mixins';
1415
1516
export default {
17+
mixins: [mergeListeners],
1618
render(h) {
1719
const getPickerComponent = asSlot => h(
1820
this.componentName,
1921
{
2022
attrs: {
23+
...this.$attrs,
2124
value: this.value,
2225
isRequired: this.isRequired,
2326
selectAttribute: this.selectAttribute_,
@@ -26,14 +29,12 @@ export default {
2629
fromPage: this.fromPage_,
2730
toPage: this.toPage_,
2831
themeStyles: this.themeStyles_,
29-
...this.$attrs,
3032
},
31-
on: {
33+
on: this.mergeListeners({
3234
'update:fromPage': val => this.fromPage_ = val,
3335
'update:toPage': val => this.toPage_ = val,
3436
drag: val => this.dragValue = val,
35-
...this.filteredListeners(),
36-
},
37+
}, this.filteredListeners()),
3738
slots: this.$slots,
3839
scopedSlots: this.$scopedSlots,
3940
...(asSlot && {

src/components/DateRangePicker.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
<script>
22
import Calendar from './Calendar';
33
import { rangeNormalizer } from '../utils/pickerProfiles';
4+
import { mergeListeners } from '@/mixins';
45
56
export default {
7+
mixins: [mergeListeners],
68
render(h) {
79
return h(Calendar, {
810
attrs: {
11+
...this.$attrs,
912
attributes: this.attributes_,
1013
themeStyles: this.themeStyles_,
11-
...this.$attrs,
1214
},
13-
on: {
15+
on: this.mergeListeners({
1416
dayclick: this.clickDay,
1517
daymouseenter: this.enterDay,
16-
...this.$listeners,
17-
},
18+
}),
1819
slots: this.$slots,
1920
scopedSlots: this.$scopedSlots,
2021
});

src/components/MultipleDatePicker.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
<script>
22
import Calendar from './Calendar';
33
import { multipleHasValue, singleValuesAreEqual, multipleNormalizer } from '../utils/pickerProfiles';
4+
import { mergeListeners } from '@/mixins';
45
56
export default {
7+
mixins: [mergeListeners],
68
render(h) {
79
return h(Calendar, {
810
attrs: {
9-
attributes: this.attributes_,
1011
...this.$attrs,
12+
attributes: this.attributes_,
1113
},
12-
on: {
14+
on: this.mergeListeners({
1315
dayclick: this.clickDay,
14-
...this.$listeners,
15-
},
16+
}),
1617
slots: this.$slots,
1718
scopedSlots: this.$scopedSlots,
1819
});

src/components/SingleDatePicker.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
<script>
22
import Calendar from './Calendar';
33
import { singleHasValue, singleValuesAreEqual } from '../utils/pickerProfiles';
4+
import { mergeListeners } from '@/mixins';
45
56
export default {
7+
mixins: [mergeListeners],
68
render(h) {
79
return h(Calendar, {
810
attrs: {
9-
attributes: this.attributes_,
1011
...this.$attrs,
12+
attributes: this.attributes_,
1113
},
12-
on: {
14+
on: this.mergeListeners({
1315
dayclick: this.clickDay,
14-
...this.$listeners,
15-
},
16+
}),
1617
slots: this.$slots,
1718
scopedSlots: this.$scopedSlots,
1819
});

src/mixins/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export const mergeListeners = {
2+
methods: {
3+
mergeListeners(sourceListeners, targetListeners = this.$listeners) {
4+
return Object.keys(sourceListeners).reduce((existing, event) => {
5+
existing[event] = existing[event] ? [existing[event], sourceListeners[event]] : sourceListeners[event];
6+
return existing;
7+
}, { ...targetListeners });
8+
},
9+
},
10+
};

0 commit comments

Comments
 (0)