I'm using lighthouse to check my app accessability. I'm trying to make bootstrap modal accessabile. The Component's code:
constructor(private modalService: NgbModal) {}
let m = this.modalService.open(ModalContentComponent, {
backdrop: 'static',
keyboard: false,
ariaDescribedBy:'tttt',
ariaLabelledBy:'uuuuu'
});
m.componentInstance.closeModal.subscribe(($event: any) => m.close('Close click'))
The rendered html:
The nested elements insode ngb-modal-content are with roles and without arias
The modal is being open automatically when the page loaded.
And I'm getting the error: "Elements with role="dialog" or role="alertdialog" do not have accessible names."
The problem is that the
ariaDescribedByandariaLabelledByattributes are not being rendered in the HTML. This is because the modal is being opened automatically when the page is loaded, and the HTML is not yet ready.To fix this, you can use the
ngAfterViewInitlifecycle hook to open the modal after the HTML has been rendered. This will ensure that theariaDescribedByandariaLabelledByattributes are included in the HTML.Here is an example of how to do this:
This should fix the accessibility error.
I hope this helps!