I have code like below
<ng-container>
<ng-container>
<div class="class1" tabindex="0" [matMenuTriggerFor]="menu" #menuTrigger="matMenuTrigger">
<div class="customclass">
<i class="fa fa-bell-o"></i>
<h2>Main Menu</h2>
</div>
</div>
</ng-container>
<mat-menu #menu="matMenu" class="myClass" >
<div class="Custom">
<div mat-menu-item (click)="$event.stopPropagation()" (keydown)="myFunc($event)"
<div class="class2">
<h3>Label</h3>
<div class="class3">
<p> some text, <a href="link address">first link</a>.
Some Test text and link <a href="address" >second link</a>
</p>
</div>
</div>
</div>
</mat-menu>
I want to navigate through links with the Tab key. So, I have added tabindex like below
let myLinks = this.elRef.nativeElement.getElementsByTagName('a');
for (let i = 0; i <= anchors.length-1; i++) {
myLinks[i].setAttribute('tabindex', '0');
}
myFunc(event: { stopPropagation: () => void }) {event.stopPropagation();}
I want to close the menu when I press shift+tab from the first link. or when I press the tab key after the last link inside the menu.
Also, when I shift+tab from the first link, focus should be on the Main Menu, and when I press the tab key after the last link, focus should be set on the next element.
How do I achieve it?