Skip to content

Commit

Permalink
fix emits
Browse files Browse the repository at this point in the history
  • Loading branch information
cheesytim committed Mar 1, 2021
1 parent f7279f6 commit a28e287
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
30 changes: 13 additions & 17 deletions src/qComponents/QDatePicker/src/QDatePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@

<script>
import { createPopper } from '@popperjs/core';
import { isEqual, isString } from 'lodash-es';
import { isString } from 'lodash-es';
import {
formatISO,
isDate,
Expand Down Expand Up @@ -150,6 +150,11 @@ export default {
}
},
model: {
prop: 'value',
event: 'change'
},
props: {
/**
* one of sugested types
Expand Down Expand Up @@ -395,7 +400,6 @@ export default {
this.createPopper();
} else {
this.destroyPopper();
this.emitChange(this.transformedValue);
this.userInput = null;
if (this.validateEvent) {
this.qFormItem?.validateField('blur');
Expand All @@ -418,7 +422,6 @@ export default {
handlePickClick(val, { hidePicker = true } = {}) {
this.pickerVisible = !hidePicker;
this.emitChange(val);
this.emitInput(val);
},
createPopper() {
Expand Down Expand Up @@ -555,10 +558,9 @@ export default {
resultValue = value;
break;
}
this.emitInput(resultValue);
this.emitChange(resultValue);
}
} else {
this.emitInput(null);
this.emitChange(null);
}
this.userInput = null;
Expand All @@ -568,8 +570,8 @@ export default {
if (this.pickerDisabled) return;
if (this.showClose) {
event.stopPropagation();
this.emitInput(null);
this.emitChange(null);
this.userInput = null;
this.showClose = false;
} else {
this.pickerVisible = !this.pickerVisible;
Expand Down Expand Up @@ -613,22 +615,16 @@ export default {
},
emitChange(val) {
if (val !== this.value) {
this.$emit('change', val);
if (this.validateEvent) {
this.qFormItem?.validateField('change');
}
}
},
emitInput(val) {
let formatted = val;
if (this.outputFormat === 'iso' && val) {
formatted = this.formatToISO(val);
}
if (!isEqual(this.transformedValue, formatted)) {
this.$emit('input', formatted);
if (formatted !== this.value) {
this.$emit('change', formatted);
if (this.validateEvent) {
this.qFormItem?.validateField('change');
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/qComponents/QDatePicker/src/styles/picker-panel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
height: 20px;
padding: 0;
font-size: 20px;
line-height: 21px;

This comment has been minimized.

Copy link
@cheesytim

cheesytim Mar 1, 2021

Author Member

Screenshot 2021-03-01 at 17 00 26
выровнил

color: var(--color-primary-blue);
background: var(--color-tertiary-gray-light);
border: 0;
Expand Down
4 changes: 3 additions & 1 deletion src/qComponents/mixins/pickers.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export default {
array.pop();
}

this.userInput = array.join('');
const parsedInputValue = array.join('');
this.userInput = parsedInputValue;
this.$emit('input', parsedInputValue);
}
}
};
8 changes: 8 additions & 0 deletions stories/components/QDatePicker/Default.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ export default (_, { argTypes }) => ({
methods: {
handleRangePickClick(val) {
console.log('handleRangePickClick', val);
},
handleChange(value) {
console.log('handleChange', value);
},
handleInput(value) {
console.log('handleInput', value);
}
},
watch: {
Expand Down Expand Up @@ -74,6 +80,8 @@ export default (_, { argTypes }) => ({
:range-separator="rangeSeparator"
:validate-event="validateEvent"
@rangepick="handleRangePickClick"
@input="handleInput"
@change="handleChange"
:append-to-body="appendToBody"
/>`
});

0 comments on commit a28e287

Please sign in to comment.