Load More
Shows the first few items of a long list and adds the rest on demand: one batch per press, everything at once with a way back, or on its own as the reader scrolls. A height clamp with a faded edge covers content that isn't a list of items.
Try it yourself. This one is live, and its code is right below.
Showing 4 of 20
Installation#
Usage#
The preview is yours to explore. Its code comes with a Pro license, paid once and used in every project.
Have a license? Unlock it here
Anatomy#
import {
LoadMore,
LoadMoreList,
LoadMoreContent,
LoadMoreStatus,
LoadMoreTrigger,
LoadMoreSentinel,
LoadMoreLoader,
LoadMoreEnd,
} from "@/components/ui/load-more"
// Count mode
<LoadMore total={…} initial={…} step={…}>
<LoadMoreList>…</LoadMoreList>
<LoadMoreSentinel />
<LoadMoreLoader />
<LoadMoreStatus />
<LoadMoreTrigger more="…" less="…" />
<LoadMoreEnd>…</LoadMoreEnd>
</LoadMore>
// Height mode
<LoadMore collapsedHeight="…">
<LoadMoreContent>…</LoadMoreContent>
<LoadMoreTrigger more="…" less="…" />
</LoadMore>Load more#
The plainest form: each press adds the next step items and the list stays open. Without less the button leaves once the last item is in, and LoadMoreEnd closes the list in its place.
Show more, show less#
Set step to the total and pass less: one press reveals everything, and the same button rolls to "Show less" and folds the list back to initial. The page scrolls with the fold, so the button stays under the pointer instead of being left far below.
Batches#
initial and step are independent: here four photos show and every press brings eight more, until all twenty are in. LoadMoreStatus keeps count in tabular figures, and with less the last press turns the button into the way back.
Showing 4 of 20
Infinite scroll#
Add LoadMoreSentinel after the list and batches load on their own as it comes within rootMargin of the scroller's edge. onLoadMore returns the fetch, and LoadMoreLoader shows while it runs. After maxAutoLoads automatic loads the sentinel stops and LoadMoreTrigger appears, so whatever sits below the list can still be reached; a failed fetch hands over to the button the same way.
Height clamp#
For content that isn't a list of items (an FAQ, a catalog grid, a long page section), leave out total and wrap it in LoadMoreContent: the region is clamped to collapsedHeight, its cut edge fades, and the button reveals the rest with a height transition.
Collapsed height#
collapsedHeight sets how much shows before the reveal. Pick a value that cuts through a row rather than landing between two: a clean break reads as the end of the list, which is the opposite of the message you want. The default is 28rem.
Alignment#
align moves the button, status, loader and end line: center (the default, which reads as a page-level affordance), start, or end. The button's row is always in flow, never floated over the fade, so opening costs no layout shift of its own.
Any surface#
The cut edge fades through the fade-b mask utility rather than a background-coloured gradient panel, so it needs to know nothing about what sits behind it. The same component on a solid brand band cuts correctly with no configuration. With tone="onMedia" the trigger becomes the white chip: on a band it is the only action on the fill, so it takes the light shape.
Without the fade#
fade={false} keeps the region opaque to the last pixel. Reach for it when a soft edge would misread as "this text trails off": a legal notice, a price list, a data table.
Open by default#
defaultExpanded opens the clamp on mount, for a deep link that should land on the full list. Pair it with onExpandedChange to react to each toggle.
API reference#
LoadMore
The root. Passing total, hasMore or onLoadMore puts it in count mode, which reveals items in batches through LoadMoreList; without them it is a height clamp around LoadMoreContent. Renders a <div>, forwards its props, and announces each new batch through a polite live region. Every part accepts className, merged last.
| Prop | Type | Default | Description |
|---|---|---|---|
| total | number | - | Count mode: how many items exist. Drives hasMore and the status line. |
| initial | number | 6 | Count mode: how many items show before the first load, and where "Show less" returns to. |
| step | number | initial | Count mode: how many items each load adds. Set it to total for a one-press reveal. |
| onLoadMore | ({ count, step }) => void | Promise<unknown> | - | Called before each batch. Return a promise to fetch: the trigger shows a spinner (or LoadMoreLoader shows, for automatic loads) and the batch appears when it resolves. A rejection keeps the count and hands control back to the button. |
| hasMore | boolean | - | Count mode with an unknown total, e.g. cursor pagination. Overrides the count < total check. |
| collapsedHeight | string | "28rem" | Height mode: the clamp, any CSS length. Pick one that cuts through a row, so the fade reads as more below. |
| defaultExpanded | boolean | false | Height mode: start revealed. |
| onExpandedChange | (expanded: boolean) => void | - | Called when the region opens or closes; in count mode, when the last batch lands and when it folds back. |
| align | "center" | "start" | "end" | "center" | Where the trigger, status, loader and end line sit. |
| Data attribute | Description |
|---|---|
| data-mode | count or height. |
| aria-busy | Present while a fetch from onLoadMore is pending. |
LoadMoreList
Count mode: renders the first count of its children. Pass the items straight in (a mapped array, not wrapped in a fragment). The list opens to fit each batch the way an accordion does, the new items fade in together, and the first of them takes focus after a press.
| Data attribute | Description |
|---|---|
| data-expanded | Present once every item is showing. |
LoadMoreStatus
The count line, "Showing 12 of 48", in tabular figures so it never jiggles. Renders a <p>.
| Prop | Type | Default | Description |
|---|---|---|---|
| children | (shown: number, total?: number) => React.ReactNode | - | Replace the wording. Defaults to the loadMoreStatus label. |
LoadMoreTrigger
The button. Its icon follows what a press does: a button that adds a batch (count mode, no less) leads with a spinning loader ring; a button that reveals and folds back (less, or height mode) ends with a caret that turns over. Wires aria-expanded and aria-controls, keeps focus through a fetch (it never disables), and steps aside while a sentinel loads on its own. Forwards Button props, children aside.
| Prop | Type | Default | Description |
|---|---|---|---|
| more | React.ReactNode | "Load more" | Label while there is more to show. Name what is below, e.g. "Older releases". |
| less | React.ReactNode | - | Label once everything shows. Pass it to fold back to the start; leave it out and the button leaves when the list is complete. |
| variant | ButtonProps["variant"] | "outline" | Defaults to secondary, the solid chip, under an onMedia or onInverse tone. |
LoadMoreSentinel
Infinite scroll: an invisible line after the list, watched by an IntersectionObserver rooted on the nearest scroll container (the viewport when there is none). Each time it comes within reach, the next batch loads.
| Prop | Type | Default | Description |
|---|---|---|---|
| rootMargin | string | "0px 0px 240px 0px" | How far ahead to start loading. A bottom margin loads before the reader hits the end. |
| threshold | number | number[] | 0 | How much of the sentinel must be in view. Leave at 0 for a 1px line. |
| maxAutoLoads | number | Infinity | Automatic loads before the button takes over, so a footer below stays reachable. |
LoadMoreLoader
Shows while an automatic load is fetching. Defaults to a spinner and the loadingMore label; pass children to replace them.
LoadMoreContent
Height mode: the clamped region; put the long grid or list straight inside. Forwards native <div> props.
| Prop | Type | Default | Description |
|---|---|---|---|
| fade | boolean | true | Dissolves the cut edge while collapsed. Skipped when the content already fits. |
| Data attribute | Description |
|---|---|
| data-expanded | Present while the region is revealed. |
| CSS variable | Description |
|---|---|
| --fade-size | Depth of the dissolve, min(16rem, 40%) here. Override per instance, e.g. [--fade-size:6rem]. |
LoadMoreEnd
Count mode: a closing line once every item has loaded, rendered only if the reader loaded at least once. Defaults to the loadMoreEnd label.