Skip to content

Commit b8379bf

Browse files
committed
feat: focus current date if the calendar is opened from popover
1 parent 4ebdcbb commit b8379bf

10 files changed

Lines changed: 47 additions & 19 deletions

packages/main/cypress/specs/DatePicker.cy.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,11 +1363,7 @@ describe("Date Picker Tests", () => {
13631363
.realPress("ArrowDown");
13641364

13651365
cy.get<DatePicker>("@datePicker")
1366-
.shadow()
1367-
.find("ui5-calendar")
1368-
.as("calendar")
1369-
.shadow()
1370-
.find("[data-ui5-cal-header-btn-month]")
1366+
.ui5DatePickerGetDisplayedDay(13)
13711367
.should("have.focus");
13721368
});
13731369

packages/main/src/Calendar.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ import {
5757
CALENDAR_HEADER_MONTH_NEXT_BUTTON_SHORTCUT,
5858
CALENDAR_HEADER_MONTH_PREVIOUS_BUTTON_TITLE,
5959
CALENDAR_HEADER_MONTH_PREVIOUS_BUTTON_SHORTCUT,
60+
CALENDAR_HEADER_YEAR_NEXT_BUTTON_TITLE,
61+
CALENDAR_HEADER_YEAR_PREVIOUS_BUTTON_TITLE,
62+
CALENDAR_HEADER_YEAR_RANGE_NEXT_BUTTON_TITLE,
63+
CALENDAR_HEADER_YEAR_RANGE_PREVIOUS_BUTTON_TITLE,
6064
} from "./generated/i18n/i18n-defaults.js";
6165
import type { YearRangePickerChangeEventDetail } from "./YearRangePicker.js";
6266

@@ -307,6 +311,9 @@ class Calendar extends CalendarPart {
307311
@property({ noAttribute: true })
308312
_pickersMode: `${CalendarPickersMode}` = "DAY_MONTH_YEAR";
309313

314+
@property({ type: Boolean, noAttribute: true })
315+
_isOpenedFromPopover?: boolean = false;
316+
310317
_valueIsProcessed = false;
311318

312319
_rangeStartYear?: number;
@@ -842,8 +849,16 @@ class Calendar extends CalendarPart {
842849
const monthLabel = Calendar.i18nBundle?.getText(CALENDAR_HEADER_MONTH_BUTTON, headerMonthButtonText);
843850
const yearLabel = Calendar.i18nBundle?.getText(CALENDAR_HEADER_YEAR_BUTTON, this._headerYearButtonText as string);
844851
const yearRangeLabel = Calendar.i18nBundle?.getText(CALENDAR_HEADER_YEAR_RANGE_BUTTON, rangeStartText, rangeEndText);
845-
const nextBtnLabel = Calendar.i18nBundle?.getText(CALENDAR_HEADER_MONTH_NEXT_BUTTON_TITLE);
846-
const prevBtnLabel = Calendar.i18nBundle?.getText(CALENDAR_HEADER_MONTH_PREVIOUS_BUTTON_TITLE);
852+
let nextBtnLabel = Calendar.i18nBundle?.getText(CALENDAR_HEADER_MONTH_NEXT_BUTTON_TITLE);
853+
let prevBtnLabel = Calendar.i18nBundle?.getText(CALENDAR_HEADER_MONTH_PREVIOUS_BUTTON_TITLE);
854+
855+
if (this._currentPicker === "month") {
856+
nextBtnLabel = Calendar.i18nBundle?.getText(CALENDAR_HEADER_YEAR_NEXT_BUTTON_TITLE);
857+
prevBtnLabel = Calendar.i18nBundle?.getText(CALENDAR_HEADER_YEAR_PREVIOUS_BUTTON_TITLE);
858+
} else if (this._currentPicker === "year") {
859+
nextBtnLabel = Calendar.i18nBundle?.getText(CALENDAR_HEADER_YEAR_RANGE_NEXT_BUTTON_TITLE);
860+
prevBtnLabel = Calendar.i18nBundle?.getText(CALENDAR_HEADER_YEAR_RANGE_PREVIOUS_BUTTON_TITLE);
861+
}
847862

848863
// Get shortcuts
849864
const monthShortcut = Calendar.i18nBundle?.getText(CALENDAR_HEADER_MONTH_BUTTON_SHORTCUT);
@@ -856,11 +871,15 @@ class Calendar extends CalendarPart {
856871
ariaLabelMonthButton: monthLabel,
857872
ariaLabelYearButton: yearLabel,
858873
ariaLabelYearRangeButton: yearRangeLabel,
874+
ariaLabelNextButton: nextBtnLabel,
875+
ariaLabelPrevButton: prevBtnLabel,
859876

860877
// Keyboard shortcuts for aria-keyshortcuts
861878
keyShortcutMonthButton: monthShortcut,
862879
keyShortcutYearButton: yearShortcut,
863880
keyShortcutYearRangeButton: yearRangeShortcut,
881+
keyShortcutNextButton: nextBtnShortcut,
882+
keyShortcutPrevButton: prevBtnShortcut,
864883

865884
// Tooltips combining label and shortcut
866885
tooltipMonthButton: `${monthLabel} (${monthShortcut})`,

packages/main/src/CalendarHeaderTemplate.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ export default function CalendarTemplate(this: Calendar) {
1818
onMouseDown={this.onPrevButtonClick}
1919
tabindex={this._previousButtonDisabled ? -1 : 0}
2020
title={this.accInfo.tooltipPrevButton}
21+
aria-label={this.accInfo.ariaLabelPrevButton}
22+
aria-description={this.accInfo.ariaLabelPrevButton}
23+
aria-keyshortcuts={this.accInfo.keyShortcutPrevButton}
2124
>
2225
<Icon class="ui5-calheader-arrowicon" name={slimArowLeft}/>
2326
</div>
@@ -97,6 +100,9 @@ export default function CalendarTemplate(this: Calendar) {
97100
onMouseDown={this.onNextButtonClick}
98101
tabindex={this._nextButtonDisabled ? -1 : 0}
99102
title={this.accInfo.tooltipNextButton}
103+
aria-label={this.accInfo.ariaLabelNextButton}
104+
aria-description={this.accInfo.ariaLabelNextButton}
105+
aria-keyshortcuts={this.accInfo.keyShortcutNextButton}
100106
>
101107
<Icon class="ui5-calheader-arrowicon" name={slimArowRight}/>
102108
</div>

packages/main/src/DateComponentBase.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ class DateComponentBase extends UI5Element {
170170
return this._displayFormat !== "medium" && this._displayFormat !== "short" && this._displayFormat !== "long";
171171
}
172172

173+
get initialFocusId(): string {
174+
return `${this._id}-calendar`;
175+
}
176+
173177
get hasSecondaryCalendarType() {
174178
return !!this.secondaryCalendarType && this.secondaryCalendarType !== this.primaryCalendarType;
175179
}

packages/main/src/DatePickerTemplate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ import type DatePicker from "./DatePicker.js";
66
export default function DatePickerTemplate(this: DatePicker) {
77
return [
88
DatePickerInputTemplate.call(this),
9-
DatePickerPopoverTemplate.call(this),
9+
DatePickerPopoverTemplate.call(this, { initialFocus: this.initialFocusId }),
1010
];
1111
}

packages/main/src/DateRangePickerTemplate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import DatePickerPopoverTemplate from "./DatePickerPopoverTemplate.js";
88
export default function DateRangePickerTemplate(this: DateRangePicker) {
99
return [
1010
DatePickerInputTemplate.call(this),
11-
DatePickerPopoverTemplate.call(this, { content }),
11+
DatePickerPopoverTemplate.call(this, { content, initialFocus: this.initialFocusId }),
1212
];
1313
}
1414

packages/main/src/DateTimePicker.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,6 @@ class DateTimePicker extends DatePicker implements IFormInputElement {
322322
return false;
323323
}
324324

325-
/**
326-
* Returns the ID of the element to focus initially when the picker opens in phone mode
327-
* @private
328-
*/
329-
get _initialFocusId() {
330-
return this._phoneMode ? `${this._id}-calendar` : undefined;
331-
}
332-
333325
/**
334326
* EVENT HANDLERS
335327
*/

packages/main/src/DateTimePickerTemplate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import TimeSelectionClocks from "./TimeSelectionClocks.js";
1212
export default function DateTimePickerTemplate(this: DateTimePicker) {
1313
return [
1414
DatePickerInputTemplate.call(this),
15-
DatePickerPopoverTemplate.call(this, { content, footer, initialFocus: this._initialFocusId }),
15+
DatePickerPopoverTemplate.call(this, { content, footer, initialFocus: this.initialFocusId }),
1616
];
1717
}
1818

packages/main/src/i18n/messagebundle.properties

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,12 +682,24 @@ CALENDAR_HEADER_YEAR_RANGE_BUTTON_SHORTCUT = Shift + F4
682682
#XACT: Title for month next button in the Calendar Header
683683
CALENDAR_HEADER_MONTH_NEXT_BUTTON_TITLE = Next Month
684684

685+
#XACT: Title for year next button in the Calendar Header
686+
CALENDAR_HEADER_YEAR_NEXT_BUTTON_TITLE = Next Year
687+
688+
#XACT: Title for year range next button in the Calendar Header
689+
CALENDAR_HEADER_YEAR_RANGE_NEXT_BUTTON_TITLE = Next Year Range
690+
685691
#XACT: Keyboard shortcut for month next button in the Calendar Header
686692
CALENDAR_HEADER_MONTH_NEXT_BUTTON_SHORTCUT = Pageup
687693

688694
#XACT: Title for month previous button in the Calendar Header
689695
CALENDAR_HEADER_MONTH_PREVIOUS_BUTTON_TITLE = Previous Month
690696

697+
#XACT: Title for year previous button in the Calendar Header
698+
CALENDAR_HEADER_YEAR_PREVIOUS_BUTTON_TITLE = Previous Year
699+
700+
#XACT: Title for year range previous button in the Calendar Header
701+
CALENDAR_HEADER_YEAR_RANGE_PREVIOUS_BUTTON_TITLE = Previous Year Range
702+
691703
#XACT: Keyboard shortcut for month previous button in the Calendar Header
692704
CALENDAR_HEADER_MONTH_PREVIOUS_BUTTON_SHORTCUT = Pagedown
693705

packages/main/src/themes/Calendar.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
padding: var(--_ui5_calendar_top_bottom_padding) var(--_ui5_calendar_left_right_padding) 0;
1717
display: flex;
1818
flex-direction: column;
19-
justify-content: flex-end;
2019
overflow: hidden;
2120
}
2221

0 commit comments

Comments
 (0)