2

When developing Aura components in Lightning Experience, you can use the Overlay Library to create a popover (via showCustomPopover()).

Is there an equivalent for LWC, or can I only use this library in an Aura component? If the latter, is there any kind of workaround, like wrapping the LWC component in an Aura component?

Note: in my case, this is being used inside a LWC that is within an Aura component, so unfortunately I can't use slots. Perhaps this would be a reason to develop the parent component as an Aura component.

1
  • 1
    You have to construct a "modal" as per SLDS using markup in the "parent component" for the "popover".
    – Phil W
    Commented Aug 6, 2021 at 16:57

1 Answer 1

3

You can refer to the SLDS Modal Blueprint to achieve the exact same thing, furthermore, you can create a "reusable" modal lwc component such as this one (which uses the slds blueprint I linked)

<template>
    <section role="dialog" tabindex="-1" aria-modal="true" class="slds-modal slds-fade-in-open">
        <div class={modalClasses}>
            <header class="slds-modal__header">
                <button class="slds-button slds-button_icon slds-modal__close slds-button_icon-inverse" title="Close"
                onclick={handleCloseEvent}>
                    <svg class="slds-button__icon slds-button__icon_large" aria-hidden="true">
                        <use xlink:href="/_slds/icons/utility-sprite/svg/symbols.svg#close"></use>
                    </svg>
                    <span class="slds-assistive-text">Close</span>
                    </button>
                <slot name="header">
                </slot>
            </header>
            <div>
                <slot name="content">
                </slot>
            </div>
            <footer class="slds-modal__footer">
                <slot name="footer"></slot>
            </footer>
        </div>
    </section>
        <div class="slds-backdrop slds-backdrop_open"></div>
</template>

and you can use it in your components as follows:

<c-custom-modal-box backdrop onclose={closeFilterModal}>
        <div slot="header">
           //your modal header content here
        </div>
        <div slot="content" class="modal-content slds-p-around_medium content-slot">
            //your modal content here
        </div>
    </c-custom-modal-box>

the js part should be fairly easy to implement (toggle the modal - displa-hide) and you can implement additional functionalities.

6
  • Unfortunately, this LWC would be within an Aura component, so I won't be able to use slots. Sorry - I just added that to the answer.
    – jbyrd
    Commented Aug 7, 2021 at 20:52
  • were you able to create your modal? hope the above helped. cheers
    – glls
    Commented Aug 11, 2021 at 1:20
  • I didn't get a chance yet, but this is helpful and I'll probably go this route. But before I do - surely someone's already created a popup LWC version? Is there some kind of marketplace of free user-created custom LWCs somewhere? Since I can't use slots, I could at least use the JS code for dynamic positioning.
    – jbyrd
    Commented Aug 11, 2021 at 19:58
  • 1
    you can simply ignore the slots for your component and replace the inner content with whatever html you want. as per ui marketplace(s), other than public github repos and the lwc recipes, there ain't much out there
    – glls
    Commented Aug 11, 2021 at 20:25
  • Would this reusable modal comply with this?: When the modal is open, everything behind it has HTML attribute aria-hidden="true", so assistive technology won't read out the underlying page. The best way to do this is to give the modal and the page separate wrapper elements and toggle aria-hidden="true"/aria-hidden="false" on the main page's wrapper depending on whether or not the modal is open.
    – Daniel
    Commented Oct 28, 2021 at 14:56

You must log in to answer this question.

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