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: fix avoid event trigger when element invisible #16681

Closed
wants to merge 3 commits into from

Conversation

qingdengyue
Copy link
Contributor

Please make sure these boxes are checked before submitting your PR, thank you!

  • Make sure you follow Element's contributing guide (中文 | English | Español | Français).
  • Make sure you are merging your commits to dev branch.
  • Add some descriptions and refer relative issues for you PR.

@qingdengyue
Copy link
Contributor Author

#16673

@element-bot
Copy link
Member

Deploy preview for element ready!

Built with commit 9552815

https://deploy-preview-16681--element.netlify.com

@a631807682
Copy link
Contributor

a631807682 commented Jul 23, 2019

scroll event does not trigger after component visible.
When contents don't fill the container at first, InfiniteScroll can not do anything.
I think when component hidden, it should create a observer to watch it if visible, and then emit 'scroll' event to compute should trigger callback or not.

@qingdengyue
Copy link
Contributor Author

scroll event does not trigger after component visible.
When contents don't fill the container at first, InfiniteScroll can not do anything.
I think when component hidden, it should create a observer to watch it if visible, and then emit 'scroll' event to compute should trigger callback or not.

yeah. when the element is invisible,may be its parent element or self invisible. now when trigger scroll event,it will check the element visible status,if true ,go on ,if false,just return. the scroll event like a observer.

@a631807682
Copy link
Contributor

a631807682 commented Jul 23, 2019

scroll event does not trigger after component visible.
When contents don't fill the container at first, InfiniteScroll can not do anything.
I think when component hidden, it should create a observer to watch it if visible, and then emit 'scroll' event to compute should trigger callback or not.

yeah. when the element is invisible,may be its parent element or self invisible. now when trigger scroll event,it will check the element visible status,if true ,go on ,if false,just return. the scroll event like a observer.

yeah, but the problem is no scroll at first.
when component invisible, load will not trigger, and count equal 0. and then component visible, but count still equal 0, there are no scroll and we have no way to trgger it. unless dispatch event
like this this.$refs.table.$el.dispatchEvent(new CustomEvent('scroll')).

template

...
<ul v-infinite-scroll="load" style="height: 300px;overflow: auto;">
     <li v-for="i in count" style="display: flex;height: 50px;">{{ i }}</li>
</ul>
...

js

...
data() {
  return {
    count: 0
  }
}
...

@qingdengyue
Copy link
Contributor Author

scroll event does not trigger after component visible.
When contents don't fill the container at first, InfiniteScroll can not do anything.
I think when component hidden, it should create a observer to watch it if visible, and then emit 'scroll' event to compute should trigger callback or not.

yeah. when the element is invisible,may be its parent element or self invisible. now when trigger scroll event,it will check the element visible status,if true ,go on ,if false,just return. the scroll event like a observer.

yeah, but the problem is no scroll at first.
when component invisible, load will not trigger, and count equal 0. and then component visible, but count still equal 0, there are no scroll and we have no way to trgger it. unless dispatch event
like this this.$refs.table.$el.dispatchEvent(new CustomEvent('scroll')).

template

...
<ul v-infinite-scroll="load" style="height: 300px;overflow: auto;">
     <li v-for="i in count" style="display: flex;height: 50px;">{{ i }}</li>
</ul>
...

js

...
data() {
  return {
    count: 0
  }
}
...

v-infinite-scroll directive will bind the container's scroll event on inserted hooks. so if word is not correct.you can provider a reproduction link?

@a631807682
Copy link
Contributor

link

https://codepen.io/a631807682/pen/jgqqJy?editors=1011#0

i chang the link to //deploy-preview-16681--element.netlify.com/element-ui.4b9a2bf.js , is a way to provider a reproduction link?

setp

  1. click change visible button
  2. can not scroll ( contents don't fill the container what infinite-scroll-immediate do)

@qingdengyue

@ziyoung ziyoung assigned ziyoung and iamkun and unassigned ziyoung Jul 31, 2019
@ziyoung ziyoung added this to the 2.12.0 milestone Jul 31, 2019
@iamkun
Copy link
Member

iamkun commented Aug 28, 2019

link

https://codepen.io/a631807682/pen/jgqqJy?editors=1011#0

i chang the link to //deploy-preview-16681--element.netlify.com/element-ui.4b9a2bf.js , is a way to provider a reproduction link?

setp

  1. click change visible button
  2. can not scroll ( contents don't fill the container what infinite-scroll-immediate do)

@qingdengyue

@qingdengyue same problem to me, please check the link above

@iamkun iamkun modified the milestones: 2.12.0, 2.13.0 Aug 28, 2019
Copy link
Contributor

@a631807682 a631807682 left a comment

Choose a reason for hiding this comment

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

i suggest to create IntersectionObserver to watch element visible status when invisible, like this:

if (!isElementVisible(el) && !visibleObserver) {
	visibleObserver = new IntersectionObserver(onScroll);
	visibleObserver.observe(el);
}

ps: i am new to review, i chose to approved, but actually i wanted to choose request change and i don't know how to change it.

@stale
Copy link

stale bot commented Aug 28, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Aug 28, 2020
@stale stale bot closed this Sep 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants