1

Is it possible to hide 'x' button

import { api } from 'lwc';
import LightningModal from 'lightning/modal';
import { PREVIEW_MARKUP } from 'c/constants';

export default class EmailPreviewMainModal extends LightningModal {
    @api content;
    renderedCallback() {
        this.template.querySelector('.container').innerHTML = PREVIEW_MARKUP;
    }
    handleOkay() {
        this.close();
    }
} 



EmailPreviewMainModal.open({
                size: 'small',
                label: 'Custom one',
            });
6
  • 2
    There is no option to hide the X (close) button on the top right corner of the modal, as it is part of the standard UI. You might need to build in the custom component. Commented Dec 27, 2023 at 11:31
  • i see but what is the option to do that? should i override <lightning-modal-header> ?
    – pincet
    Commented Dec 27, 2023 at 11:37
  • You need to remove the button above the header code. Commented Dec 27, 2023 at 11:40
  • 1
    Again, you'd have to write your own custom component, as you can't remove or hide the close button.
    – sfdcfox
    Commented Dec 27, 2023 at 11:49
  • 1
    Unfortunately so.
    – sfdcfox
    Commented Dec 27, 2023 at 22:18

1 Answer 1

0

Yes it is possible to hide the X button in a lightning-modal element. You will just need to override the style within a CSS file, save it as a static resource in your org, and import the file in your LWC.

To start, this is the exact styling that worked for me to remove the X button:

lightning-button-icon.slds-modal__close {
    display: none;
}

Once you've added this snippet to your CSS file and saved it as a static resource, import it into your LWC like so:

import { loadStyle } from 'lightning/platformResourceLoader';

import globalStylesheet from '@salesforce/resourceUrl/nameOfYourCSSFileStaticResource';

Lastly, just use the loadStyle import in the connectedCallback() of your LWC javascript file and that should do it!

connectedCallback() {
    loadStyle(this, globalStylesheet);
}
1
  • Be careful. This will hide the X for all modals because it loads the style into the global space.
    – Nick C
    Commented Jun 16 at 23:47

You must log in to answer this question.

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