2
0
mirror of https://github.com/tenrok/vue2-datepicker.git synced 2026-06-05 23:52:26 +03:00

feat: ignore whitespace around separator on manual range input (#416)

This commit is contained in:
mengxiong10
2020-03-06 16:57:06 +08:00
parent 17d2262c59
commit 376a7ef412
2 changed files with 22 additions and 3 deletions
+20 -1
View File
@@ -355,8 +355,8 @@ describe('DatePicker', () => {
it('should emit pick event on first click', () => {
wrapper = mount(DatePicker, {
range: true,
propsData: {
range: true,
open: true,
defaultValue: new Date(2019, 9, 1),
},
@@ -365,4 +365,23 @@ describe('DatePicker', () => {
td.trigger('click');
expect(wrapper.emitted().pick[0][0]).toEqual(new Date(2019, 8, 29));
});
it('Ignore whitespace around separator on manual range input', () => {
const rangeSeparator = ' ~ ';
const text = '2020-02-12';
wrapper = mount(DatePicker, {
propsData: {
range: true,
rangeSeparator: ' ~ ',
valueType: 'format',
},
});
const input = wrapper.find('input');
input.setValue(`${text} ${rangeSeparator} ${text}`);
input.trigger('change');
input.setValue(`${text}${rangeSeparator.trim()}${text}`);
input.trigger('change');
expect(wrapper.emitted().input).toEqual([[[text, text]], [[text, text]]]);
});
});
+2 -2
View File
@@ -419,14 +419,14 @@ export default {
},
handleInputChange() {
if (!this.editable || this.userInput === null) return;
const text = this.userInput;
const text = this.userInput.trim();
this.userInput = null;
if (text === '') {
this.handleClear();
return;
}
const date = this.range
? text.split(this.rangeSeparator).map(v => this.parseDate(v, this.format))
? text.split(this.rangeSeparator.trim()).map(v => this.parseDate(v.trim(), this.format))
: this.parseDate(text, this.format);
if (this.isValidValue(date)) {
this.emitValue(date);