Skip to content

Commit a04667d

Browse files
authored
Merge pull request #313 from UiPath/fix/aria-expanded
Fix(grid): make trigger menu button accessible
2 parents 233725b + 80f3612 commit a04667d

File tree

14 files changed

+109
-5
lines changed

14 files changed

+109
-5
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# v14.5.4 (2023-03-08)
2+
* **grid** add aria-expanded to filters btn
3+
* **grid** add tick to test
4+
* **grid** announce filter menu state collapsed/expanded
5+
* **a11y** filter messages that are announced
6+
* **a11y** add menu-trigger directive that sets aria-expanded
7+
18
# v14.5.3 (2023-03-03)
29
* **grid** add test for tooltip on focus
310
* **grid** display title & description tooltip on focus

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-components",
3-
"version": "14.5.3",
3+
"version": "14.5.4",
44
"author": {
55
"name": "UiPath Inc",
66
"url": "https://uipath.com"

projects/angular/a11y/src/queued-announcer/queued-announcer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export class QueuedAnnouncer {
1616

1717
constructor(private _liveAnnouncer: LiveAnnouncer) { }
1818

19-
enqueue(msg: string) {
19+
enqueue(msg: string | undefined) {
20+
if (!msg) { return; }
2021
this._msgQueue.push(msg);
2122

2223
if (!this._isAnnouncing) {

projects/angular/components/ui-grid/src/ui-grid.component.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@
612612
<button *ngIf="hasAnyFiltersVisible$ | async"
613613
[disabled]="disabled"
614614
(click)="showFilters = !showFilters"
615+
[attr.aria-expanded]="showFilters"
615616
mat-button
616617
type="button"
617618
class="ui-grid-collapsible-filters-toggle">
@@ -630,6 +631,8 @@
630631
<button [matMenuTriggerFor]="filterOptions"
631632
[disabled]="column.dropdown?.disabled || disabled"
632633
[attr.data-column-name]="getColumnName(column)"
634+
[expandedTranslation]="intl.menuExpanded"
635+
uiCustomMatMenuTriggerFor
633636
mat-button
634637
type="button"
635638
class="ui-grid-dropdown-filter-button">

projects/angular/components/ui-grid/src/ui-grid.component.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,8 @@ describe('Component: UiGrid', () => {
10911091

10921092
expect(headerSelectionAction).toBeFalsy();
10931093
expect((grid.selectionManager as any)._hasValue$.getValue()).toBe(false);
1094+
tick(100);
1095+
discardPeriodicTasks();
10941096
}));
10951097

10961098
it('should be able to move focus to selection action button if at least one row is selected', () => {

projects/angular/components/ui-grid/src/ui-grid.intl.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ export class UiGridIntl implements OnDestroy {
118118
*
119119
*/
120120
clearCustomFilter = 'Clear custom filter';
121+
/**
122+
* Menu expanded message for live announcer.
123+
*
124+
*/
125+
menuExpanded = 'expanded';
121126
/**
122127
* No data row message alternative function.
123128
*

projects/angular/components/ui-grid/src/ui-grid.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { MatSelectModule } from '@angular/material/select';
1212
import { MatTooltipModule } from '@angular/material/tooltip';
1313
import { UiAutoAccessibleLabelModule } from '@uipath/angular/a11y';
1414
import { UiSuggestModule } from '@uipath/angular/components/ui-suggest';
15+
import { UiCustomMatMenuTriggerModule } from '@uipath/angular/directives/custom-mat-menu-trigger';
1516
import { UiNgLetModule } from '@uipath/angular/directives/ui-ng-let';
1617
import { UiVirtualScrollViewportResizeModule } from '@uipath/angular/directives/ui-virtual-scroll-viewport-resize';
1718

@@ -52,6 +53,7 @@ import { UiGridComponent } from './ui-grid.component';
5253
UiVirtualScrollViewportResizeModule,
5354
UiAutoAccessibleLabelModule,
5455
UiNgLetModule,
56+
UiCustomMatMenuTriggerModule,
5557
],
5658
declarations: [
5759
UiGridComponent,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import {
2+
Subject,
3+
takeUntil,
4+
} from 'rxjs';
5+
6+
import { LiveAnnouncer } from '@angular/cdk/a11y';
7+
import {
8+
AfterContentInit,
9+
Directive,
10+
ElementRef,
11+
HostBinding,
12+
inject,
13+
Input,
14+
OnDestroy,
15+
} from '@angular/core';
16+
import { _MatMenuTriggerBase } from '@angular/material/menu';
17+
18+
// FIXME: this directive will not be necessary anymore in the @angular/[email protected] version
19+
// its sole purpose is to fix the aria-expanded issue https://github.com/angular/components/issues/26262
20+
21+
@Directive({
22+
selector: '[uiCustomMatMenuTriggerFor]',
23+
})
24+
export class UiCustomMatMenuTriggerDirective extends _MatMenuTriggerBase implements AfterContentInit, OnDestroy {
25+
@HostBinding()
26+
ariaExpanded = false;
27+
28+
@Input()
29+
expandedTranslation = 'expanded';
30+
31+
nativeElement = inject(ElementRef<HTMLElement>).nativeElement;
32+
33+
private _liveAnnouncer = inject(LiveAnnouncer);
34+
private _destroyed$ = new Subject<void>();
35+
ngAfterContentInit() {
36+
this.menuOpened.pipe(
37+
takeUntil(this._destroyed$),
38+
).subscribe(() => {
39+
// although setting aria-expanded to true, it is not announced
40+
this.nativeElement.setAttribute('aria-expanded', 'true');
41+
this._liveAnnouncer.announce(this.expandedTranslation);
42+
43+
// after closing the menu it would appear for a short time as expanded
44+
// therefore we set it as collapsed before it is actually closed
45+
setTimeout(() => {
46+
this.nativeElement.setAttribute('aria-expanded', 'false');
47+
}, 100);
48+
});
49+
50+
this.menuClosed.pipe(
51+
takeUntil(this._destroyed$),
52+
).subscribe(() => {
53+
this.nativeElement.setAttribute('aria-expanded', 'false');
54+
55+
// timeout is required because
56+
// after focusing another element then returning to this one, it will lose collapsed state
57+
setTimeout(() => {
58+
this.nativeElement.setAttribute('aria-expanded', 'false');
59+
}, 100);
60+
});
61+
}
62+
63+
ngOnDestroy() {
64+
super.ngOnDestroy();
65+
this._destroyed$.next();
66+
this._destroyed$.complete();
67+
}
68+
}
69+

0 commit comments

Comments
 (0)