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

InfiniteScroll: Skip trigger event on invisible element #17553

Merged
merged 2 commits into from
Oct 31, 2019
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
3 changes: 3 additions & 0 deletions packages/infinite-scroll/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ const handleScroll = function(cb) {

if (disabled) return;

const containerInfo = container.getBoundingClientRect();
if (!containerInfo.width && !containerInfo.height) return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里还有个和immediate属性有关的问题,如果一开始没撑满容器,并且是不可见的状态,当切换成可见状态后不会继续撑满容器,也就没有scroll,后面的事情也不会发生。


let shouldTrigger = false;

if (container === el) {
Expand Down
26 changes: 26 additions & 0 deletions test/unit/specs/infiniteScroll.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,31 @@ describe('InfiniteScroll', () => {
await wait();
expect(vm.$el.innerText.indexOf('2') > -1).to.be.true;
});

it('invisible element not trigger', async() => {
vm = createVue({
template: `
<div v-show="false">
<ul ref="scrollTarget" v-infinite-scroll="load" style="height: 300px;overflow: auto;">
<li v-for="i in count" style="display: flex;height: 50px;">{{ i }}</li>
</ul>
</div>
`,
data() {
return {
count: 0
};
},
methods: {
load() {
this.count += 2;
}
}
}, true);
vm.$refs.scrollTarget.scrollTop = 2000;
await wait();
expect(vm.$el.innerText.indexOf('2') > -1).to.be.false;
});

});