Saturday, August 10, 2019

LWC: Modal implementation



Check the code in the below repo for the modal implementation in LWC:
https://github.com/iamsonal/lwc-modal

Notes:
  • If you want to hide the close icon, then set the hide-close property to true like below:

  • <!-- modalContainer.html -->
    <template>
        <c-modal name="Modal Name" title="Modal Title" hide-close>
        </c-modal>
    </template>

  • Similarly, if you want to display a large modal, then set the is-large property to true like below:

  • <!-- modalContainer.html -->
    <template>
        <c-modal name="Modal Name" title="Modal Title" hide-close is-large>
        </c-modal>
    </template>


  • Using slots (unnamed and named), we are passing the modal body and footer content from parent into the child component like below. In this way, we can control the markup that can be displayed in the modal. For more information about how to use slots, check the LWC documentation.

  • <c-modal name="Modal Name" title="Modal Title" >
    
        <!-- Unnamed Slot -->
        <p>This is some content</p>
    
        <!-- Named Slot -->
        <div slot="footer" style="display: inline;">
            <lightning-button label="Close" variant="neutral" onclick={handleCancelModal}></lightning-button>
        </div>
        
    </c-modal>


  • Set the style-class property to apply a custom CSS in the modal.

Share This:    Facebook Twitter

1 comment:

  1. Is there a way to pass an entire component into an slot?

    ReplyDelete

Total Pageviews

My Social Profiles

View Sonal's profile on LinkedIn

Tags

__proto__ $Browser Access Grants Accessor properties Admin Ajax AllowsCallouts Apex Apex Map Apex Sharing AssignmentRuleHeader AsyncApexJob Asynchronous Auth Provider AWS Callbacks Connected app constructor Cookie CPU Time CSP Trusted Sites CSS Custom settings CustomLabels Data properties Database.Batchable Database.BatchableContext Database.query Describe Result Destructuring Dynamic Apex Dynamic SOQL Einstein Analytics enqueueJob Enterprise Territory Management Enumeration escapeSingleQuotes featured Flows geolocation getGlobalDescribe getOrgDefaults() getPicklistValues getRecordTypeId() getRecordTypeInfosByName() getURLParameters Google Maps Governor Limits hasOwnProperty() Heap Heap Size IIFE Immediately Invoked Function Expression Interview questions isCustom() Javascript Javascript Array jsForce Lightning Lightning Components Lightning Events lightning-record-edit-form lightning:combobox lightning:icon lightning:input lightning:select LockerService Lookup LWC Manual Sharing Map Modal Module Pattern Named Credentials NodeJS OAuth Object.freeze() Object.keys() Object.preventExtensions() Object.seal() Organization Wide Defaults Override PDF Reader Performance performance.now() Permission Sets Picklist Platform events Popup Postman Primitive Types Profiles Promise propertyIsEnumerable() prototype Query Selectivity Queueable Record types Reference Types Regex Regular Expressions Relationships Rest API Rest Operator Revealing Module Pattern Role Hierarchy Salesforce Salesforce Security Schema.DescribeFieldResult Schema.DescribeSObjectResult Schema.PicklistEntry Schema.SObjectField Schema.SObjectType Security Service Components Shadow DOM Sharing Sharing Rules Singleton Slots SOAP API SOAP Web Services SOQL SOQL injection Spread Operator Star Rating stripInaccessible svg svgIcon Synchronous this Token Triggers uiObjectInfoApi Upload Files VSCode Web Services XHR
Scroll To Top