8 * If true, the orientation is horizontal; otherwise is vertical.
10 * @attribute horizontal
15 observer: '_horizontalChanged'
19 * Set opened to true to show the collapse element and to false to hide it.
27 observer: '_openedChanged'
34 'aria-expanded': 'false'
38 transitionend: '_transitionEnd'
42 // Avoid transition at the beginning e.g. page loads and enable
43 // transitions only after the element is rendered and ready.
44 this._enableTransition = true;
48 * Toggle the opened state.
53 this.opened = !this.opened;
64 updateSize: function(size, animated) {
65 this.enableTransition(animated);
67 var nochange = s[this.dimension] === size;
68 s[this.dimension] = size;
69 if (animated && nochange) {
70 this._transitionEnd();
74 enableTransition: function(enabled) {
75 this.style.transitionDuration = (enabled && this._enableTransition) ? '' : '0s';
78 _horizontalChanged: function() {
79 this.dimension = this.horizontal ? 'width' : 'height';
80 this.style.transitionProperty = this.dimension;
83 _openedChanged: function() {
85 this.toggleClass('iron-collapse-closed', false);
86 this.updateSize('auto', false);
87 var s = this._calcSize();
88 this.updateSize('0px', false);
89 // force layout to ensure transition will go
90 /** @suppress {suspiciousCode} */ this.offsetHeight;
91 this.updateSize(s, true);
94 this.toggleClass('iron-collapse-opened', false);
95 this.updateSize(this._calcSize(), false);
96 // force layout to ensure transition will go
97 /** @suppress {suspiciousCode} */ this.offsetHeight;
98 this.updateSize('0px', true);
100 this.setAttribute('aria-expanded', this.opened ? 'true' : 'false');
104 _transitionEnd: function() {
106 this.updateSize('auto', false);
108 this.toggleClass('iron-collapse-closed', !this.opened);
109 this.toggleClass('iron-collapse-opened', this.opened);
110 this.enableTransition(false);
113 _calcSize: function() {
114 return this.getBoundingClientRect()[this.dimension] + 'px';