Skip to content

Commit

Permalink
feat: add overlayRole property to customize dialog role (#7582)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored Jul 25, 2024
1 parent 4d80c5c commit 9509e0d
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 2 deletions.
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
14 changes: 14 additions & 0 deletions packages/dialog/test/dom/__snapshots__/dialog.test.snap.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,17 @@ snapshots["vaadin-dialog overlay class"] =
`;
/* end snapshot vaadin-dialog overlay class */

snapshots["vaadin-dialog overlay role"] =
`<vaadin-dialog-overlay
focus-trap=""
id="overlay"
opened=""
restore-focus-on-close=""
role="alertdialog"
with-backdrop=""
>
content
</vaadin-dialog-overlay>
`;
/* end snapshot vaadin-dialog overlay role */

5 changes: 5 additions & 0 deletions packages/dialog/test/dom/dialog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ describe('vaadin-dialog', () => {
dialog.overlayClass = 'custom dialog-overlay';
await expect(overlay).dom.to.equalSnapshot(SNAPSHOT_CONFIG);
});

it('overlay role', async () => {
dialog.overlayRole = 'alertdialog';
await expect(overlay).dom.to.equalSnapshot(SNAPSHOT_CONFIG);
});
});
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

0 comments on commit 9509e0d

Please sign in to comment.