Infinite Scroll
Container that fires a load event as the reader nears the bottom, with a loading spinner and an end-of-list state.
<arc-infinite-scroll>Overview
Infinite Scroll wraps your items and puts an Intersection Observer sentinel after them. When the sentinel comes within threshold pixels of the bottom of the viewport (200 by default), the component fires arc-load-more. Fetch the next batch and append it. A larger threshold asks for the next batch earlier. Changing it on a mounted component takes effect at once, and fires arc-load-more straight away if the sentinel is already inside the new distance.
Set loading to true while you fetch. A spinner shows in the footer, and no further arc-load-more fires until you set loading back to false.
When there's nothing left, set finished to true. The observer disconnects and the footer shows "No more items". The container sets aria-busy while loading. If your items are self-contained entries such as posts, slot them as <article> elements and add role="feed" to the component for the ARIA feed pattern.
Guidelines
Do
- Set `loading` to `true` as soon as you start fetching, and back to `false` when the data arrives
- Set `finished` when the API says there are no more pages
- Put it inside a scrollable parent, or let the page scroll
- Append new items as direct children. They render in the default slot
Don't
- Don't use it for small, fixed datasets. Use pagination or a plain list
- Don't put footer content below it without another way to reach it. The footer moves down every time items load
Features
- `disabled` disconnects the observer, blocks pointer events and dims the component to 50% opacity
- The observer reconnects when `finished` or `disabled` is set back to false
Preview
Usage
This component needs JavaScript. Use the Web Component or a framework wrapper.
<arc-infinite-scroll id="feed" threshold="200">
<!-- Items appended here -->
</arc-infinite-scroll>
<script>
const feed = document.getElementById('feed');
let page = 1;
feed.addEventListener('arc-load-more', async () => {
feed.loading = true;
const items = await fetchPage(page++);
items.forEach(item => feed.appendChild(createItemEl(item)));
feed.loading = false;
if (!items.length) feed.finished = true;
});
</script>import { InfiniteScroll } from '@arclux/arc-ui-react';
const [items, setItems] = useState(initialItems);
const [loading, setLoading] = useState(false);
const [finished, setFinished] = useState(false);
async function loadMore() {
setLoading(true);
const next = await fetchNextPage();
setItems(prev => [...prev, ...next]);
setLoading(false);
if (!next.length) setFinished(true);
}
<InfiniteScroll loading={loading} finished={finished} onArcLoadMore={loadMore}>
{items.map(item => <div key={item.id}>{item.name}</div>)}
</InfiniteScroll><script setup>
import { ref } from 'vue';
import { InfiniteScroll } from '@arclux/arc-ui-vue';
const items = ref(initialItems);
const loading = ref(false);
const finished = ref(false);
async function loadMore() {
loading.value = true;
const next = await fetchNextPage();
items.value.push(...next);
loading.value = false;
if (!next.length) finished.value = true;
}
</script>
<template>
<InfiniteScroll :loading="loading" :finished="finished" @arc-load-more="loadMore">
<div v-for="item in items" :key="item.id">{{ item.name }}</div>
</InfiniteScroll>
</template><script>
import { InfiniteScroll } from '@arclux/arc-ui-svelte';
let items = $state(initialItems);
let loading = $state(false);
let finished = $state(false);
async function loadMore() {
loading = true;
const next = await fetchNextPage();
items = [...items, ...next];
loading = false;
if (!next.length) finished = true;
}
</script>
<InfiniteScroll {loading} {finished} on:arc-load-more={loadMore}>
{#each items as item (item.id)}
<div>{item.name}</div>
{/each}
</InfiniteScroll>import { Component } from '@angular/core';
import { InfiniteScroll } from '@arclux/arc-ui-angular';
@Component({
imports: [InfiniteScroll],
template: `
<arc-infinite-scroll
[loading]="loading"
[finished]="finished"
(arc-load-more)="loadMore()"
>
<div *ngFor="let item of items">{{ item.name }}</div>
</arc-infinite-scroll>
`,
})
export class FeedComponent {
items = [];
loading = false;
finished = false;
async loadMore() {
this.loading = true;
const next = await this.fetchNextPage();
this.items.push(...next);
this.loading = false;
if (!next.length) this.finished = true;
}
}import { createSignal, For } from 'solid-js';
import { InfiniteScroll } from '@arclux/arc-ui-solid';
const [items, setItems] = createSignal(initialItems);
const [loading, setLoading] = createSignal(false);
const [finished, setFinished] = createSignal(false);
async function loadMore() {
setLoading(true);
const next = await fetchNextPage();
setItems(prev => [...prev, ...next]);
setLoading(false);
if (!next.length) setFinished(true);
}
<InfiniteScroll loading={loading()} finished={finished()} onArcLoadMore={loadMore}>
<For each={items()}>{item => <div>{item.name}</div>}</For>
</InfiniteScroll>import { useState } from 'preact/hooks';
import { InfiniteScroll } from '@arclux/arc-ui-preact';
const [items, setItems] = useState(initialItems);
const [loading, setLoading] = useState(false);
const [finished, setFinished] = useState(false);
async function loadMore() {
setLoading(true);
const next = await fetchNextPage();
setItems(prev => [...prev, ...next]);
setLoading(false);
if (!next.length) setFinished(true);
}
<InfiniteScroll loading={loading} finished={finished} onArcLoadMore={loadMore}>
{items.map(item => <div key={item.id}>{item.name}</div>)}
</InfiniteScroll>API
thresholdnumber200- How far below the bottom of the viewport, in pixels, the sentinel after the content can be when
arc-load-morefires. Defaults to 200. Read when the observer attaches and again whenever it changes. loadingbooleanfalse- When true, displays a spinner in the footer and suppresses additional
arc-load-moreevents. finishedbooleanfalse- When true, disconnects the observer and displays "No more items" text in the footer.
disabledbooleanfalse- Disables the component, disconnects the observer, and reduces opacity to 40%.
Events
arc-load-more- Fired when the scroll sentinel enters the viewport, signaling more content should load