salla-infinite-scroll

Wraps a paginated list and loads the next page into it, either when the visitor clicks a "Load more" button that it adds after the list, or automatically on scroll.

Wraps a paginated list and loads the next page into it, either when the visitor clicks a "Load more" button that it adds after the list, or automatically on scroll. Use it around product, brand, order or comment lists that the server paginates. Set next-page to the URL of the next page; it shows a message when the end is reached and when loading fails.

Nothing is rendered when next-page is empty. The button is a link, so it can be reached and activated with the keyboard.

Use it

In HTML or JSX, use the tag <salla-infinite-scroll> with the Attribute names below. In React, the wrapper takes the Property names (camelCase).

import { SallaInfiniteScroll } from '@salla.sa/twilight-components-react/infinite-scroll';

Client-only. On the server this wrapper renders a placeholder (a skeleton, or nothing), and the real component mounts in the browser. Do not rely on it for content that search engines must see.

Example

import { SallaInfiniteScroll } from '@salla.sa/twilight-components-react/infinite-scroll';

export function Example() {
  return (
    <SallaInfiniteScroll nextPage="/products?page=2" autoload>
      <div className="product">Product 1</div>
      <div className="product">Product 2</div>
    </SallaInfiniteScroll>
  );
}

Properties

PropertyAttributeDescriptionTypeDefault
autoloadautoloadWhen true, the next page loads automatically as the visitor scrolls near the end of the list and the browser URL is updated for each loaded page. When false, only the "Load more" button loads more.booleanfalse
containercontainerCSS selector of the element that holds the list items, when it is not the <salla-infinite-scroll> element itself.string'salla-infinite-scroll'
itemitemCSS selector of the list items to take from each loaded page and append to the container.string'salla-infinite-scroll > *'
loadMoreTextload-more-textText of the "Load more" button. Falls back to the translated default.string
nextPagenext-pageURL of the next page of results. It should contain a page=N query parameter, which is replaced with the right page number on each load. When it no longer contains : or . the component treats the list as finished.string''

Slots

SlotDescription
(default)The list items already on the page. Items from later pages are appended after them.

On this page