Skip to content

Commit fc6beea

Browse files
kseamoncrisbeto
authored andcommitted
fix(cdk-experimental/popover-edit): Fix dialog role and allow aria label on popup (#29380)
(cherry picked from commit 23494a9)
1 parent 00fe295 commit fc6beea

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

src/cdk-experimental/popover-edit/popover-edit.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const POPOVER_EDIT_DIRECTIVE_NAME = `
6262
[cdkPopoverEdit]="nameEdit"
6363
[cdkPopoverEditColspan]="colspan"
6464
[cdkPopoverEditDisabled]="nameEditDisabled"
65+
[cdkPopoverEditAriaLabel]="nameEditAriaLabel"
6566
`;
6667

6768
const POPOVER_EDIT_DIRECTIVE_WEIGHT = `[cdkPopoverEdit]="weightEdit" cdkPopoverEditTabOut`;
@@ -77,6 +78,7 @@ abstract class BaseTestComponent {
7778

7879
preservedValues = new FormValueContainer<PeriodicElement, {'name': string}>();
7980
nameEditDisabled = false;
81+
nameEditAriaLabel: string | undefined = undefined;
8082
ignoreSubmitUnlessValid = true;
8183
clickOutBehavior: PopoverEditClickOutBehavior = 'close';
8284
colspan: CdkPopoverEditColspan = {};
@@ -557,6 +559,22 @@ describe('CDK Popover Edit', () => {
557559
expect(component.lensIsOpen()).toBe(false);
558560
clearLeftoverTimers();
559561
}));
562+
563+
it('sets aria label and role dialog on the popup', fakeAsync(() => {
564+
component.nameEditAriaLabel = 'Label of name!!';
565+
fixture.changeDetectorRef.markForCheck();
566+
fixture.detectChanges();
567+
568+
// Uses Enter to open the lens.
569+
component.openLens();
570+
fixture.detectChanges();
571+
572+
expect(component.lensIsOpen()).toBe(true);
573+
const dialogElem = component.getEditPane()!;
574+
expect(dialogElem.getAttribute('aria-label')).toBe('Label of name!!');
575+
expect(dialogElem.getAttribute('role')).toBe('dialog');
576+
clearLeftoverTimers();
577+
}));
560578
});
561579

562580
describe('focus manipulation', () => {

src/cdk-experimental/popover-edit/table-directives.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ const POPOVER_EDIT_INPUTS = [
173173
{name: 'context', alias: 'cdkPopoverEditContext'},
174174
{name: 'colspan', alias: 'cdkPopoverEditColspan'},
175175
{name: 'disabled', alias: 'cdkPopoverEditDisabled'},
176+
{name: 'ariaLabel', alias: 'cdkPopoverEditAriaLabel'},
176177
];
177178

178179
/**
@@ -196,6 +197,9 @@ export class CdkPopoverEdit<C> implements AfterViewInit, OnDestroy {
196197
*/
197198
context?: C;
198199

200+
/** Aria label to set on the popover dialog element. */
201+
ariaLabel?: string;
202+
199203
/**
200204
* Specifies that the popup should cover additional table cells before and/or after
201205
* this one.
@@ -302,7 +306,10 @@ export class CdkPopoverEdit<C> implements AfterViewInit, OnDestroy {
302306
});
303307

304308
this.initFocusTrap();
305-
this.overlayRef.overlayElement.setAttribute('aria-role', 'dialog');
309+
this.overlayRef.overlayElement.setAttribute('role', 'dialog');
310+
if (this.ariaLabel) {
311+
this.overlayRef.overlayElement.setAttribute('aria-label', this.ariaLabel);
312+
}
306313

307314
this.overlayRef.detachments().subscribe(() => this.closeEditOverlay());
308315
}

src/material-experimental/popover-edit/popover-edit.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const POPOVER_EDIT_DIRECTIVE_NAME = `
5353
[matPopoverEdit]="nameEdit"
5454
[matPopoverEditColspan]="colspan"
5555
[matPopoverEditDisabled]="nameEditDisabled"
56+
[matPopoverEditAriaLabel]="nameEditAriaLabel"
5657
`;
5758

5859
const POPOVER_EDIT_DIRECTIVE_WEIGHT = `[matPopoverEdit]="weightEdit" matPopoverEditTabOut`;
@@ -69,6 +70,7 @@ abstract class BaseTestComponent {
6970
preservedValues = new FormValueContainer<PeriodicElement, {'name': string}>();
7071

7172
nameEditDisabled = false;
73+
nameEditAriaLabel: string | undefined = undefined;
7274
ignoreSubmitUnlessValid = true;
7375
clickOutBehavior: PopoverEditClickOutBehavior = 'close';
7476
colspan: CdkPopoverEditColspan = {};
@@ -430,6 +432,22 @@ describe('Material Popover Edit', () => {
430432
expect(component.lensIsOpen()).toBe(false);
431433
clearLeftoverTimers();
432434
}));
435+
436+
it('sets aria label and role dialog on the popup', fakeAsync(() => {
437+
component.nameEditAriaLabel = 'Label of name!!';
438+
fixture.changeDetectorRef.markForCheck();
439+
fixture.detectChanges();
440+
441+
// Uses Enter to open the lens.
442+
component.openLens();
443+
fixture.detectChanges();
444+
445+
expect(component.lensIsOpen()).toBe(true);
446+
const dialogElem = component.getEditPane()!;
447+
expect(dialogElem.getAttribute('aria-label')).toBe('Label of name!!');
448+
expect(dialogElem.getAttribute('role')).toBe('dialog');
449+
clearLeftoverTimers();
450+
}));
433451
});
434452

435453
describe('focus manipulation', () => {

src/material-experimental/popover-edit/table-directives.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const POPOVER_EDIT_INPUTS = [
2626
{name: 'context', alias: 'matPopoverEditContext'},
2727
{name: 'colspan', alias: 'matPopoverEditColspan'},
2828
{name: 'disabled', alias: 'matPopoverEditDisabled'},
29+
{name: 'ariaLabel', alias: 'matPopoverEditAriaLabel'},
2930
];
3031

3132
const EDIT_PANE_CLASS = 'mat-edit-pane';

0 commit comments

Comments
 (0)