all files / modules/ember-ticketfly-accordion/components/ tf-accordion-panel-body.js

100% Statements 12/12
87.5% Branches 7/8
100% Functions 6/6
100% Lines 12/12
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135                                                                                                                                                    37×                                       26×   26×             37×   37× 11×   11× 11×                 27×   27×           26×       27×        
import Component from 'ember-component';
import layout from '../templates/components/tf-accordion-panel-body';
import get from 'ember-metal/get';
import { default as computed, not } from 'ember-computed';
import { scheduleOnce } from 'ember-runloop';
 
/**
 * @module tf-accordion
 */
 
/**
 * @class TFAccordionPanelBodyComponent
 * @namespace TFAccordion
 * @extends Ember.Component
 */
export default Component.extend({
  layout,
 
  attributeBindings: [
    'tabID:aria-labelledby',
    'aria-hidden',
    'isHidden:hidden'
  ],
 
  classNames: ['tfa-panel-body'],
 
  tabID: '',
  content: '',
 
  /**
   * Tracks whether or not the panel that this body belongs to is expanded.
   * This is bound to the computed function for determining
   * the value of this component's element's `aria-hidden` property
   *
   * @property isPanelExpanded
   * @type Boolean
   * @default false
   */
  isPanelExpanded: false,
 
  /**
   * Bound to the `role` attribute of the `tf-accordion-panel-body` component's element.
   *
   * See http://www.w3.org/TR/wai-aria/roles#tabpanel
   *
   * @property ariaRole
   * @type String
   * @default 'tabpanel'
   */
  ariaRole: 'tabpanel',
 
  /* ---------- COMPUTEDS ---------- */
 
  /**
   * Bound to the `hidden` attribute on this component's element.
   *
   * @see {@link https://developer.mozilla.org/en/docs/Web/HTML/Global_attributes/hidden}
   * @property isHidden
   * @type String
   */
  isHidden: not('isPanelExpanded'),
 
  /**
   * Bound to the `aria-hidden` attribute on this component's element.
   *
   * @see {@link https://www.w3.org/TR/wai-aria-practices-1.1/#accordion}
   * @see {@link https://github.com/BrianSipple/why-am-i-doing-this/blob/master/ember/aria-attribute-binding-in-components.md}
   * @property aria-hidden
   * @type String
   * @default 'false'
   * @readOnly
   */
  'aria-hidden': computed('isHidden', {
    get() {
      return get(this, 'isHidden') ? 'true' : 'false';
    }
  }).readOnly(),
 
  /**
   * The instance object of the `tf-accordion-panel` component to
   * which this panel body belongs.
   *
   * @property panel
   * @type TFAccordion.TFAccordionPanelComponent
   * @default null
   */
  panel: null,
 
  /* ---------- LIFECYCLE ---------- */
 
  /**
   * @override
   */
  init() {
    this._super(...arguments);
 
    scheduleOnce('actions', this, this._registerWithPanel);
  },
 
  /**
   * @override
   */
  didReceiveAttrs({ oldAttrs }) {
    this._super(...arguments);
 
    if (oldAttrs && !!oldAttrs.isPanelExpanded) {
      const wasPanelExpanded = !!oldAttrs.isPanelExpanded.value;
 
      Eif (get(this, 'isPanelExpanded') !== wasPanelExpanded) {
        get(this, 'accordion').send('_panelBodyExpansionWasChanged', get(this, 'panel'), get(this, 'isPanelExpanded'));
      }
    }
  },
 
  /**
   * @override
   */
  willDestroyElement() {
    this._super(...arguments);
 
    scheduleOnce('actions', this, this._unRegisterWithPanel);
  },
 
  /* ---------- PRIVATE METHODS ---------- */
 
  _registerWithPanel() {
    get(this, 'panel').registerPanelBody(this);
  },
 
  _unRegisterWithPanel() {
    get(this, 'panel').unRegisterPanelBody(this);
  }
});