diff --git a/addon/components/paper-autocomplete-trigger.js b/addon/components/paper-autocomplete-trigger.js index 977a61a05..97469f6c4 100644 --- a/addon/components/paper-autocomplete-trigger.js +++ b/addon/components/paper-autocomplete-trigger.js @@ -39,28 +39,50 @@ export default Component.extend({ }), // Lifecycle hooks - didUpdateAttrs({ oldAttrs, newAttrs }) { + init() { this._super(...arguments); + this.set('oldSelect', this.get('select')); + this.set('oldLoading', this.get('loading')); + this.set('oldLastSearchedText', this.get('lastSearchedText')); + }, + + didUpdateAttrs() { + this._super(...arguments); + + let oldSelect = this.get('oldSelect'); + let oldLoading = this.get('oldLoading'); + let oldLastSearchedText = this.get('oldLastSearchedText'); + + let select = this.get('select'); + let loading = this.get('loading'); + let searchText = this.get('searchText'); + let lastSearchedText = this.get('lastSearchedText'); + let options = this.get('options'); + /* * We need to update the input field with value of the selected option whenever we're closing * the select box. But we also close the select box when we're loading search results and when * we remove input text -- so protect against this */ - if (oldAttrs.select.isOpen && !newAttrs.select.isOpen && !newAttrs.loading && newAttrs.searchText) { + if (oldSelect.isOpen && !select.isOpen && !loading && searchText) { this.set('text', this.getSelectedAsText()); } - if (newAttrs.lastSearchedText !== oldAttrs.lastSearchedText) { - if (isBlank(newAttrs.lastSearchedText)) { - run.schedule('actions', null, newAttrs.select.actions.close, null, true); + if (lastSearchedText !== oldLastSearchedText) { + if (isBlank(lastSearchedText)) { + run.schedule('actions', null, select.actions.close, null, true); } else { - run.schedule('actions', null, newAttrs.select.actions.open); + run.schedule('actions', null, select.actions.open); } - } else if (!isBlank(newAttrs.lastSearchedText) && get(this, 'options.length') === 0 && this.get('loading')) { - run.schedule('actions', null, newAttrs.select.actions.close, null, true); - } else if (oldAttrs.loading && !newAttrs.loading && newAttrs.options.length > 0) { - run.schedule('actions', null, newAttrs.select.actions.open); + } else if (!isBlank(lastSearchedText) && get(this, 'options.length') === 0 && this.get('loading')) { + run.schedule('actions', null, select.actions.close, null, true); + } else if (oldLoading && !loading && options.length > 0) { + run.schedule('actions', null, select.actions.open); } + + this.set('oldSelect', select); + this.set('oldLoading', loading); + this.set('oldLastSearchedText', lastSearchedText); }, // Actions diff --git a/addon/components/paper-virtual-repeat.js b/addon/components/paper-virtual-repeat.js index 13c35e1a6..9816803c5 100644 --- a/addon/components/paper-virtual-repeat.js +++ b/addon/components/paper-virtual-repeat.js @@ -117,6 +117,11 @@ const VirtualRepeatComponent = VirtualEachComponent.extend({ return Math.ceil(this.get('itemHeight') ? size / this.get('itemHeight') : 1) + EXTRA_ROW_PADDING; }).readOnly(), + init() { + this._super(...arguments); + this.set('oldScrollIndex', this.get('scrollIndex')); + }, + didInsertElement() { this._super(...arguments); @@ -127,9 +132,15 @@ const VirtualRepeatComponent = VirtualEachComponent.extend({ }); }, - didReceiveAttrs(changes) { + didReceiveAttrs() { this._super(...arguments); - let { newAttrs, oldAttrs = {} } = changes; + + let height = this.get('height'); + let width = this.get('width'); + let scrollIndex = this.get('scrollIndex'); + let scrollTop = this.get('scrollTop'); + + let oldScrollIndex = this.get('oldScrollIndex'); RSVP.cast(this.getAttr('items')).then((attrItems) => { let items = emberArray(attrItems); @@ -141,17 +152,19 @@ const VirtualRepeatComponent = VirtualEachComponent.extend({ }); // Set size explicitly - if (newAttrs.height) { - this.set('size', newAttrs.height); - } else if (newAttrs.width) { - this.set('size', newAttrs.width); + if (height) { + this.set('size', height); + } else if (width) { + this.set('size', width); } // Scroll index has changed, load more data & scroll - if (oldAttrs.scrollIndex !== newAttrs.scrollIndex) { - this.scrollToVirtualItem(newAttrs.scrollIndex, newAttrs.scrollTop); + if (oldScrollIndex !== scrollIndex) { + this.scrollToVirtualItem(scrollIndex, scrollTop); } }); + + this.set('oldScrollIndex', scrollIndex); }, didRender() {