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

feat(VInfiniteScroll): add reset method #20637

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

giftimie
Copy link

Description

When the VInfiniteScroll reaches the 'empty' state, it is not possible to get out of it without doing any tricks such as caching the done method.
Many users are using this component to paginate search results, and when a specific search returns zero items, the component will be stuck in the empty state

closes #20308
closes #19935

Markup:

<template>
  <v-app>
    <v-container>
      <v-infinite-scroll ref="infiniteScrollRef" height="300" side="end" @load="load">
        <template v-for="(item, index) in items" :key="index">
          <div :class="['px-2', index % 2 === 0 ? 'bg-grey-lighten-2' : '']">
            Item number {{ item }}
          </div>
        </template>
      </v-infinite-scroll>
      <v-btn @click="reset">Call reset</v-btn>
    </v-container>
  </v-app>
</template>

<script setup>
  import { ref } from 'vue'
  const infiniteScrollRef = ref(null)

  const items = ref([])

  function reset() {
    items.value = []
    infiniteScrollRef.value.reset()
  }

  function load({ side, done }) {
    setTimeout(() => {
      if (items.value.length >= 40) {
        done('empty')
        return
      }

      const arr = Array.from({ length: 10 }, (k, v) => (items.value.at(-1) ?? 0) + 1 + v)
      items.value = [...items.value, ...arr]

      done('ok')
    }, 1000)
  }
</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants