Skip to content
This repository was archived by the owner on Mar 14, 2025. It is now read-only.

Commit 6ab87dc

Browse files
committed
Add events prop to customize emitted events, #53
1 parent f9e5acc commit 6ab87dc

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

Diff for: CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## [6.1.0](https://github.com/ankurk91/vue-flatpickr-component/compare/6.0.0...6.1.0)
4+
* Add: `events` props to customise the emitted events, fixes [#53](https://github.com/ankurk91/vue-flatpickr-component/issues/53)
5+
```html
6+
<flatpickr v-model="date" events="['onChange']">
7+
```
8+
- `events` prop is optional and component emits all events when prop is not specified.
9+
310
## [6.0.0](https://github.com/ankurk91/vue-flatpickr-component/compare/5.0.5...6.0.0)
411
* Add: emit all events, fixes [#37](https://github.com/ankurk91/vue-flatpickr-component/issues/37)
512
* Fix: dynamically change configs, [#20](https://github.com/ankurk91/vue-flatpickr-component/issues/20)

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ The component accepts these props:
154154
| :--- | :---: | :---: | :--- |
155155
| v-model / value | String / Date Object / Array / Timestamp / null | `null` | Set or Get date-picker value (required) |
156156
| config | Object | `{wrap:false}` | Flatpickr configuration [options](https://chmln.github.io/flatpickr/options/)|
157+
| events | Array | Array of all events | Customise the [events](https://chmln.github.io/flatpickr/events/) to be emitted|
157158

158159
## Install in non-module environments (without webpack)
159160
* Include required files

Diff for: __test__/events.spec.js

+19
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,24 @@ describe('Flatpickr events', () => {
4646
expect(onChangeStub).toHaveBeenCalled();
4747
});
4848

49+
test('emits only those are specified via prop', () => {
50+
wrapper = shallow(Component, {
51+
propsData: {
52+
value: null,
53+
events: ['onChange']
54+
}
55+
});
56+
57+
const onOpen = jest.fn();
58+
wrapper.vm.$on('on-open', onOpen);
59+
wrapper.trigger('focus');
60+
expect(onOpen).not.toHaveBeenCalled();
61+
62+
const onChange = jest.fn();
63+
wrapper.vm.$on('on-change', onChange);
64+
wrapper.setProps({value: '2017-10-04'});
65+
expect(onChange).toHaveBeenCalled();
66+
});
67+
4968

5069
});

Diff for: src/component.vue

+8-3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
wrap: false
5151
})
5252
},
53+
events: {
54+
type: Array,
55+
default: () => hooks
56+
}
5357
},
5458
data() {
5559
return {
@@ -64,8 +68,8 @@
6468
/* istanbul ignore if */
6569
if (this.fp) return;
6670
67-
// Inject our method into hooks array
68-
hooks.forEach((hook) => {
71+
// Inject our method into events array
72+
this.events.forEach((hook) => {
6973
this.config[hook] = arrayify(this.config[hook] || []).concat((...args) => {
7074
this.$emit(camelToKebab(hook), ...args)
7175
});
@@ -104,7 +108,8 @@
104108
config: {
105109
deep: true,
106110
handler(newConfig) {
107-
// Workaround: Don't pass hooks to configs again
111+
// Workaround: Don't pass hooks to configs again otherwise
112+
// previously registered hooks will stop working
108113
hooks.forEach((hook) => {
109114
delete newConfig[hook];
110115
});

0 commit comments

Comments
 (0)