I have added slds-is-relative
as mentioned in lightning:spinner Overlay screen this post and it is working.
Model code:
myModal.html
<template>
<lightning-modal-header label="Test"></lightning-modal-header>
<lightning-modal-body> Content: {content}
<div class="slds-is-relative">
<lightning-spinner if:true={isLoading} alternative-text="Loading" variant="brand"></lightning-spinner>
</div>
</lightning-modal-body>
<lightning-modal-footer>
<lightning-button label="OK" onclick={handleOkay}></lightning-button>
</lightning-modal-footer>
</template>
myModal.js
import { track, api } from 'lwc';
import LightningModal from 'lightning/modal';
export default class MyModal extends LightningModal {
@api content;
@track isLoading = true;
handleOkay() {
this.close('okay');
}
}
modelOverLayTest.html
<template>
<lightning-button
onclick={handleClick}
aria-haspopup="dialog"
label="Open My Modal">
</lightning-button>
<p>Result: {result}</p>
</template>
modelOverLayTest.js
import { LightningElement } from 'lwc';
import MyModal from 'c/myModal';
export default class modelOverLayTest extends LightningElement {
async handleClick() {
const result = await MyModal.open({
// `label` is not included here in this example.
// it is set on lightning-modal-header instead
size: 'full',
description: 'Accessible description of modal\'s purpose',
content: 'Passed into content api',
});
// if modal closed with X button, promise returns result = 'undefined'
// if modal closed with OK button, promise returns result = 'okay'
console.log(result);
}
}
Ouptup: