Skip to content

Commit 7328528

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

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

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
@@ -83,10 +83,13 @@ export class ExpandableNavbarSectionComponent extends NavbarSectionComponent imp
8383

8484
ngAfterViewChecked(): void {
8585
if (this.addArrowEventListeners) {
86-
const dropdownItems = document.querySelectorAll(`#${this.expandableNavbarSectionId()} *[role="menuitem"]`);
87-
dropdownItems.forEach(item => {
86+
const dropdownItems: NodeListOf<HTMLElement> = document.querySelectorAll(`#${this.expandableNavbarSectionId()} *[role="menuitem"]`);
87+
dropdownItems.forEach((item: HTMLElement) => {
8888
item.addEventListener('keydown', this.navigateDropdown.bind(this));
8989
});
90+
if (dropdownItems.length > 0) {
91+
dropdownItems.item(0).focus();
92+
}
9093
this.addArrowEventListeners = false;
9194
}
9295
}
@@ -166,7 +169,7 @@ export class ExpandableNavbarSectionComponent extends NavbarSectionComponent imp
166169
this.deactivateSection(event, false);
167170
break;
168171
case 'ArrowDown':
169-
this.navigateDropdown(event);
172+
this.activateSection(event);
170173
break;
171174
case 'Space':
172175
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
@@ -75,9 +75,12 @@ export class MenuSectionComponent implements OnInit, OnDestroy {
7575
/**
7676
* Activate this section
7777
* @param {Event} event The user event that triggered this method
78+
* @param skipEvent Weather the event should still be triggered after deactivating the section or not
7879
*/
79-
activateSection(event: Event) {
80-
event.preventDefault();
80+
activateSection(event: Event, skipEvent = true): void {
81+
if (skipEvent) {
82+
event.preventDefault();
83+
}
8184
if (!this.section.model?.disabled) {
8285
this.menuService.activateSection(this.menuID, this.section.id);
8386
}

0 commit comments

Comments
 (0)