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;
59 this.toggleClass('iron-collapse-closed', false);
60 this.updateSize('auto', false);
61 var s = this._calcSize();
62 this.updateSize('0px', false);
63 // force layout to ensure transition will go
65 this.updateSize(s, true);
69 this.toggleClass('iron-collapse-opened', false);
70 this.updateSize(this._calcSize(), false);
71 // force layout to ensure transition will go
73 this.updateSize('0px', true);
76 updateSize: function(size, animated) {
77 this.enableTransition(animated);
79 var nochange = s[this.dimension] === size;
80 s[this.dimension] = size;
81 if (animated && nochange) {
82 this._transitionEnd();
86 enableTransition: function(enabled) {
87 this.style.transitionDuration = (enabled && this._enableTransition) ? '' : '0s';
90 _horizontalChanged: function() {
91 this.dimension = this.horizontal ? 'width' : 'height';
92 this.style.transitionProperty = this.dimension;
95 _openedChanged: function() {
96 this[this.opened ? 'show' : 'hide']();
97 this.setAttribute('aria-expanded', this.opened ? 'true' : 'false');
101 _transitionEnd: function() {
103 this.updateSize('auto', false);
105 this.toggleClass('iron-collapse-closed', !this.opened);
106 this.toggleClass('iron-collapse-opened', this.opened);
107 this.enableTransition(false);
110 _calcSize: function() {
111 return this.getBoundingClientRect()[this.dimension] + 'px';