Skip to content

Commit

Permalink
fix(ui5-time-picker): support relative value "now" (#7325)
Browse files Browse the repository at this point in the history
* fix(ui5-time-picker): support relative value "now"
  • Loading branch information
hinzzx authored Jul 25, 2023
1 parent d6aeb0f commit 0b2ef4f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/main/src/TimePicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ class TimePicker extends TimePickerBase {
@property()
formatPattern!: string;

onBeforeRendering() {
this.value = this.normalizeValue(this.value!) || this.value;
}

get _formatPattern() {
const hasHours = !!this.formatPattern.match(/H/i);
const fallback = !this.formatPattern || !hasHours;
Expand Down
3 changes: 3 additions & 0 deletions packages/main/test/pages/TimePicker.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
<ui5-time-picker id="timepickerInput"></ui5-time-picker>
<ui5-input id="inputResult"></ui5-input>

<br /><br />
<ui5-title>Test "now" value</ui5-title>
<ui5-time-picker id="timepickerNow" value="now"></ui5-time-picker>

<br /><br />
<ui5-title>Test empty value</ui5-title>
Expand Down
13 changes: 13 additions & 0 deletions packages/main/test/specs/TimePicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,17 @@ describe("TimePicker general interaction", () => {
assert.notOk(await timepickerPopover.isDisplayed(), "the picker should be collapsed");
});

it("the value 'now' returns the current time, instead of the string 'now'", async () => {
await browser.url(`test/pages/TimePicker.html`);

const timepicker = await browser.$("#timepicker");

// act
await timepicker.click();
await browser.keys("now");
await browser.keys("Enter");

// assert that the value in the input is different than the string 'now'
assert.notStrictEqual(await timepicker.shadow$("ui5-input").getProperty("value"), "now", "the value is not 'now'");
});
});

0 comments on commit 0b2ef4f

Please sign in to comment.