Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui5-calendar): autofocus on render #10739

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions packages/main/src/Calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ interface ICalendarPicker {
_showNextPage: () => void,
_hasPreviousPage: () => boolean,
_hasNextPage: () => boolean,
_autoFocus?: boolean,
_firstYear?: number,
_lastYear?: number,
}
Expand Down Expand Up @@ -441,7 +440,6 @@ class Calendar extends CalendarPart {
if (defaultTypes.includes(this._selectedItemType)) {
this._selectedItemType = "None"; // In order to avoid filtering of default types
}
this._currentPickerDOM._autoFocus = false;
}

/**
Expand Down Expand Up @@ -507,7 +505,6 @@ class Calendar extends CalendarPart {
}

showMonth() {
this._currentPickerDOM._autoFocus = false;
this._currentPicker = "month";
}

Expand All @@ -520,7 +517,6 @@ class Calendar extends CalendarPart {
}

showYear() {
this._currentPickerDOM._autoFocus = false;
this._currentPicker = "year";
}

Expand All @@ -534,21 +530,13 @@ class Calendar extends CalendarPart {
*/
onHeaderPreviousPress() {
this._currentPickerDOM._showPreviousPage();

if (this.calendarLegend) {
this._currentPickerDOM._autoFocus = true;
}
}

/**
* The year clicked the "Next" button in the header
*/
onHeaderNextPress() {
this._currentPickerDOM._showNextPage();

if (this.calendarLegend) {
this._currentPickerDOM._autoFocus = true;
}
}

_setSecondaryCalendarTypeButtonText() {
Expand Down Expand Up @@ -641,8 +629,6 @@ class Calendar extends CalendarPart {
} else {
this._fireEventAndUpdateSelectedDates(e.detail.dates);
}

this._currentPickerDOM._autoFocus = true;
}

onSelectedYearChange(e: CustomEvent<YearPickerChangeEventDetail>) {
Expand All @@ -655,8 +641,6 @@ class Calendar extends CalendarPart {
} else {
this._fireEventAndUpdateSelectedDates(e.detail.dates);
}

this._currentPickerDOM._autoFocus = true;
}

onNavigate(e: CustomEvent) {
Expand Down
14 changes: 0 additions & 14 deletions packages/main/src/DayPicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,6 @@ class DayPicker extends CalendarPart implements ICalendarPicker {
@property({ type: Array })
specialCalendarDates: Array<SpecialCalendarDateT> = [];

_autoFocus?: boolean;

@i18n("@ui5/webcomponents")
static i18nBundle: I18nBundle;

Expand Down Expand Up @@ -401,25 +399,13 @@ class DayPicker extends CalendarPart implements ICalendarPicker {
}

onAfterRendering() {
if (this._autoFocus && !this._hidden) {
this.focus();
}

const focusedDay = this.shadowRoot!.querySelector<HTMLElement>("[data-sap-focus-ref]");

if (focusedDay && document.activeElement !== focusedDay && this._specialCalendarDates.length === 0) {
focusedDay.focus();
}
}

_onfocusin() {
this._autoFocus = true;
}

_onfocusout() {
this._autoFocus = false;
}

/**
* Tells if the day is selected (dark blue).
* @param timestamp
Expand Down
2 changes: 0 additions & 2 deletions packages/main/src/DayPickerTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ export default function DayPickerTemplate(this: DayPicker) {
onKeyUp={this._onkeyup}
onClick={this._onclick}
onMouseOver={this._onmouseover}
onFocusIn={this._onfocusin}
onFocusOut={this._onfocusout}
>
<div id={`${this._id}-content`} class="ui5-dp-content" role="grid" aria-roledescription={this.ariaRoledescription}>
<div role="row" class="ui5-dp-days-names-container">
Expand Down
16 changes: 8 additions & 8 deletions packages/main/test/specs/DatePicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -955,9 +955,9 @@ describe("Date Picker Tests", () => {

it("DayPiker day number attribute", async () => {
await browser.url(`test/pages/DatePicker_test_page.html?sap-ui-language=en`);
datepicker.id = "#dp13";
const root = await datepicker.getRoot();
await root.setAttribute("primary-calendar-type", "Gregorian");
datepicker.id = "#dp13";
await datepicker.openPicker();
await root.keys("May 3, 2100");
await root.keys("Enter");
Expand Down Expand Up @@ -992,9 +992,9 @@ describe("Date Picker Tests", () => {

const data = Array.from(await datepicker.getDayPickerDatesRow(2));
assert.strictEqual(await data[0].getAttribute("aria-label"), "Calendar Week 19", "First columnheader have Week number aria-label");
assert.strictEqual(await data[1].getAttribute("aria-label"), "Non-Working Day May 2, 2100", "Each date have the full date's info in Month Date, Year in aria-label");
assert.strictEqual(await data[2].getAttribute("aria-label"), "May 3, 2100", "Each date have the full date's info in Month Date, Year in aria-label");
assert.strictEqual(await data[3].getAttribute("aria-label"), "May 4, 2100", "Each date have the full date's info in Month Date, Year in aria-label");
assert.strictEqual(await data[1].getAttribute("aria-label"), "May 2, 2100 Non-Working Day ", "Each date have the full date's info in Month Date, Year in aria-label");
assert.strictEqual(await data[2].getAttribute("aria-label"), "May 3, 2100 ", "Each date have the full date's info in Month Date, Year in aria-label");
assert.strictEqual(await data[3].getAttribute("aria-label"), "May 4, 2100 ", "Each date have the full date's info in Month Date, Year in aria-label");

await datepicker.closePicker();
});
Expand Down Expand Up @@ -1284,9 +1284,9 @@ describe("Date Picker Tests", () => {
assert.ok(await monthPicker.getAttribute("hidden"));
assert.notOk(await yearPicker.getAttribute("hidden"));

const timestamp_2014 = 1388534400;
const calendarDate_2014 = await datepicker.getPickerYear(timestamp_2014);
await calendarDate_2014.click();
const timestamp_2015 = 1420070400;
const calendarDate_2015 = await datepicker.getPickerYear(timestamp_2015);
await calendarDate_2015.click();

assert.isFalse(await datepicker.isPickerOpen(), "picker is closed after year selection");
});
Expand Down Expand Up @@ -1414,7 +1414,7 @@ describe("Date Picker Tests", () => {
});

describe("Legacy date customization", () => {
it.only("Customization of legacy dates in Islamic calendar", async () => {
it("Customization of legacy dates in Islamic calendar", async () => {
// According to the Islamic calendar, Rab. I 9, 1446 AH should be displayed on Thursday,
// but it needs to be configured using the legacyDateCalendarCustomizing setting.
datepicker.page = "test/pages/DatePicker_legacy_test_page.html";
Expand Down