Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. <!-- childWebComp.html -->
  2. <template>
  3. <lightning-button label="Close tab" icon-name="utility:chevronclose" icon-position="right" onclick={handleButtonChange}></lightning-button>
  4. </template>
  5.  
  6. // childWebComp.js
  7. import { LightningElement } from 'lwc';
  8.  
  9. export default class CategoryFilter extends LightningElement {
  10.  
  11. handleButtonChange(){
  12. var close = true;
  13. const closeclickedevt = new CustomEvent('closeclicked', {
  14. detail: { close },
  15. });
  16.  
  17. // Fire the custom event
  18. this.dispatchEvent(closeclickedevt);
  19. }
  20.  
  21. }
  22. Now write parent Aura component and controller to changed event
  23.  
  24. <lightning:card title="AuraDomEventListener" iconName="custom:custom30">
  25. <aura:set attribute="actions">
  26. <span class="aura">Aura Component</span>
  27. </aura:set>
  28. <div class="slds-m-around_medium">
  29. <lightning:layout>
  30. <lightning:layoutItem size="4">
  31. **<!-- This is an LWC component -->
  32. <c:childWebComp oncloseclicked="{!c.handleFilterChange}"/>**
  33. </lightning:layoutItem>
  34. <lightning:layoutItem size="8" class="slds-p-left_medium">
  35. {!v.message}
  36. </lightning:layoutItem>
  37. </lightning:layout>
  38. </div>
  39. </lightning:card>
  40.  
  41.  
  42.  
  43. var CloseClicked = event.getParam('close');
  44. component.set('v.message', 'Close Clicked');
  45.  
  46.  
  47. var workspaceAPI = component.find("workspace");
  48. workspaceAPI.getFocusedTabInfo().then(function(response) {
  49. var focusedTabId = response.tabId;
  50. workspaceAPI.closeTab({tabId: focusedTabId});
  51. })
  52. .catch(function(error) {
  53. console.log(error);
  54. });
  55. },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement