Skip to content

Commit

Permalink
Merge 3a39671 into bd1208d
Browse files Browse the repository at this point in the history
  • Loading branch information
Nii Yeboah committed Feb 4, 2020
2 parents bd1208d + 3a39671 commit 8bdc5ab
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/vaadin-date-picker-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
observer: '_openedChanged'
},

/**
* Set true to prevent the overlay from opening automatically.
*/
autoOpenDisabled: Boolean,

/**
* Set true to display ISO-8601 week numbers in the calendar. Notice that
* displaying week numbers is only supported when `i18n.firstDayOfWeek`
Expand Down Expand Up @@ -329,7 +334,7 @@
// then the following composedPath check could be simplified down
// to `if (!e.defaultPrevented)`.
// https://github.com/vaadin/vaadin-text-field/issues/352
if (!isClearButton(e)) {
if (!isClearButton(e) && (!this.autoOpenDisabled || this._noInput)) {
this.open();
}
});
Expand All @@ -342,7 +347,10 @@
this.addEventListener('keydown', this._onKeydown.bind(this));
this.addEventListener('input', this._onUserInput.bind(this));
this.addEventListener('focus', e => this._noInput && e.target.blur());
this.addEventListener('blur', e => !this.opened && this.validate());
this.addEventListener('blur', e => {
this.autoOpenDisabled && this._onOverlayClosed();
!this.opened && this.validate();
});
}

_initOverlay() {
Expand Down Expand Up @@ -844,7 +852,7 @@
}

_onUserInput(e) {
if (!this.opened && this._inputElement.value) {
if (!this.opened && this._inputElement.value && !this.autoOpenDisabled) {
this.open();
}
this._userInputValueChanged();
Expand Down
16 changes: 16 additions & 0 deletions test/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@
listenForEvent(datepicker.$.overlay, 'vaadin-overlay-open', done);
});

it('should not open on input tap when autoOpenDisabled is true and not on mobile', () => {
datepicker.autoOpenDisabled = true;
tap(datepicker.$.input);
if (!datepicker._noInput) {
expect(datepicker.opened).not.to.be.true;
} else {
expect(datepicker.opened).to.be.true;
}
});

it('should pass the placeholder attribute to the input tag', () => {
var placeholder = 'Pick a date';
datepicker.set('placeholder', placeholder);
Expand Down Expand Up @@ -240,6 +250,12 @@
listenForEvent(datepicker.$.overlay, 'vaadin-overlay-open', done);
});

it('should open by tapping the calendar icon even if autoOpenDisabled is true', done => {
this.autoOpenDisabled = true;
tap(toggleButton);
listenForEvent(datepicker.$.overlay, 'vaadin-overlay-open', done);
});

it('should scroll to a date on open', done => {
const overlayContent = getOverlayContent(datepicker);
// We must scroll to a date on every open because at least IE11 seems to reset
Expand Down
8 changes: 8 additions & 0 deletions test/custom-input.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@
datepicker._nativeInput.dispatchEvent(new CustomEvent('input', {bubbles: true}));
});

it('should not open calendar on input when autoOpenDisabled is true', () => {
var target = datepicker._inputElement;
datepicker.autoOpenDisabled = true;
target.bindValue = '1';
datepicker._nativeInput.dispatchEvent(new CustomEvent('input', {bubbles: true}));
expect(datepicker.$.overlay.opened).not.to.be.true;
});

it('should show week numbers', () => {
datepicker.showWeekNumbers = true;
expect(overlayContent.showWeekNumbers).to.equal(true);
Expand Down
20 changes: 20 additions & 0 deletions test/keyboard-input.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,26 @@
expect(datepicker.opened).to.be.true;
});

it('should not open overlay on input if autoOpenDisabled is true', () => {
datepicker.autoOpenDisabled = true;
inputChar('j');
expect(datepicker.opened).not.to.be.true;
});

it('should set datepicker value on blur if autoOpenDisabled is true', () => {
datepicker.autoOpenDisabled = true;
inputChar('1/1/2000');
datepicker.dispatchEvent(new Event('blur'));
expect(datepicker.value).to.equal('2000-01-01');
});

it('should not be invalid on blur if valid date is enetered and autoOpenDisabled is true', () => {
datepicker.autoOpenDisabled = true;
inputChar('1/1/2000');
datepicker.dispatchEvent(new Event('blur'));
expect(datepicker.invalid).not.to.be.true;
});

it('should not focus with unparseable date', () => {
inputChar('j');

Expand Down
16 changes: 16 additions & 0 deletions test/keyboard-navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,29 @@
expect(datepicker.opened).to.be.true;
});

it('should open overlay on down even if autoOpenDisabled is true', () => {
datepicker.autoOpenDisabled = true;
target = datepicker.$.input;
arrowDown();

expect(datepicker.opened).to.be.true;
});

it('should open overlay on up', () => {
target = datepicker.$.input;
arrowUp();

expect(datepicker.opened).to.be.true;
});

it('should open overlay on up even if autoOpenDisabled is true', () => {
datepicker.autoOpenDisabled = true;
target = datepicker.$.input;
arrowUp();

expect(datepicker.opened).to.be.true;
});

it('should close overlay on esc', done => {
datepicker.open();
target = datepicker.$.overlay;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8bdc5ab

Please sign in to comment.