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

100% Statements 11/11
100% Branches 2/2
100% Functions 9/9
100% Lines 11/11
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 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185                                                                                                                                                                                                    37×                                                 26×   26×             27×   27×                   10×                               10×                           26×       27×        
import Component from 'ember-component';
import layout from '../templates/components/tf-accordion-panel-tab';
import get from 'ember-metal/get';
import { default as computed, readOnly } from 'ember-computed';
import { once } from 'ember-runloop';
 
/**
 * @module tf-accordion
 */
 
/**
 * @class TFAccordionPanelTabComponent
 * @namespace TFAccordion
 * @extends Ember.Component
 */
export default Component.extend({
  layout,
  tagName: 'button',
 
  attributeBindings: [
    'aria-expanded',
    'aria-selected',
    'aria-controls'
  ],
 
  classNames: ['tfa-panel-tab'],
  classNameBindings: ['isPanelExpanded:tfa-panel-tab--expanded:tfa-panel-tab--hidden'],
 
  /**
   * Bound to the `role` attribute of the `tf-accordion-panel-tab` component's element.
   *
   * See http://www.w3.org/TR/wai-aria/roles#tab
   *
   * @property ariaRole
   * @type String
   * @default 'tab'
   */
  ariaRole: 'tab',
 
  /**
   * Tracks whether or not the panel that this tab belongs to is expanded.
   * This is bound to the computed function for determining
   * the value of this component's element's `aria-expanded` property
   *
   * @property isPanelExpanded
   * @type Boolean
   * @default false
   */
  isPanelExpanded: false,
 
  /**
   * The id of the element for this tab's sibling panel body component
   *
   * @property panelBodyID
   * @type String
   */
  panelBodyID: '',
 
  /**
   * The id of the element for this tab's sibling panel body component
   *
   * @property panelBodyID
   * @type String
   */
  title: '',
 
  /**
   * The instance object of the `tf-accordion` component that
   * this tab's panel belongs to.
   *
   * @property accordion
   * @type TFAccordion.TFAccordionComponent
   */
  accordion: null,
 
  /**
   * The instance object of the `tf-accordion-panel` component to
   * which this panel tab belongs.
   *
   * @property panel
   * @type TFAccordion.TFAccordionPanelComponent
   */
  panel: null,
 
  /* ---------- COMPUTEDS ---------- */
 
  /**
   * Bound to the `aria-expanded` 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-expanded
   * @type String
   * @default 'false'
   * @readOnly
   */
  'aria-expanded': computed('isPanelExpanded', {
    get() {
      return get(this, 'isPanelExpanded') ? 'true' : 'false';
    }
  }).readOnly(),
 
  /**
   * Bound to the `aria-controls` attribute on this component's element.
   * This identifies the element -- in this case, our sibling panel body --
   * whose contents or presence are controlled by the current element.
   *
   * (There's a bit of skepticism as to what purpose this property serves, but
   * we'll follow the spec for the time being.)
   *
   * @see {@link https://www.w3.org/TR/wai-aria/states_and_properties#aria-controls}
   * @property aria-controls
   * @type String
   * @readOnly
   */
  'aria-controls': readOnly('panelBodyID'),
 
  /* ---------- LIFECYCLE ---------- */
 
  /**
   * @override
   */
  init() {
    this._super(...arguments);
 
    once(this, this._registerWithPanel);
  },
 
  /**
   * @override
   */
  willDestroyElement() {
    this._super(...arguments);
 
    once(this, this._unRegisterWithPanel);
  },
 
  /* ---------- EVENT HANDLERS ---------- */
 
  /**
   * When the `click` DOM event fires on the element, trigger the
   * root `tf-accordion` component's action with the panel component
   */
  click(/* event */) {
    get(this, 'accordion').send('_onPanelSelection', get(this, 'panel'));
  },
 
  /**
   * When the `touchEnd` DOM event fires on the element, trigger the
   * root `tf-accordion` component's action with the panel component
   */
  touchEnd(/* event */) {
    get(this, 'accordion').send('_onPanelSelection', get(this, 'panel'));
  },
 
  /**
   * When the `focusIn` DOM event fires on the element, trigger the
   * root `tf-accordion` component's action with the panel component
   * and the jQuery event.
   */
  focusIn(event) {
    get(this, 'accordion').handlePanelEvent('onPanelTabFocusIn', get(this, 'panel'), event);
  },
 
  /**
   * When the `focusOut` DOM event fires on the element, trigger the
   * root `tf-accordion` component's action with the panel component
   * and the jQuery event.
   */
  focusOut(event) {
    get(this, 'accordion').handlePanelEvent('onPanelTabFocusOut', get(this, 'panel'), event);
  },
 
  /* ---------- PRIVATE METHODS ---------- */
 
  _registerWithPanel() {
    get(this, 'panel').registerTab(this);
  },
 
  _unRegisterWithPanel() {
    get(this, 'panel').unRegisterTab(this);
  }
});