Skip to main content
239

Search Lumen

Find components, APIs, guides, and recipes.

GitHub
Themes
Web docs
Navigation

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
01

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.

AstroCode target · live preview uses Astro
  • 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.
astro
---
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>
Edit LoadMore in browser
02

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.

bash@santi020k/lumen-astro
pnpm add @santi020k/lumen-astro
bashAstro wrapper
lumen add LoadMore

API 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.

AttributeValuesDefaultDescription
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.
loadingbooleanfalseShows 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.
hasMorebooleantrueSet to false when the feed ends: the button hides and the done message shows. Astro uses data-has-more="false"; Elements has-more="false".
errorboolean | stringfalseShows the error copy (or the string) and turns the button into a retry; the retry request reports retry: true. Automatic loading never retries.
targetstring-Id of the feed container. Its children are counted to announce how many items were added and to focus the first new one.
autobooleanfalseInfinite mode: requests when a sentinel nears the viewport through IntersectionObserver. The button remains as the fallback.
rootMarginstring"0px 0px 200px 0px"IntersectionObserver margin for auto. Elements use root-margin.
focusNewItemsbooleanfalseMoves 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.
hrefstring-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 / retryLabelstring"Load more" / "Loading…" / "Try again"Button copy for idle, loading, and error.
errorLabel / doneLabelstring"Could not load more items." / "No more items"Message copy for error and the end of the feed.
addedLabelstring | { 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.
loadedLabelstring"More items loaded"Announced after a load when there is no target to count.
localestringdocument languageLocale for plural rules and number formatting.
class, classNamestring""Merges custom classes with the generated ui-* root classes.
...native attributesHTML 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.

cssScoped theme overrides
.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.

HookValuesDefaultContract
class, classNamestring""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.

KeyAction
Enter, SpaceRequest more items, or retry after an error. Focus stays on the button while loading.
TabAfter a load with focusNewItems, focus starts at the first new item.

Runtime events

CustomEvents dispatched by the Astro UIPrimitives runtime for this component.

EventTargetDetailWhen
ui:load-moreLoadMore 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.

Web docsFull catalog