Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<div class="side-add-button-container">
<button
#actionsButton
class="side-add-button"
mat-fab
(click)="menuTrigger.openMenu()"
Expand Down Expand Up @@ -38,6 +39,8 @@
class="side-add-menu-button"
[class.with-description]="item.description !== null"
(click)="item.onClick()"
(keydown.tab)="focusButton($event)"
(keydown.escape)="focusButton($event)"
[disabled]="item.disabled$ | async">
<mat-icon *ngIf="item.svgIcon" svgIcon="{{ item.svgIcon }}"></mat-icon>
<mat-icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,27 @@ describe('SideButtonMenuComponent', () => {
expect(onClickSpy).toHaveBeenCalled();
});

['Escape', 'Tab'].forEach((key: string) => {
it(`should focus side button on ${key} press`, async () => {
const button = document.querySelector(
'.side-add-button'
) as HTMLButtonElement;
const buttonFocusSpy = spyOn(button, 'focus');
const firstItemElement = await items[0].host();
await firstItemElement.dispatchEvent('keydown', { key: key });

expect(buttonFocusSpy).toHaveBeenCalled();
});

it(`should close menu on ${key} press`, async () => {
const closeMenuSpy = spyOn(component.menuTrigger(), 'closeMenu');
const firstItemElement = await items[0].host();
await firstItemElement.dispatchEvent('keydown', { key: key });

expect(closeMenuSpy).toHaveBeenCalled();
});
});

it('should display the correct icons for actions', async () => {
const text0 = await items[0].getText();
const text1 = await items[1].getText();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, input } from '@angular/core';
import { Component, input, viewChild } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';
import { MatMenuModule } from '@angular/material/menu';
import { MatMenuModule, MatMenuTrigger } from '@angular/material/menu';
import { CommonModule } from '@angular/common';
import { AddMenuItem } from '../../app.component';
import { MatTooltip } from '@angular/material/tooltip';
Expand All @@ -19,5 +19,18 @@ import { MatTooltip } from '@angular/material/tooltip';
styleUrl: './side-button-menu.component.scss',
})
export class SideButtonMenuComponent {
readonly menuTrigger = viewChild.required<MatMenuTrigger>('menuTrigger');
menuItems = input<AddMenuItem[]>([]);

focusButton(event: Event) {
event.preventDefault();
event.stopPropagation();
const button = document.querySelector(
'.side-add-button'
) as HTMLButtonElement;
if (button) {
button.focus();
}
this.menuTrigger().closeMenu();
}
}