Skip to content

Commit

Permalink
feat: ignore whitespace around separator on manual range input (#416)
Browse files Browse the repository at this point in the history
  • Loading branch information
mengxiong10 committed Mar 6, 2020
1 parent 17d2262 commit 376a7ef
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
21 changes: 20 additions & 1 deletion __test__/date-picker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
Expand All @@ -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]]]);
});
});
4 changes: 2 additions & 2 deletions src/date-picker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 376a7ef

Please sign in to comment.