Skip to content

Commit

Permalink
Merge fa417c0 into 471a367
Browse files Browse the repository at this point in the history
  • Loading branch information
samiheikki committed Jan 21, 2019
2 parents 471a367 + fa417c0 commit d0c3226
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/vaadin-number-field.html
Expand Up @@ -209,6 +209,12 @@
}

__onInputChange() {
if (this.min && this.value < this.min) {
this.value = this.min;
} else if (this.max && this.value > this.max) {
this.value = this.max;
}

this.checkValidity() && this.__adjustDecimals();
}

Expand Down
14 changes: 14 additions & 0 deletions test/number-field.html
Expand Up @@ -246,6 +246,20 @@
numberField.value = '5';
expect(numberField.validate(), 'value should not be greater than max').to.be.false;
});

it('should prevent setting value over max', () => {
numberField.max = 2;
numberField.value = 5;
numberField.focusElement.dispatchEvent(new Event('change'));
expect(numberField.value).to.be.equal('2');
});

it('should prevent setting value under min', () => {
numberField.min = 2;
numberField.value = 1;
numberField.focusElement.dispatchEvent(new Event('change'));
expect(numberField.value).to.be.equal('2');
});
});

});
Expand Down

0 comments on commit d0c3226

Please sign in to comment.