Skip to content

Commit 22c8916

Browse files
authored
refactor: declare max and min properties as constraints (#4381)
1 parent af96f9a commit 22c8916

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

‎packages/time-picker/src/vaadin-time-picker.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,10 @@ class TimePicker extends PatternMixin(InputControlMixin(ThemableMixin(ElementMix
305305
return ['__updateDropdownItems(i18n.*, min, max, step)'];
306306
}
307307

308+
static get constraints() {
309+
return [...super.constraints, 'min', 'max'];
310+
}
311+
308312
/**
309313
* Used by `InputControlMixin` as a reference to the clear button element.
310314
* @protected

‎packages/time-picker/test/validation.test.js‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,30 @@ describe('validation', () => {
8383
expect(timePicker.inputElement.hasAttribute('invalid')).to.be.true;
8484
});
8585

86+
it('should not validate on min change without value', () => {
87+
timePicker.min = '12:00';
88+
expect(validateSpy.called).to.be.false;
89+
});
90+
91+
it('should validate on min change with value', () => {
92+
timePicker.value = '12:00';
93+
validateSpy.resetHistory();
94+
timePicker.min = '12:00';
95+
expect(validateSpy.calledOnce).to.be.true;
96+
});
97+
98+
it('should not validate on max change without value', () => {
99+
timePicker.max = '12:00';
100+
expect(validateSpy.called).to.be.false;
101+
});
102+
103+
it('should validate on max change with value', () => {
104+
timePicker.value = '12:00';
105+
validateSpy.resetHistory();
106+
timePicker.max = '12:00';
107+
expect(validateSpy.calledOnce).to.be.true;
108+
});
109+
86110
it('should fire a validated event on validation success', () => {
87111
const validatedSpy = sinon.spy();
88112
timePicker.addEventListener('validated', validatedSpy);

0 commit comments

Comments
 (0)