I have a datatable with a column button "Open". Clicking this button should open a modal. The modal is shown under the component, not as a pop up. Could you point out my error please?

        <div style="height: 300px;">
        <template if:true={openModal}>
                <div class="slds-modal__container">
                        <button class="slds-button slds-button_icon slds-modal__close slds-button_icon-inverse">
                          <svg class="slds-button__icon slds-button__icon_large" aria-hidden="true">
                            <use xlink:href="/assets/icons/utility-sprite/svg/symbols.svg#close"></use>
                          <span class="slds-assistive-text">Cancel and close</span>
                        <div class="slds-modal__header">
                          <h1 id="modal-heading-01" class="slds-modal__title slds-hyphenate">Modal header</h1>
                        <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">
                          <p>Sit nulla est ex deserunt exercitation anim occaecat. Nostrud ullamco deserunt aute id consequat veniam incididunt duis in sint irure nisi. Mollit officia cillum Lorem ullamco minim nostrud elit officia tempor esse quis. Cillum sunt ad dolore quis
                            aute consequat ipsum magna exercitation reprehenderit magna. Tempor cupidatat consequat elit dolor adipisicing.</p>
                          <p>Dolor eiusmod sunt ex incididunt cillum quis nostrud velit duis sit officia. Lorem aliqua enim laboris do dolor eiusmod officia. Mollit incididunt nisi consectetur esse laborum eiusmod pariatur proident. Eiusmod et adipisicing culpa deserunt nostrud
                            ad veniam nulla aute est. Labore esse esse cupidatat amet velit id elit consequat minim ullamco mollit enim excepteur ea.</p>
                        <div class="slds-modal__footer">
                          <button class="slds-button slds-button_neutral" aria-label="Cancel and close">Cancel</button>
                          <button class="slds-button slds-button_brand">Save</button>

import { LightningElement, api, wire } from 'lwc';
import { NavigationMixin } from 'lightning/navigation';
import accounts from '@salesforce/apex/utils.getAccs';

const columns = [
    { label: 'Name', fieldName: 'Name' },
    { label: 'id', fieldName: 'Id'},
    { label: 'Action', type: 'button', typeAttributes: {
        iconName: 'action:preview',  
        label: 'View',  
        name: 'View',  
        title: 'View',  
        disabled: false,  
        value: 'view',  
        iconPosition: 'right'  
    { label: 'Action', type: 'button', typeAttributes: {
        iconName: 'action:preview',  
        label: 'Open Modal',  
        name: 'Open',  
        title: 'Open',  
        disabled: false,  
        value: 'open',  
        iconPosition: 'right'  

    export default class DataTable extends NavigationMixin(LightningElement) {
        @api recordId;
        @wire(accounts) data;
        openModal = false;
        columns = columns;
                console.log(event.detail.action.name); //View
                console.log(event.detail.row.Name); //Name
                console.log(event.detail.row.Id); //Id
                    type: 'standard__recordPage',
                    attributes: {
                        recordId: event.detail.row.Id,
                        actionName: 'view'
                this.openModal = true;

1 Answer 1


You are missing the outer slds-modal class (and also the backdrop) and that is likely to be the problem:

<section class="slds-modal slds-fade-in-open">
<div class="slds-backdrop slds-backdrop_open"></div>

See the SLDS Modals documentation.

Also this is the approach I have used to show/hide modals via CSS:

@api show = false;

get dialogClass() {
    const size = 'slds-modal_medium';
    const open = this.show ? 'slds-fade-in-open' : '';
    return `slds-modal ${size} ${open}`;

get backdropClass() {
    const open = this.show ? 'slds-backdrop_open' : '';
    return `slds-backdrop ${open}`;

with the the HTML then being:

<section class={dialogClass}>
<div class={backdropClass}></div>

You must log in to answer this question.

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