5

I am able to add a lightning-spinner in an LWC component, but I'm not able to display the text along with the spinner. I need some help regarding the same. I tried both alternate-text in HTML & content in CSS file - both dint work.

HTML :-

<div class="exampleHolder">
    <template if:true={showLoadingSpinner}>
        <lightning-spinner  alternative-text="Fetching Fields of the Object......" size="medium"></lightning-spinner>
    </template>
</div>

CSS is as follows:-

.exampleHolder{
    margin: auto;
    content :'Fetching Fields of the Object......';
    display: inline-block;
    width: 80px;
    height: 80px;
    text-align: center;
    font-weight: bold;  
}
1
  • alternative-text is displayed when the spinner is not loaded due to some reason/s. Oct 3, 2019 at 9:47

1 Answer 1

7

The answer on this post here for aura component can be adapted for LWC as follows, you can try it

HTML

<template>
<div class="exampleHolder">
    <template if:true={showLoadingSpinner}>
        <lightning-spinner class="spins" size="medium"></lightning-spinner>
    </template>
</div>
</template>

CSS

 .spins::after {
    position: absolute;
    content: 'Fetching Fields of the Object......';
    width: 100%;
    text-align: center;
    top: calc(50% + 3em);
    font-weight: bold;
}
2
  • In case of dynamic message for different scenarios? Jul 13, 2021 at 12:00
  • @AdityaVijay you can have several CSS classes with different content message, then use a getter in JS to toggle the class name based on the conditions
    – Shamina
    Jul 13, 2021 at 13:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .