Skip to content

Commit

Permalink
Merge 01eaa1e into bd1208d
Browse files Browse the repository at this point in the history
  • Loading branch information
Nii Yeboah committed Jan 28, 2020
2 parents bd1208d + 01eaa1e commit c9c24ad
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 2 deletions.
9 changes: 7 additions & 2 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 Down Expand Up @@ -844,7 +849,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
6 changes: 6 additions & 0 deletions test/keyboard-input.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@
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 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.
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 c9c24ad

Please sign in to comment.