Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- childWebComp.html -->
- <template>
- <lightning-button label="Close tab" icon-name="utility:chevronclose" icon-position="right" onclick={handleButtonChange}></lightning-button>
- </template>
- // childWebComp.js
- import { LightningElement } from 'lwc';
- export default class CategoryFilter extends LightningElement {
- handleButtonChange(){
- var close = true;
- const closeclickedevt = new CustomEvent('closeclicked', {
- detail: { close },
- });
- // Fire the custom event
- this.dispatchEvent(closeclickedevt);
- }
- }
- Now write parent Aura component and controller to changed event
- <lightning:card title="AuraDomEventListener" iconName="custom:custom30">
- <aura:set attribute="actions">
- <span class="aura">Aura Component</span>
- </aura:set>
- <div class="slds-m-around_medium">
- <lightning:layout>
- <lightning:layoutItem size="4">
- **<!-- This is an LWC component -->
- <c:childWebComp oncloseclicked="{!c.handleFilterChange}"/>**
- </lightning:layoutItem>
- <lightning:layoutItem size="8" class="slds-p-left_medium">
- {!v.message}
- </lightning:layoutItem>
- </lightning:layout>
- </div>
- </lightning:card>
- var CloseClicked = event.getParam('close');
- component.set('v.message', 'Close Clicked');
- var workspaceAPI = component.find("workspace");
- workspaceAPI.getFocusedTabInfo().then(function(response) {
- var focusedTabId = response.tabId;
- workspaceAPI.closeTab({tabId: focusedTabId});
- })
- .catch(function(error) {
- console.log(error);
- });
- },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement