Skip to content

Commit 376a7ef

Browse files
committed
feat: ignore whitespace around separator on manual range input (#416)
1 parent 17d2262 commit 376a7ef

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

__test__/date-picker.test.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,8 @@ describe('DatePicker', () => {
355355

356356
it('should emit pick event on first click', () => {
357357
wrapper = mount(DatePicker, {
358-
range: true,
359358
propsData: {
359+
range: true,
360360
open: true,
361361
defaultValue: new Date(2019, 9, 1),
362362
},
@@ -365,4 +365,23 @@ describe('DatePicker', () => {
365365
td.trigger('click');
366366
expect(wrapper.emitted().pick[0][0]).toEqual(new Date(2019, 8, 29));
367367
});
368+
369+
it('Ignore whitespace around separator on manual range input', () => {
370+
const rangeSeparator = ' ~ ';
371+
const text = '2020-02-12';
372+
wrapper = mount(DatePicker, {
373+
propsData: {
374+
range: true,
375+
rangeSeparator: ' ~ ',
376+
valueType: 'format',
377+
},
378+
});
379+
const input = wrapper.find('input');
380+
381+
input.setValue(`${text} ${rangeSeparator} ${text}`);
382+
input.trigger('change');
383+
input.setValue(`${text}${rangeSeparator.trim()}${text}`);
384+
input.trigger('change');
385+
expect(wrapper.emitted().input).toEqual([[[text, text]], [[text, text]]]);
386+
});
368387
});

src/date-picker.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,14 +419,14 @@ export default {
419419
},
420420
handleInputChange() {
421421
if (!this.editable || this.userInput === null) return;
422-
const text = this.userInput;
422+
const text = this.userInput.trim();
423423
this.userInput = null;
424424
if (text === '') {
425425
this.handleClear();
426426
return;
427427
}
428428
const date = this.range
429-
? text.split(this.rangeSeparator).map(v => this.parseDate(v, this.format))
429+
? text.split(this.rangeSeparator.trim()).map(v => this.parseDate(v.trim(), this.format))
430430
: this.parseDate(text, this.format);
431431
if (this.isValidValue(date)) {
432432
this.emitValue(date);

0 commit comments

Comments
 (0)