Skip to content

Commit

Permalink
fix(ui5-date-picker): open correct picker (#8371)
Browse files Browse the repository at this point in the history
fixes: #8218
  • Loading branch information
tsanislavgatev authored Mar 1, 2024
1 parent 1ee820a commit 78b98a5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/main/src/DatePicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,22 @@ class DatePicker extends DateComponentBase implements IFormElement {
return false;
}

/**
* Returns the first picker depending on the CalendarPickerMode
*/
get firstPicker() {
const calendarPickerMode = this._calendarPickersMode;
let firstPicker = "day";

if (calendarPickerMode === CalendarPickersMode.YEAR) {
firstPicker = "year";
} else if (calendarPickerMode === CalendarPickersMode.MONTH_YEAR) {
firstPicker = "month";
}

return firstPicker;
}

/**
* Defines whether the value help icon is hidden
* @private
Expand Down Expand Up @@ -795,7 +811,7 @@ class DatePicker extends DateComponentBase implements IFormElement {
*/
async openPicker(): Promise<void> {
this._isPickerOpen = true;
this._calendarCurrentPicker = "day";
this._calendarCurrentPicker = this.firstPicker;
this.responsivePopover = await this._respPopover();

this.responsivePopover.showAt(this);
Expand Down
24 changes: 24 additions & 0 deletions packages/main/test/specs/DatePicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1345,4 +1345,28 @@ describe("Date Picker Tests", () => {

assert.strictEqual(await input.getProperty("valueState"), valueState, "value state is not changed");
});

it("should open date picker in daypicker", async () => {
datepicker.id = "#dpCalendarModeMonths";

const calendar = await datepicker.getCalendar();
const datepickerRoot = await datepicker.getRoot();
await datepicker.openPicker();

let currentPicker = await calendar.getProperty("_currentPicker");
assert.equal(currentPicker, "month", "calendar is opened on months");

await datepickerRoot.setAttribute("format-pattern", "yyyy, dd/MM");
await datepicker.openPicker();
currentPicker = await calendar.getProperty("_currentPicker");

assert.equal(currentPicker, "day", "calendar is opened on days");

const dayPicker = await calendar.shadow$("ui5-daypicker");
const monthPicker = await calendar.shadow$("ui5-monthpicker");
const yearPicker = await calendar.shadow$("ui5-yearpicker");
assert.notOk(await dayPicker.getAttribute("hidden"));
assert.ok(await monthPicker.getAttribute("hidden"));
assert.ok(await yearPicker.getAttribute("hidden"));
});
});

0 comments on commit 78b98a5

Please sign in to comment.