Components
Infinite Scroll
A sentinel-based list that loads more content when scrolled into view.
Installation
$ npx veil-ui@latest add infinite-scrollUsage
import { InfiniteScroll } from "@/components/ui/infinite-scroll";
<InfiniteScroll hasMore={hasMore} loading={loading} onLoadMore={loadMore}>
{items.map((item) => <Item key={item.id} {...item} />)}
</InfiniteScroll>;Examples
Basic
Activity item 1
Activity item 2
Activity item 3
Activity item 4
Activity item 5
Scroll for more content
End state
First result
Second result
No more results.
API reference
The package exports infinite-scroll along with its composable parts. It forwards standard attributes to its root element; see the examples above for the component-specific props.
Accessibility
- Touch targets are large enough to tap comfortably and keep visible focus rings for keyboard and switch users.
- Gesture interactions (swipe, pull to refresh) have visible button alternatives so they are not the only way to act.
- Sheets, drawers and dialogs follow the underlying accessible primitives for focus trapping and escape handling.
Vue and plain HTML
This component also ships for Vue (Reka UI) and plain HTML. Install it with npx veil-ui add infinite-scroll --framework vue or switch the framework in components.json.
<script setup lang="ts">
import { Loader2 } from "lucide-vue-next";
import { onBeforeUnmount, onMounted, ref, watch } from "vue";
import { cn } from "@/lib/utils";
const props = withDefaults(
defineProps<{
hasMore: boolean;
loading?: boolean;
loadingMessage?: string;
endMessage?: string;
class?: string;
}>(),
{
loading: false,
loadingMessage: "Loading more…",
endMessage: "You have reached the end.",
},
);
const emit = defineEmits<{ loadMore: [] }>();
const sentinel = ref<HTMLElement | null>(null);
let observer: IntersectionObserver | null = null;
function observe() {
observer?.disconnect();
observer = null;
if (!sentinel.value || !props.hasMore) return;
observer = new IntersectionObserver(
(entries) => {
if (entries[0]?.isIntersecting && !props.loading) emit("loadMore");
},
{ rootMargin: "120px" },
);
observer.observe(sentinel.value);
}
onMounted(observe);
watch(() => [props.hasMore, props.loading], observe);
onBeforeUnmount(() => observer?.disconnect());
</script>
<template>
<div data-slot="infinite-scroll" :class="cn('grid gap-3', props.class)">
<slot />
<div
ref="sentinel"
aria-live="polite"
class="flex min-h-10 items-center justify-center text-xs text-muted-foreground"
>
<span v-if="loading" class="flex items-center gap-2">
<Loader2 class="size-3.5 animate-spin" aria-hidden="true" />
{{ loadingMessage }}
</span>
<span v-else-if="hasMore" class="sr-only">Scroll for more content</span>
<template v-else>{{ endMessage }}</template>
</div>
</div>
</template>