Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resizing autocomplete suggestion container to take up only required amount of space #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions addon/components/paper-virtual-repeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const VirtualRepeatComponent = VirtualEachComponent.extend({
classNameBindings: ['horizontal:md-orient-horizontal'],
rawVisibleItems: computed.mapBy('visibleItems', 'raw'),
containerSelector: undefined,
originalScrollHeight: 0,

actions: {
onScroll(e) {
Expand All @@ -37,12 +38,24 @@ const VirtualRepeatComponent = VirtualEachComponent.extend({
size: computed('initialSize', 'items.[]', 'itemHeight', function() {
let itemSize = this.get('itemHeight');
let fullSize = this.get('items.length') * itemSize;
let initSize = this.get('initialSize');
let originalScrollHeight = this.get('originalScrollHeight');

if (fullSize <= itemSize) {
return itemSize;
let minSize = itemSize;

// no options found. only default option is preloaded
if (initSize < originalScrollHeight) {
minSize = Math.max(itemSize, initSize);
}

if (fullSize <= minSize) {
return minSize;
}
return Math.min(fullSize, this.get('initialSize'));

if (fullSize) {
return Math.min(fullSize, this.get('originalScrollHeight'));
}
return initSize;
}),

height: computed('size', 'horizontal', function() {
Expand Down Expand Up @@ -122,7 +135,14 @@ const VirtualRepeatComponent = VirtualEachComponent.extend({

run.scheduleOnce('afterRender', this, function() {
let element = this.$().get(0);
let initSize = this.get('horizontal') ? element.clientWidth : element.clientHeight;
let elemHeight = element.clientHeight;
this.originalScrollHeight = elemHeight;
// no options found. only default option is preloaded
if (this.$('.md-virtual-repeat-offsetter').get().length > 0
&& this.$('.md-virtual-repeat-offsetter').get(0).firstElementChild.children.length > 0) {
elemHeight = this.$('.md-virtual-repeat-offsetter').get(0).offsetHeight;
}
let initSize = this.get('horizontal') ? element.clientWidth : elemHeight;
this.set('initialSize', initSize);
});
},
Expand Down