LoadMore
Requests the next page of a feed with a button or infinite scroll, and announces what was added.
- Frameworks
- Astro · React · Elements · Dioxus
- Registry
lumen add LoadMore- Interaction
- Enhanced runtime
See it and copy it
Framework example
Choose Astro, React, Elements, or Dioxus to compare native usage against the shared visual output. Each example assumes the framework-level setup is already complete.
- Post 1
- Post 2
- Post 3
View LoadMore code
Framework usage
Switch targets to compare the adapter code. This live preview runs the Astro example. Before copying an example, complete the matching framework setup; React, Elements, and Dioxus use their own behavior APIs.Width controls resize the preview container. Resize your browser to test viewport breakpoints.---
import { LoadMore } from '@santi020k/lumen-astro'
---
<ul id="demo-load-more-feed">
<li>Post 1</li>
<li>Post 2</li>
<li>Post 3</li>
</ul>
<LoadMore
addedLabel={{ one: '{count} post added', other: '{count} posts added' }}
id="demo-load-more"
target="demo-load-more-feed"
/>
<script>
let page = 1
const appendPosts = (root: HTMLElement, feed: HTMLElement): void => {
for (let index = 1; index <= 3; index++) {
const item = document.createElement('li')
item.textContent = `Post ${page * 3 + index}`
feed.append(item)
}
page += 1
if (page >= 3) root.setAttribute('data-has-more', 'false')
root.removeAttribute('data-loading')
}
const root = document.getElementById('demo-load-more')
const feed = document.getElementById('demo-load-more-feed')
if (root && feed) {
root.addEventListener('ui:load-more', () => {
window.setTimeout(() => {
appendPosts(root, feed)
}, 600)
})
}
</script>'use client'
import { useEffect, useState } from 'react'
import { LoadMore } from '@santi020k/lumen-react'
const posts = Array.from({ length: 9 }, (_, index) => ({ id: index + 1, title: `Post ${index + 1}` }))
export function Example() {
const [visibleCount, setVisibleCount] = useState(3)
const [loading, setLoading] = useState(false)
useEffect(() => {
if (!loading) return
// Simulate loading the next page from this local sample.
const timeout = window.setTimeout(() => {
setVisibleCount(count => Math.min(count + 3, posts.length))
setLoading(false)
}, 600)
return () => window.clearTimeout(timeout)
}, [loading])
return (
<>
<ul id="posts-feed">
{posts.slice(0, visibleCount).map(post => <li key={post.id}>{post.title}</li>)}
</ul>
<LoadMore
addedLabel={{ one: '{count} post added', other: '{count} posts added' }}
hasMore={visibleCount < posts.length}
loading={loading}
onLoadMore={() => setLoading(true)}
target="posts-feed"
/>
</>
)
}<script type="module">
import { defineLumenElements } from '@santi020k/lumen-elements/define'
defineLumenElements()
</script>
<ul id="posts-feed"><li>Post 1</li><li>Post 2</li><li>Post 3</li></ul>
<lumen-load-more
added-label-one="{count} post added"
added-label-other="{count} posts added"
id="more-posts"
target="posts-feed"
></lumen-load-more>
<script type="module">
const root = document.getElementById('more-posts')
const feed = document.getElementById('posts-feed')
root?.addEventListener('ui:load-more', () => {
if (!feed) {
root.removeAttribute('loading')
root.setAttribute('error', 'The feed is unavailable.')
return
}
// Simulate loading the next page from this local sample.
window.setTimeout(() => {
for (let index = 0; index < 3; index += 1) {
const item = document.createElement('li')
item.textContent = `Post ${feed.children.length + 1}`
feed.append(item)
}
if (feed.children.length >= 9) root.setAttribute('has-more', 'false')
root.removeAttribute('loading')
}, 600)
})
</script>use dioxus::prelude::*;
use lumen_dioxus::prelude::*;
#[component]
fn Example() -> Element {
let mut items = use_signal(|| 10_u64);
rsx! {
ul { id: "feed",
for index in 0..items() {
li { key: "{index}", "Item {index}" }
}
}
LoadMore {
target: "feed",
item_count: items(),
has_more: items() < 30,
on_load_more: move |_| items += 10,
}
}
}Choose your target
Add this component
Choose the package for your runtime. All adapters share the Lumen stylesheet. Use the matching registry command when you want a local wrapper for that framework.
pnpm add @santi020k/lumen-astrolumen add LoadMorepnpm add @santi020k/lumen-reactlumen add LoadMore --target reactpnpm add @santi020k/lumen-elementslumen add LoadMore --target elementsAPI reference
Lumen-specific props and runtime attributes for the Astro primitive. Use the framework differences above and the copyable examples for React composition and Elements attributes; the public adapter types define their supported contracts.
| Attribute | Values | Default | Description |
|---|---|---|---|
| onLoadMore / ui:load-more | (detail: { retry: boolean }) => void | CustomEvent | - | Requests the next page. LoadMore never fetches: the consumer appends items, then updates loading, hasMore, and error. Astro and Elements set loading first and dispatch a bubbling, cancelable ui:load-more event on the root; canceling it leaves the state idle. |
| loading | boolean | false | Shows the loading copy and marks the root and target aria-busy. The button stays focusable with aria-disabled instead of disabled. Astro uses data-loading at runtime. |
| hasMore | boolean | true | Set to false when the feed ends: the button hides and the done message shows. Astro uses data-has-more="false"; Elements has-more="false". |
| error | boolean | string | false | Shows the error copy (or the string) and turns the button into a retry; the retry request reports retry: true. Automatic loading never retries. |
| target | string | - | Id of the feed container. Its children are counted to announce how many items were added and to focus the first new one. |
| auto | boolean | false | Infinite mode: requests when a sentinel nears the viewport through IntersectionObserver. The button remains as the fallback. |
| rootMargin | string | "0px 0px 200px 0px" | IntersectionObserver margin for auto. Elements use root-margin. |
| focusNewItems | boolean | false | Moves focus to the first new item after a load. Otherwise focus stays on the button, or moves to the done message when the button hides. |
| href | string | - | No-script fallback: renders the control as a link to the next page; with script the click is intercepted. Unsafe URLs fall back to a button. Astro and React only. |
| label / loadingLabel / retryLabel | string | "Load more" / "Loading…" / "Try again" | Button copy for idle, loading, and error. |
| errorLabel / doneLabel | string | "Could not load more items." / "No more items" | Message copy for error and the end of the feed. |
| addedLabel | string | { zero?, one?, two?, few?, many?, other? } | { one: "{count} item added", other: "{count} items added" } | Polite announcement after a load, pluralized with Intl.PluralRules. Elements use added-label and added-label-one, and so on. |
| loadedLabel | string | "More items loaded" | Announced after a load when there is no target to count. |
| locale | string | document language | Locale for plural rules and number formatting. |
| class, className | string | "" | Merges custom classes with the generated ui-* root classes. |
| ...native attributes | HTML attributes | - | Forwards standard attributes to the root element unless the component consumes them. |
Customize LoadMore
Start with semantic theme tokens and a class on the public component. Keep its accessible name, focus treatment, and interaction state intact.
.product-load-more {
--surface: 0 0% 100%;
--ink: 220 20% 15%;
--line: 220 15% 82%;
}Apply product-load-more through Astro's class, React's className, or the custom element's class. Verify foreground and background contrast in both schemes.
| Hook | Values | Default | Contract |
|---|---|---|---|
| class, className | string | "" | Merges custom classes with the generated ui-* root classes. |
Use the documented hooks above and adapter types when targeting component states. Theme guide · Accessibility verification scope
Keyboard interactions
Keyboard behavior provided by the Astro UIPrimitives runtime for this component.
| Key | Action |
|---|---|
| Enter, Space | Request more items, or retry after an error. Focus stays on the button while loading. |
| Tab | After a load with focusNewItems, focus starts at the first new item. |
Runtime events
CustomEvents dispatched by the Astro UIPrimitives runtime for this component.
| Event | Target | Detail | When |
|---|---|---|---|
| ui:load-more | LoadMore root ([data-ui-load-more]) | { retry: boolean } | The button is pressed, or the sentinel nears the viewport in auto mode. The root is already marked loading; append items, then clear data-loading and set data-has-more="false" or data-error. Call preventDefault to cancel the request. |