Overview
Scroll More fits long content into a set height or width. The wrapper is nds-scroll-more, and the part that scrolls is nds-scroll-more-content. When the content does not fit, its edges fade, and an optional nds-show-more button moves it on one page at a time. The script finds the scroll direction by itself.
Pick another component when:
- the items are tabs: Tabs, which scroll their own tab row
- a “Show all” button is enough and paging is not needed: Expandable Content
- the content is a menu with levels: Drawer
Markup
- Riyadh
- Jeddah
- Makkah
- Madinah
- Dammam
- Khobar
- Taif
- Tabuk
- Abha
- Buraydah
- Khamis Mushait
- Hail
Variants
Every row goes on the wrapper. The wrapper fits its content, but never grows wider than its container, so a wide row scrolls. A list scrolls only once its height is limited: nds-fit gives it the height of its parent, or 240px.
| Group | Option | Markup | On element | Use |
|---|---|---|---|---|
| Structure | Vertical list (default) | — | — | A list with nds-fit, 240px tall when alone. The button stands under it |
| Structure | Horizontal row | canon #sm-row |
— | A row of buttons or chips, as wide as its container. The button stands at the row’s end, as an arrow with no label |
| Structure | Card track | canon #sm-cards |
— | A row of cards wider than its container. The wrapper stops at the container’s width, and the cards scroll inside it |
| Structure | Fit (hint: A list that fills the height of its row) | canon #sm-grid |
— | A vertical list with nds-fit, in a card beside a taller card. The list fills its card and scrolls in that height |
| Divided | Divided | .nds-divided |
.nds-scroll-more |
A hairline between the content and the button, shown while the content overflows |
| Snap | Snap (hint: Each click and drag stops at the start of an item) | .nds-snap |
.nds-scroll-more |
Each item’s start snaps to the edge of the scrolling area |
| Gap | Gap | --scroll-gap: var(--spacing-md) |
.nds-scroll-more |
Space between the content and the button. With Divided, the hairline sits in the gap |
Built-in Features
-
Auto-initialization
Every
.nds-scroll-moreon the page starts by itself. The overflow check, the scroll listener and the button need no call. -
Axis Auto-detection
The script measures both directions and scrolls the one that overflows. When both do, it scrolls vertically.
-
Edge Fade Mask
An edge fades only while more content lies past it, so there is no fade at the very start or the very end.
-
Item-aware Step
Each click moves one page minus one item, so the last item stays in view as an anchor. The first item's size sets the step.
-
Loop to Start
At the end, the button's arrow flips, and the next click scrolls back to the start.
-
Reactive to Layout
The script checks the overflow again when the content area changes size, so the button shows and hides as needed.
-
Free-scroll Friendly
Touch, trackpad and mouse-wheel scrolling work as usual. The scroll listener is passive and runs at most once a frame.
-
Keyboard Scroll
Content that scrolls and holds no link or control gets
tabindex="0", so a keyboard user can tab to it and scroll it with the arrow keys. Atabindexin your markup stays as written. -
Programmatic Control
Start a new wrapper, check the overflow again or remove the behavior through
NDS.ScrollMore.
Best Practices
- Use Scroll More to fit a long list, a row of chips or a card track into a set area, with every item still in reach.
- Give a vertical list a height limit:
nds-fit,--scroll-max-height, or a flex or grid parent with a set height. Without one, the list never overflows and the button never shows. A plain block parent with a set height does not hold the list: it grows past it. - For another height, set
--scroll-max-heightin your own stylesheet, not in astyleattribute: a strict Content Security Policy blocks inline styles. - In a card beside a taller card, add
nds-fit, so the list fills its card. - Keep the items the same size when you want even paging. The first item sets the step.
- Keep the visible “Show more” label on the button. It names the button for screen readers.
- Add
nds-snapto a card track, so each click stops at the start of a card. - When items have borders or shadows that the edge clips, add inline padding to
.nds-scroll-more-content.
API
Classes
| Class | Element | Effect |
|---|---|---|
nds-fit |
A vertical .nds-scroll-more |
Fills the height its parent gives it, and the items scroll in that height: a grid cell, a flex row, or a card beside a taller card. The parent must be a grid or a flex container. In a card, put the title in .nds-card-header: a .nds-card-text beside the list grows too and takes part of the height. With no height from the parent, such as stacked cards on a phone, the list takes --scroll-max-height. Not for a row or a card track: they already fill their container’s width |
Data Attributes
The script writes these on the wrapper. Read them in your own CSS or script. Do not set them.
| Attribute | Element | Effect |
|---|---|---|
data-axis |
.nds-scroll-more |
vertical or horizontal: the direction that overflows. Removed when nothing overflows |
data-state |
.nds-scroll-more |
has-more while the content overflows, at-start at the start of the scroll and at-end at the end. They drive the fade and the direction of the button’s arrow |
CSS Custom Properties
Set these on the wrapper.
| Property | Default | Controls |
|---|---|---|
--scroll-max-height |
none |
Height limit of the wrapper, for vertical overflow. With nds-fit it is the least height, 240px when unset: the list grows past it to fill its parent |
--scroll-max-width |
100% |
Width limit of the wrapper, for horizontal overflow. The wrapper never grows past its container, whatever the value |
--scroll-fade |
16px |
Length of the edge fade |
--scroll-gap |
0 |
Space between the content and the button |
--scroll-divider |
var(--divider-color) |
Color of the nds-divided hairline |
--scroll-padding |
var(--spacing-xs) |
Space at the end of the scroll, so the last item’s border and focus ring are not clipped. The start stays flush. Set 0 to remove it |
Tokens
It reads these shared tokens. A change to one also changes other components: see Tokens.
Source: the var() reads in _sass/components/_scroll-more.scss.
| Token | Preview | Value |
|---|---|---|
--divider-colorRead by --scroll-divider | var(--colors-alpha-black-10)Dark mode var(--colors-alpha-white-10) |
JavaScript
| Method | Effect |
|---|---|
NDS.ScrollMore.init() |
Starts every .nds-scroll-more on the page that has not started yet |
NDS.ScrollMore.create(wrapper) |
Starts one wrapper. It does nothing on a wrapper that has started |
NDS.ScrollMore.refresh(wrapper) |
Checks the overflow again. Call it after you add or remove items while the wrapper keeps its size |
NDS.ScrollMore.destroy(wrapper) |
Removes the listeners, the divider it built, data-axis and the overflow states. Call it before you remove the wrapper |
The full API is in the banner of _js/nds-scroll-more.js.