1

Able to display Toast message in Lightning. But I need to set duration for lightning toast messages how can I do it. I need to display toast message for few seconds in screen..now what's happening is it will stay in screen forever..after showing msg it should appear .. for below line of code.

I have tried like this:

 showNotification : function(component,variant,title,messageBody,mode){
    component.find('message').showToast({
        "variant": variant,
        "title": title,
        "message": messageBody,
         duration:' 5000',
        "mode": mode
    });

Components:

  <lightning:notificationsLibrary aura:id="message"/>

Js side:

  if(component.get('v.phoneQSelected') === '--None--'){
        helper.showNotification(component,"Error","Missing Value","What phone Q did the call originate on?","sticky");
        return;
    }

 showNotification : function(component,variant,title,messageBody,mode){
    component.find('message').showToast({
        "variant": variant,
        "title": title,
        "message": messageBody,

        "mode": mode
    });
1

For now, the only way to specify a duration is force:showToast.

$A.get("e.force:showToast")
    .setParams({duration: 5000, ... })
    .fire();

The lightning:notificationsLibrary is the preferred mechanism, but does not allow you to specify anything other than until dismissed, dismissed or 3 seconds, or 3 seconds.

2
  if(component.get('v.phoneQSelected') === '--None--'){
    helper.showNotification(component,"Error","Missing Value","What phone Q did the call originate on?","**dismissible**");
    return;
}

You need to change the value for the parameter mode to either dismissible or pester. Refer this link for more info here

In the specification tab you can find detailed information for each attribute.

1

From docs for lightning : notification.

mode: Determines how persistent the toast is. The default is dismissable. Valid modes are:

  1. dismissable: Remains visible until you press the close button or 3 seconds has elapsed, whichever comes first.
  2. pester: Remains visible until the close button is clicked.
  3. sticky: Remains visible for 3 seconds.

There is no extra parameter to control the timing of the toasts. The reason being showing toast and looks are controlled by lightning container. (one.app) and the container does not provide you that flexibility. The reason being SF wants you to stick to the standard SF guidelines. This makes it uniform and all toast in Standard SF are 3 secs long.

You have to design your own toast component using SLDS, once it's your component you can control your duration using Javascript.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.