Update 10/25
I have a modal that I am creating when a user clicks on a lighting card. For accessibility reason I need the focus to remain in the modal until the user clicks Dismiss or hits the escape key.
For some reason the focus exits the modal and start focusing through the page content when i hit the tab key.
I've tried to custom code this issue and got to the point where I submitted a ticket to Salesforce.
Unfortunately this is a known issue https://success.salesforce.com/issues_view?id=a1p3A000001SH48QAG.
I've also tried to import a third party library to try and resolve this issue. (https://www.w3.org/TR/wai-aria-practices/examples/dialog-modal/dialog.html)
JAVA SCRIPT FILE Open Modal
import { loadScript } from 'lightning/platformResourceLoader';
import DIALOG_JS from '@salesforce/resourceUrl/dialog';
dialogjsInitialized;
renderedCallback() {
if (this.dialogjsInitialized) {
return;
}
this.dialogjsInitialized = true;
loadScript(this, DIALOG_JS)
.then(() => {
this.initializeModal();
})
.catch(error => {
this.error = error;
});
}
@api openModal() {
alert("openDialog");
dialog.openDialog('dialog1', this);
alert("finished openDialog");
}
initializeModal() {
dialogjsInitialized = false;
}
@api closeModal() {
dialog.closeCurrentDialog();
}
}
HTML FILE Open Modal
<div role="dialog"
id="dialog1"
aria-labelledby="dialog1_label"
aria-modal="true"
class="hidden">
<h2 id="dialog1_label" class="dialog_label">
My Modal
</h2>
.....
</div>
For some reason when I try and utilize the dialog .close
or dialog .open
nothing happens, and I don't see an error on on the console, log or browser. What might be going wrong? How can I further debug?
I have uploaded the dialog.js as a static resource that was provided on the W3.
Do I need to make modifications to that file and put it in a LWC JavaScript format?
Can I not just upload the JavaScript As Is?