Skip to content

Commit eb93041

Browse files
116404: Apply focus on first item
(cherry picked from commit 2152bab)
1 parent b9b1d3f commit eb93041

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/app/navbar/expandable-navbar-section/expandable-navbar-section.component.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,13 @@ export class ExpandableNavbarSectionComponent extends NavbarSectionComponent imp
112112

113113
ngAfterViewChecked(): void {
114114
if (this.addArrowEventListeners) {
115-
const dropdownItems = document.querySelectorAll(`#${this.expandableNavbarSectionId()} *[role="menuitem"]`);
116-
dropdownItems.forEach(item => {
115+
const dropdownItems: NodeListOf<HTMLElement> = document.querySelectorAll(`#${this.expandableNavbarSectionId()} *[role="menuitem"]`);
116+
dropdownItems.forEach((item: HTMLElement) => {
117117
item.addEventListener('keydown', this.navigateDropdown.bind(this));
118118
});
119+
if (dropdownItems.length > 0) {
120+
dropdownItems.item(0).focus();
121+
}
119122
this.addArrowEventListeners = false;
120123
}
121124
}
@@ -195,7 +198,7 @@ export class ExpandableNavbarSectionComponent extends NavbarSectionComponent imp
195198
this.deactivateSection(event, false);
196199
break;
197200
case 'ArrowDown':
198-
this.navigateDropdown(event);
201+
this.activateSection(event);
199202
break;
200203
case 'Space':
201204
event.preventDefault();

src/app/shared/menu/menu-section/menu-section.component.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,12 @@ export class MenuSectionComponent implements OnInit, OnDestroy {
9292
/**
9393
* Activate this section
9494
* @param {Event} event The user event that triggered this method
95+
* @param skipEvent Weather the event should still be triggered after deactivating the section or not
9596
*/
96-
activateSection(event: Event) {
97-
event.preventDefault();
97+
activateSection(event: Event, skipEvent = true): void {
98+
if (skipEvent) {
99+
event.preventDefault();
100+
}
98101
if (!this.section.model?.disabled) {
99102
this.menuService.activateSection(this.menuID, this.section.id);
100103
}

0 commit comments

Comments
 (0)