From d379ec5ae2101d1cf6f466f903b4383621bf1ac9 Mon Sep 17 00:00:00 2001 From: Anthony Koerber Date: Wed, 19 Aug 2015 14:17:02 -0500 Subject: [PATCH] pre-selected item fix --- src/mm-dropdown/mm-dropdown.js | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/mm-dropdown/mm-dropdown.js b/src/mm-dropdown/mm-dropdown.js index ad2d06ff..bb797b25 100644 --- a/src/mm-dropdown/mm-dropdown.js +++ b/src/mm-dropdown/mm-dropdown.js @@ -105,7 +105,6 @@ open: function(silent) { var inherited = BehaviorUtils.findSuper(StrandTraits.PositionableDropdown, 'open'); // Ensures that we get a value for the offsetHeight of the distributed list items: - // See Selectable behavior if (this.maxItems) this._setMaxHeight(this.maxItems); if (!this._widthLocked) this._lockWidth(); @@ -126,21 +125,20 @@ if(this.state === this.STATE_OPENED) this.close(); }, - _selectItemByValue: function(value) { - var item = null; - - value = value.toString(); - - if (!this._widthLocked) this._lockWidth(); + this.async(function(){ + var item = null; + value = value.toString(); - if (this.data) { - item = this._getDataItemByValue(value); - } else { + if (!this._widthLocked) this._lockWidth(); - item = this._getDomByValue(value); - } - if (item) this.selectedIndex = this.items.indexOf(item); + if (this.data) { + item = this._getDataItemByValue(value); + } else { + item = this._getDomByValue(value); + } + if (item) this.selectedIndex = this.items.indexOf(item); + }); }, _updateSelectedItem: function(e) { @@ -177,7 +175,7 @@ // Data handling _dataChanged: function(newData, oldData) { - if(newData) this._setMaxHeight(this.maxItems); + if (newData) this._setMaxHeight(this.maxItems); if (newData && this.value) this._selectItemByValue(this.value); }, @@ -316,7 +314,7 @@ }, _setMaxHeight: function(maxItems) { - actualMax = Math.min(this.items.length, maxItems); + var actualMax = Math.min(this.items.length, maxItems); this.$.list.style.height = this.itemHeight * actualMax + 'px';