Skip to content

Commit

Permalink
fix: always strip input value to match step interval (#8421) (#8423)
Browse files Browse the repository at this point in the history
  • Loading branch information
vursen authored Jan 2, 2025
1 parent 9e0098b commit 90056f0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/time-picker/src/vaadin-time-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,11 @@ class TimePicker extends PatternMixin(InputControlMixin(ThemableMixin(ElementMix
__updateValue(obj) {
const timeString = this.__formatISO(this.__validateTime(obj)) || '';
this.value = timeString;

// Always strip the input value to match the step interval, even
// if the component value hasn't changed. For example, if the step
// is 3600 "10:00:50" should become "10:00".
this.__updateInputValue(obj);
}

/** @private */
Expand Down
16 changes: 16 additions & 0 deletions packages/time-picker/test/value-commit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,22 @@ describe('value commit', () => {
expectValueCommit('23:59:59');
});

it('should strip milliseconds and commit on Enter', async () => {
await sendKeys({ type: '10:00:00.000' });
await sendKeys({ press: 'Enter' });
expectValueCommit('10:00:00');
expect(timePicker.inputElement.value).to.equal('10:00:00');
});

it('should strip milliseconds without commit on Enter if value was unchanged', async () => {
timePicker.value = '10:00:00';
valueChangedSpy.resetHistory();
await sendKeys({ type: '.000' });
await sendKeys({ press: 'Enter' });
expectNoValueCommit();
expect(timePicker.inputElement.value).to.equal('10:00:00');
});

describe('with arrow key committed', () => {
beforeEach(async () => {
await sendKeys({ press: 'ArrowDown' });
Expand Down

0 comments on commit 90056f0

Please # to comment.