Salesforce LWC : Compact Layout on Hover



Salesforce LWC : Compact Layout showing on Hover

Sometime we have requirement to show Account name link on standard views, a popup with the Compact Layout shows the details of that record.


LWC Parent Component : Template (HTML Code)



<template>
	<lightning-card  title="Account Details">
        <lightning-record-view-form
                record-id={recordId}
                object-api-name="Account">
                <div class="slds-box">
                    <!-- Tooltip-->
                    <div style="display:none;position: absolute;opacity:0" class="ModelTooltip">
                        <c-compact-layout-on-hover record-id={recordId} ></c-compact-layout-on-hover>
                    </div>
                    <lightning-output-field field-name="Name" onmouseout={handleMouseout} onmouseover={handleMouseover}>
                    </lightning-output-field>
                </div>
        </lightning-record-view-form>
    </lightning-card>
</template>



LWC : JS (Process Code)



import { LightningElement,api } from 'lwc';

export default class AccountComponent extends LightningElement {
   @api recordId;
    @track objRecordId;
    handleMouseover(event) {
        console.log(this.recordId);
        this.objRecordId = null
        const toolTipDiv = this.template.querySelector('div.ModelTooltip');
        toolTipDiv.style.opacity = 1;
        toolTipDiv.style.display = "block";
        // eslint-disable-next-line
        window.clearTimeout(this.delayTimeout);
        // eslint-disable-next-line @lwc/lwc/no-async-operation
        this.delayTimeout = setTimeout(() => {
            this.objRecordId = this.recordId;
        }, 50);
    }

    /* Handle Mouse Out*/
    handleMouseout() {
        const toolTipDiv = this.template.querySelector('div.ModelTooltip');
        toolTipDiv.style.opacity = 0;
        toolTipDiv.style.display = "none";
    }
}



LWC : XML (Config Code)



<!--xml version="1.0" encoding="UTF-8"?-->
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>51.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__RecordPage</target>
    </targets>
</LightningComponentBundle>



LWC Child Component (CompactLayoutOnHover) : Template (HTML Code)



<template>
      <div>
        <template if:true={recordId} >
        <div style="position: absolute; opacity: 1" class="ModelTooltip">
            <section class="slds-popover slds-popover_panel slds-nubbin_top-left" role="dialog">
              <div class="slds-popover__header">
                <header class="slds-media slds-media_center slds-m-bottom_small">
                  <div class="slds-media__body">
                    <h2 class="slds-text-heading_medium slds-hyphenate">Account Details</h2>
                  </div>
                </header>
              </div>
              <div class="slds-popover__body">
                <lightning-record-form record-id={recordId} object-api-name="Account" layout-type="Compact" columns="1" mode="readonly"> </lightning-record-form>
              </div>
            </section>
          </div>
          </template>
      </div>
</template>



LWC : JS (Process Code)



import { LightningElement,api } from 'lwc';

export default class PopoverComponent extends LightningElement {
    @api recordId;
}



LWC : XML (Config Code)



<!--xml version="1.0" encoding="UTF-8"?-->
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>51.0</apiVersion>
    <isExposed>false</isExposed>
</LightningComponentBundle>



LWC :Output


Happy Sharing...

Everyone has their own favorites, so please feel free to share with yours contacts and comments below for any type of help!

Comments

  1. 360degree Salesforce implementation services opens doors to wide-ranging benefits for the efficiency in your business process, bringing you better results. Streamlining the business processes, managing contacts, lead management, tracking the customer timelines and activities, closing deals faster , 360degree makes it all so easy to handle. As a platform for success, customizability lets the Salesforce CRM bring together the most tools for productivity and enablement in one place.

    visit-360degreecloud

    ReplyDelete
  2. Thanks for your great information.

    ReplyDelete
  3. I tried this on other object which is added it into the Opportunity object related list. but I am getting error bcz it is different object. Can you please help for this how will pass other object id . How we will get other object compact layout records hover in opportunity related list. If you give solution it is more help full to me.

    ReplyDelete
    Replies
    1. Hi Nidhee, were you able to get the answer to this question? i have a same requirement. Thanks.

      Delete
  4. Aswindow is the Top Organization upvc entryways makers in delhi and Supply UPVC, Top of the line Entryways and Windows to Clients All around The Noida, Delhi Gurgaon and NCR. AS Window is a trailblazer in the creation of plasticized upvc window suppliers in gurugram and entryways. UPVC is a superb option in contrast to wood and metal. AS Window offers an extensive variety of wonderful and perfect home window plans that won't just change your home yet will likewise safeguard it from the rest of the world. UPVC is an all-climate, harmless to the ecosystem, intensity and commotion safe material for entryways and windows that add solace, accommodation, and style to current homes.

    ReplyDelete
  5. Model is disappeared when I mouse hover on it because of mouseout event so is there any solution so when mouse hover on model then it should not go away.

    ReplyDelete

Post a Comment

Popular posts from this blog

Salesforce LWC With Third Party JS : D3

Communications between Lightning Components : Salesforce