LWC Toast – Adding Line Break in LWC Toast Message

how can we achieve new line in LWC toast message. I tried using <br> and /n .. but it is not working. Its working in aura, but not in LWC.

JS-

showSuccessToast() {
    var sMsg = 'Salesforce documentation is available in the app.<br/>';
    sMsg += 'Click ? in the upper-right corner.';
    const evt = new ShowToastEvent({
        title: 'Record Update',
        message: sMsg,
        variant: 'success',
        mode: 'sticky'
    });
    this.dispatchEvent(evt);
}

enter image description here

Best Answer

You should try \n instead of /n. That aside, it is documented that there are some limitations between the Aura and LWC versions; use Aura if you definitely need this today. You can use an Aura wrapper and dispatch an event from your LWC to Aura, then have Aura use the lightning:notificationsLibrary module to show your message from there.

Related Topic