All files / packages/sds-recipes/src/modules/c/feedbackTooltip feedbackTooltip.js

100% Statements 16/16
75% Branches 3/4
75% Functions 3/4
100% Lines 16/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65              12x 12x   12x   12x   12x                             26x         1x           2x             7x 7x 7x 7x   7x     4x 4x       4x        
import { LightningElement } from 'lwc';
 
export default class FeedbackTooltip extends LightningElement {
  // Render component in native shadow mode
  static shadowSupportMode = 'native';
 
  // Private Variables
  _moreInfo = false;
  _label = 'Tell us more'; // Use a localized label
  _textareaPlaceholder = 'Give feedback...'; // Use localized placeholder
  _textareaHelpMessage;
  _thumbsUpSelected = false;
  _thumbsDownSelected = false;
 
  /**
   * Returns the popover type depending on the thumbs down state.
   *
   * Thumbs down selected = popover
   * Thumbs down not selected = tooltip
   */
  get popoverType() {
    return this._thumbsDownSelected ? 'popover' : 'tooltip';
  }
 
  get popoverPlacement() {
    // If this._thumbsDownSelected is true
    //   it should be a popover whose placement should be 'block-end'
    // Else, it is a tooltip and its placement would be block-start'
    return this._thumbsDownSelected ? 'block-end' : 'block-start';
  }
 
  // Event Handlers
  handleChangeOther(event) {
    this._moreInfo = event.target.checked;
  }
 
  handleTextareaBlur(event) {
    // validate textarea content
  }
 
  handleClickCancel(event) {
    event.target.dispatchEvent(new CustomEvent('close', { composed: true, bubbles: true }));
    this._thumbsDownSelected = false;
  }
 
  handleClickThumbsDown(event) {
    this._thumbsUpSelected = false;
    this._thumbsDownSelected = !this._thumbsDownSelected;
    if (this._thumbsDownSelected) {
    E  this.template.querySelector('.dual-popover').openPopover();
    }
    event.stopPropagation();
  }
 
  handleClickThumbsUp() {
    this._thumbsDownSelected = false;
    this._thumbsUpSelected = !this._thumbsUpSelected;
    // Trigger positive feedback action
  }
 
  handlePopoverClosed(event) {
    this._thumbsDownSelected = false;
  }
}