Skip to content
Merged
Show file tree
Hide file tree
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
18 changes: 12 additions & 6 deletions src/components/InfiniteLoading.vue
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,18 @@ export default {
getScrollParent(elm = this.$el) {
let result;

if (elm.tagName === 'BODY') {
result = window;
} else if (!this.forceUseInfiniteWrapper && ['scroll', 'auto'].indexOf(getComputedStyle(elm).overflowY) > -1) {
result = elm;
} else if (elm.hasAttribute('infinite-wrapper') || elm.hasAttribute('data-infinite-wrapper')) {
result = elm;
if (typeof this.forceUseInfiniteWrapper === 'string') {
result = elm.querySelector(this.forceUseInfiniteWrapper);
}

if (!result) {
if (elm.tagName === 'BODY') {
result = window;
} else if (!this.forceUseInfiniteWrapper && ['scroll', 'auto'].indexOf(getComputedStyle(elm).overflowY) > -1) {
result = elm;
} else if (elm.hasAttribute('infinite-wrapper') || elm.hasAttribute('data-infinite-wrapper')) {
result = elm;
}
}

return result || this.getScrollParent(elm.parentNode);
Expand Down
31 changes: 31 additions & 0 deletions test/unit/specs/InfiniteLoading.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,4 +566,35 @@ describe('vue-infinite-loading', () => {

vm.$mount('#app');
});

it('should find my forcible element as scroll wrapper when using `force-use-infinite-wrapper` as seletor', (done) => {
vm = new Vue(Object.assign({}, basicConfig, {
template: `
<div class="scroll">
<div style="overflow: auto;">
<div style="overflow: auto;">
<ul>
<li v-for="item in list" v-text="item"></li>
</ul>
<infinite-loading
:direction="direction"
@infinite="infiniteHandler"
ref="infiniteLoading"
force-use-infinite-wrapper=".scroll"
>
</infinite-loading>
</div>
</div>
</div>
`,
methods: {
infiniteHandler: function infiniteHandler() {
expect(this.$refs.infiniteLoading.scrollParent).to.equal(this.$el);
done();
},
},
}));

vm.$mount('#app');
});
});