Skip to content

Commit e381532

Browse files
authored
feat(design): allow aria-labelledby to be set by the DaffModalService (#2967)
1 parent ab4aacc commit e381532

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

libs/design/modal/README.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,20 @@ Buttons can be added to a modal by using `<daff-modal-actions>`. This container
2626
A modal can be dismissed via the close button or the `ESC` key. The close button is shown by default but can be hidden by setting the `dismissible` property to `false` on `<daff-modal-header>`. Additionally, the `[daffModalClose]` directive can be added to a `<button>` HTML element.
2727

2828
## Accessibility
29-
Modal works with the ARIA `role="dialog"` and `aria-modal="true"` attributes to provide an accessible experience. `aria-labelledby` is assigned the `[daffModalTitle]` string. When a modal is opened, the first tabbable element within it will receive focus.
29+
Modal works with the ARIA `role="dialog"` and `aria-modal="true"` attributes to provide an accessible experience. The first tabbable element will receive focus when a modal is opened.
30+
31+
`aria-labelledby` is assigned the `[daffModalTitle]` string when it's used. If there is no title, `aria-labelledby` should be set in the configurations through the `DaffModalService`.
32+
33+
```ts
34+
constructor(private modalService: DaffModalService) {}
35+
36+
showModal() {
37+
this.modal = this.modalService.open(
38+
BasicModalContentComponent,
39+
{ ariaLabelledBy: 'Modal Title' },
40+
);
41+
}
42+
```
3043

3144
### Keyboard Interactions
3245
A modal can be closed by choosing one of the actions buttons, the close button in the header, or it can be dismissed by pressing the `ESC` key.

libs/design/modal/examples/src/basic-modal/basic-modal.component.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ export class BasicModalComponent {
2626
constructor(private modalService: DaffModalService) {}
2727

2828
showModal() {
29-
this.modal = this.modalService.open(BasicModalContentComponent);
29+
this.modal = this.modalService.open(
30+
BasicModalContentComponent,
31+
{ ariaLabelledBy: 'Modal Title' },
32+
);
3033
}
3134
}

libs/design/modal/src/modal/modal-config.ts

+3
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ export interface DaffModalConfiguration {
44
* DaffModalComponent is interacted with.
55
*/
66
onBackdropClicked?: () => void;
7+
8+
/** Sets the `aria-labelledby` property on the modal */
9+
ariaLabelledBy?: string;
710
}

libs/design/modal/src/service/modal.service.ts

+4
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ export class DaffModalService {
7979
const _modal = this._attachModal(_ref);
8080
const _attachedModal = this._attachModalContent(component, _modal);
8181

82+
if(configuration?.ariaLabelledBy) {
83+
_modal.instance.ariaLabelledBy = configuration.ariaLabelledBy;
84+
}
85+
8286
const modal: DaffModal = {
8387
modal: _modal,
8488
overlay: _ref,

0 commit comments

Comments
 (0)