DatePicker: fix clear button, fixed #1690 (#1710)

* DatePicker: fix clear button, fixed #1690

* DatePicker: fix reset button style

* DatePicker: fix set value

* DatePicker: fix test
pull/1738/head
cinwell.li 2016-12-13 22:51:43 +08:00 committed by baiyaaaaa
parent 9c7786b203
commit cad3d770ed
7 changed files with 26 additions and 18 deletions

View File

@ -282,7 +282,8 @@
} else if (Array.isArray(newVal)) { } else if (Array.isArray(newVal)) {
this.minDate = newVal[0] ? toDate(newVal[0]) : null; this.minDate = newVal[0] ? toDate(newVal[0]) : null;
this.maxDate = newVal[1] ? toDate(newVal[1]) : null; this.maxDate = newVal[1] ? toDate(newVal[1]) : null;
this.date = new Date(this.minDate); if (this.minDate) this.date = new Date(this.minDate);
this.handleConfirm(true);
} }
} }
}, },
@ -454,8 +455,8 @@
this.resetDate(); this.resetDate();
}, },
handleConfirm() { handleConfirm(visible) {
this.$emit('pick', [this.minDate, this.maxDate]); this.$emit('pick', [this.minDate, this.maxDate], visible);
}, },
resetDate() { resetDate() {

View File

@ -150,6 +150,7 @@
}, },
value(newVal) { value(newVal) {
if (!newVal) return;
newVal = new Date(newVal); newVal = new Date(newVal);
if (!isNaN(newVal)) { if (!isNaN(newVal)) {
if (typeof this.disabledDate === 'function' && if (typeof this.disabledDate === 'function' &&

View File

@ -112,6 +112,13 @@
}; };
}, },
watch: {
value(newVal) {
this.panelCreated();
this.$nextTick(_ => this.ajustScrollTop());
}
},
methods: { methods: {
panelCreated() { panelCreated() {
const time = clacTime(this.value); const time = clacTime(this.value);

View File

@ -72,6 +72,7 @@
minutes: date.getMinutes(), minutes: date.getMinutes(),
seconds: date.getSeconds() seconds: date.getSeconds()
}); });
this.$nextTick(_ => this.ajustScrollTop());
}, },
selectableRange(val) { selectableRange(val) {

View File

@ -85,8 +85,9 @@ const RANGE_FORMATTER = function(value, format) {
const RANGE_PARSER = function(text, format) { const RANGE_PARSER = function(text, format) {
const array = text.split(RANGE_SEPARATOR); const array = text.split(RANGE_SEPARATOR);
if (array.length === 2) { if (array.length === 2) {
const range1 = array[0].split(':').map(item => item.slice(-2)).join(':'); const range1 = array[0];
const range2 = array[1].split(':').map(item => item.slice(-2)).join(':'); const range2 = array[1];
return [parseDate(range1, format), parseDate(range2, format)]; return [parseDate(range1, format), parseDate(range2, format)];
} }
return []; return [];
@ -323,7 +324,6 @@ export default {
handleMouseEnterIcon() { handleMouseEnterIcon() {
if (this.readonly || this.disabled) return; if (this.readonly || this.disabled) return;
if (!this.valueIsEmpty) { if (!this.valueIsEmpty) {
this.visualValue = this.refInput.value;
this.showClose = true; this.showClose = true;
} }
}, },
@ -358,15 +358,10 @@ export default {
handleKeydown(event) { handleKeydown(event) {
const keyCode = event.keyCode; const keyCode = event.keyCode;
const target = event.target;
// tab // tab
if (keyCode === 9) { if (keyCode === 9) {
this.pickerVisible = false; this.pickerVisible = false;
// enter
} else if (keyCode === 13) {
this.pickerVisible = this.picker.visible = false;
this.visualValue = target.value;
} }
}, },

View File

@ -87,7 +87,7 @@
@e link-btn { @e link-btn {
cursor: pointer; cursor: pointer;
color: #55a4ff; color: var(--color-primary);
text-decoration: none; text-decoration: none;
padding: 15px; padding: 15px;
font-size: 12px; font-size: 12px;

View File

@ -145,13 +145,16 @@ describe('DatePicker', () => {
expect(vm.pickerVisible).to.false; expect(vm.pickerVisible).to.false;
}); });
it('enter', () => { it('enter', done => {
input.value = '2000-10-1'; input.value = '2000-10-1';
keyDown(input, 13); triggerEvent(input, 'change', true);
expect(vm.pickerVisible).to.false; setTimeout(_ => {
expect(vm.picker.value.getFullYear()).to.equal(2000); expect(vm.pickerVisible).to.true; //
expect(vm.picker.value.getMonth()).to.equal(9); expect(vm.picker.date.getFullYear()).to.equal(2000);
expect(vm.picker.value.getDate()).to.equal(1); expect(vm.picker.date.getMonth()).to.equal(9);
expect(vm.picker.date.getDate()).to.equal(1);
done();
}, DELAY);
}); });
it('left', () => { it('left', () => {