Skip to content

Commit

Permalink
Merge 070c5cc into 91f3671
Browse files Browse the repository at this point in the history
  • Loading branch information
tomivirkki committed Nov 14, 2019
2 parents 91f3671 + 070c5cc commit edab9b4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/vaadin-number-field.html
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@
}

__onInputChange() {
this.checkValidity();
this.validate();
}

_stepOrMinChanged(step, min) {
Expand All @@ -344,7 +344,7 @@
checkValidity() {
// text-field mixin does not check against `min`, `max` and `step`
if (this.min !== undefined || this.max !== undefined || this.step !== 1) {
this.invalid = !this.inputElement.checkValidity();
return this.inputElement.checkValidity();
}
return super.checkValidity();
}
Expand Down
26 changes: 26 additions & 0 deletions test/number-field.html
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,32 @@
expect(numberField.validate()).to.be.true;
});

it('should align checkValidity with the native input element', () => {
numberField.value = -1;
numberField.min = 0;

expect(numberField.checkValidity()).to.equal(numberField.inputElement.checkValidity());
});

it('should not validate when explicitly set to invalid', () => {
numberField.invalid = true;

expect(numberField.value).to.be.empty;
expect(numberField.validate()).to.be.false;

expect(numberField.invalid).to.be.true;
});

it('should validate when inherited validation constraint is provided and explicitly set to invalid', () => {
numberField.invalid = true;
numberField.maxlength = 5;

expect(numberField.value).to.be.empty;
expect(numberField.validate()).to.be.true;

expect(numberField.invalid).to.be.false;
});

it('should allow setting decimals', () => {
numberField.value = 7.6;
expect(numberField.value).to.be.equal('7.6');
Expand Down

0 comments on commit edab9b4

Please sign in to comment.