10 * If true, the orientation is horizontal; otherwise is vertical.
12 * @attribute horizontal
17 observer: '_horizontalChanged'
21 * Set opened to true to show the collapse element and to false to hide it.
29 observer: '_openedChanged'
36 'aria-expanded': 'false'
40 transitionend: '_transitionEnd'
44 // Avoid transition at the beginning e.g. page loads and enable
45 // transitions only after the element is rendered and ready.
46 this._enableTransition = true;
50 * Toggle the opened state.
55 this.opened = !this.opened;
66 updateSize: function(size, animated) {
67 this.enableTransition(animated);
69 var nochange = s[this.dimension] === size;
70 s[this.dimension] = size;
71 if (animated && nochange) {
72 this._transitionEnd();
76 enableTransition: function(enabled) {
77 this.style.transitionDuration = (enabled && this._enableTransition) ? '' : '0s';
80 _horizontalChanged: function() {
81 this.dimension = this.horizontal ? 'width' : 'height';
82 this.style.transitionProperty = this.dimension;
85 _openedChanged: function() {
87 this.toggleClass('iron-collapse-closed', false);
88 this.updateSize('auto', false);
89 var s = this._calcSize();
90 this.updateSize('0px', false);
91 // force layout to ensure transition will go
92 /** @suppress {suspiciousCode} */ this.offsetHeight;
93 this.updateSize(s, true);
96 this.toggleClass('iron-collapse-opened', false);
97 this.updateSize(this._calcSize(), false);
98 // force layout to ensure transition will go
99 /** @suppress {suspiciousCode} */ this.offsetHeight;
100 this.updateSize('0px', true);
102 this.setAttribute('aria-expanded', this.opened ? 'true' : 'false');
106 _transitionEnd: function() {
108 this.updateSize('auto', false);
110 this.toggleClass('iron-collapse-closed', !this.opened);
111 this.toggleClass('iron-collapse-opened', this.opened);
112 this.enableTransition(false);
115 _calcSize: function() {
116 return this.getBoundingClientRect()[this.dimension] + 'px';