Skip to content

fix(cdk-experimental/popover-edit): Fix dialog role and allow aria label on popup #29380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 9, 2024
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
18 changes: 18 additions & 0 deletions src/cdk-experimental/popover-edit/popover-edit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const POPOVER_EDIT_DIRECTIVE_NAME = `
[cdkPopoverEdit]="nameEdit"
[cdkPopoverEditColspan]="colspan"
[cdkPopoverEditDisabled]="nameEditDisabled"
[cdkPopoverEditAriaLabel]="nameEditAriaLabel"
`;

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

preservedValues = new FormValueContainer<PeriodicElement, {'name': string}>();
nameEditDisabled = false;
nameEditAriaLabel: string | undefined = undefined;
ignoreSubmitUnlessValid = true;
clickOutBehavior: PopoverEditClickOutBehavior = 'close';
colspan: CdkPopoverEditColspan = {};
Expand Down Expand Up @@ -557,6 +559,22 @@ describe('CDK Popover Edit', () => {
expect(component.lensIsOpen()).toBe(false);
clearLeftoverTimers();
}));

it('sets aria label and role dialog on the popup', fakeAsync(() => {
component.nameEditAriaLabel = 'Label of name!!';
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();

// Uses Enter to open the lens.
component.openLens();
fixture.detectChanges();

expect(component.lensIsOpen()).toBe(true);
const dialogElem = component.getEditPane()!;
expect(dialogElem.getAttribute('aria-label')).toBe('Label of name!!');
expect(dialogElem.getAttribute('role')).toBe('dialog');
clearLeftoverTimers();
}));
});

describe('focus manipulation', () => {
Expand Down
9 changes: 8 additions & 1 deletion src/cdk-experimental/popover-edit/table-directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ const POPOVER_EDIT_INPUTS = [
{name: 'context', alias: 'cdkPopoverEditContext'},
{name: 'colspan', alias: 'cdkPopoverEditColspan'},
{name: 'disabled', alias: 'cdkPopoverEditDisabled'},
{name: 'ariaLabel', alias: 'cdkPopoverEditAriaLabel'},
];

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

/** Aria label to set on the popover dialog element. */
ariaLabel?: string;

/**
* Specifies that the popup should cover additional table cells before and/or after
* this one.
Expand Down Expand Up @@ -302,7 +306,10 @@ export class CdkPopoverEdit<C> implements AfterViewInit, OnDestroy {
});

this.initFocusTrap();
this.overlayRef.overlayElement.setAttribute('aria-role', 'dialog');
this.overlayRef.overlayElement.setAttribute('role', 'dialog');
if (this.ariaLabel) {
this.overlayRef.overlayElement.setAttribute('aria-label', this.ariaLabel);
}

this.overlayRef.detachments().subscribe(() => this.closeEditOverlay());
}
Expand Down
18 changes: 18 additions & 0 deletions src/material-experimental/popover-edit/popover-edit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const POPOVER_EDIT_DIRECTIVE_NAME = `
[matPopoverEdit]="nameEdit"
[matPopoverEditColspan]="colspan"
[matPopoverEditDisabled]="nameEditDisabled"
[matPopoverEditAriaLabel]="nameEditAriaLabel"
`;

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

nameEditDisabled = false;
nameEditAriaLabel: string | undefined = undefined;
ignoreSubmitUnlessValid = true;
clickOutBehavior: PopoverEditClickOutBehavior = 'close';
colspan: CdkPopoverEditColspan = {};
Expand Down Expand Up @@ -430,6 +432,22 @@ describe('Material Popover Edit', () => {
expect(component.lensIsOpen()).toBe(false);
clearLeftoverTimers();
}));

it('sets aria label and role dialog on the popup', fakeAsync(() => {
component.nameEditAriaLabel = 'Label of name!!';
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();

// Uses Enter to open the lens.
component.openLens();
fixture.detectChanges();

expect(component.lensIsOpen()).toBe(true);
const dialogElem = component.getEditPane()!;
expect(dialogElem.getAttribute('aria-label')).toBe('Label of name!!');
expect(dialogElem.getAttribute('role')).toBe('dialog');
clearLeftoverTimers();
}));
});

describe('focus manipulation', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const POPOVER_EDIT_INPUTS = [
{name: 'context', alias: 'matPopoverEditContext'},
{name: 'colspan', alias: 'matPopoverEditColspan'},
{name: 'disabled', alias: 'matPopoverEditDisabled'},
{name: 'ariaLabel', alias: 'matPopoverEditAriaLabel'},
];

const EDIT_PANE_CLASS = 'mat-edit-pane';
Expand Down
Loading