Skip to content

Commit

Permalink
116404: Apply focus on first item
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrevryghem committed Jul 5, 2024
1 parent 101f55a commit 2c86f59
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,13 @@ export class ExpandableNavbarSectionComponent extends NavbarSectionComponent imp

ngAfterViewChecked(): void {
if (this.addArrowEventListeners) {
const dropdownItems = document.querySelectorAll(`#${this.expandableNavbarSectionId()} *[role="menuitem"]`);
dropdownItems.forEach(item => {
const dropdownItems: NodeListOf<HTMLElement> = document.querySelectorAll(`#${this.expandableNavbarSectionId()} *[role="menuitem"]`);
dropdownItems.forEach((item: HTMLElement) => {
item.addEventListener('keydown', this.navigateDropdown.bind(this));
});
if (dropdownItems.length > 0) {
dropdownItems.item(0).focus();
}
this.addArrowEventListeners = false;
}
}
Expand Down Expand Up @@ -188,7 +191,7 @@ export class ExpandableNavbarSectionComponent extends NavbarSectionComponent imp
this.deactivateSection(event, false);
break;
case 'ArrowDown':
this.navigateDropdown(event);
this.activateSection(event);
break;
case 'Space':
event.preventDefault();
Expand Down
7 changes: 5 additions & 2 deletions src/app/shared/menu/menu-section/menu-section.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,12 @@ export class MenuSectionComponent implements OnInit, OnDestroy {
/**
* Activate this section
* @param {Event} event The user event that triggered this method
* @param skipEvent Weather the event should still be triggered after deactivating the section or not
*/
activateSection(event: Event) {
event.preventDefault();
activateSection(event: Event, skipEvent = true): void {
if (skipEvent) {
event.preventDefault();
}
if (!this.section.model?.disabled) {
this.menuService.activateSection(this.menuID, this.section.id);
}
Expand Down

0 comments on commit 2c86f59

Please sign in to comment.