Skip to content
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

feat: add overlayRole property to customize dialog role #7582

Merged
merged 3 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions packages/dialog/src/vaadin-dialog-base-mixin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,11 @@ export declare class DialogBaseMixinClass {
* Set to true to remove backdrop and allow click events on background elements.
*/
modeless: boolean;

/**
* The `role` attribute value to be set on the overlay. Defaults to "dialog".
*
* @attr {string} overlay-role
*/
overlayRole: string;
}
10 changes: 10 additions & 0 deletions packages/dialog/src/vaadin-dialog-base-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ export const DialogBaseMixin = (superClass) =>
type: Boolean,
value: false,
},

/**
* The `role` attribute value to be set on the overlay. Defaults to "dialog".
*
* @attr {string} overlay-role
*/
overlayRole: {
type: String,
value: 'dialog',
},
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/dialog/src/vaadin-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class Dialog extends DialogDraggableMixin(

<vaadin-dialog-overlay
id="overlay"
role="dialog"
role$="[[overlayRole]]"
header-title="[[headerTitle]]"
on-opened-changed="_onOverlayOpened"
on-mousedown="_bringOverlayToFront"
Expand Down
2 changes: 1 addition & 1 deletion packages/dialog/src/vaadin-lit-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Dialog extends DialogDraggableMixin(
return html`
<vaadin-dialog-overlay
id="overlay"
role="dialog"
role="${this.overlayRole}"
.owner="${this}"
.opened="${this.opened}"
.headerTitle="${this.headerTitle}"
Expand Down
6 changes: 6 additions & 0 deletions packages/dialog/test/dialog.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ describe('vaadin-dialog', () => {
expect(overlay.getAttribute('role')).to.be.eql('dialog');
});

it('should change role attribute on the overlay based on overlayRole', async () => {
Copy link
Contributor

@vursen vursen Jul 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could it be a snapshot test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, thanks. Moved this test and removed two others for default role and theme as they are also covered by existing snapshot tests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted changes to unrelated tests to #7586 so that this PR doesn't touch unit tests.

dialog.overlayRole = 'alertdialog';
await nextUpdate(dialog);
expect(overlay.getAttribute('role')).to.equal('alertdialog');
});

it('overlay should have the `aria-label` attribute (if set)', async () => {
dialog.ariaLabel = 'accessible';
await nextUpdate(dialog);
Expand Down
1 change: 1 addition & 0 deletions packages/dialog/test/typings/dialog.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ assertType<boolean>(dialog.resizable);
assertType<boolean>(dialog.noCloseOnEsc);
assertType<boolean>(dialog.noCloseOnOutsideClick);
assertType<string>(dialog.overlayClass);
assertType<string>(dialog.overlayRole);
assertType<string | null | undefined>(dialog.headerTitle);
assertType<DialogRenderer | null | undefined>(dialog.renderer);
assertType<DialogRenderer | null | undefined>(dialog.headerRenderer);
Expand Down
Loading