# `LedgerUI.Components.Scrollspy`
[🔗](https://github.com/devaction-labs/ledger_ui/blob/v0.2.0/lib/ledger_ui/components/scrollspy.ex#L1)

A list of links to the sections of the page that marks the section in view.

    <.scrollspy id="settings-nav" offset={96}>
      <:item href="#profile">Profile</:item>
      <:item href="#security">Security</:item>
    </.scrollspy>

The hook `LedgerUI.Scrollspy` (`priv/static/ledger_ui/hooks/scrollspy.js`) watches the elements
the links point at and moves `aria-current="true"` (and the class `on`) to the link of the
section at the top of the view (`offset` pixels from the top, 120 by default). A click scrolls
to the section smoothly (instantly with `prefers-reduced-motion`).

The server renders `aria-current="true"` on an item whose `class` includes `on` (the initial
state); the hook only updates it as the page scrolls.

The root is a `<nav>` (the design's `lu-spy nav`); wrap it in a `lu-spy` grid yourself.
`label: nil` omits the `aria-label`.

# `scrollspy`

## Attributes

* `id` (`:string`) (required)
* `label` (`:any`) - Defaults to `"On this page"`.
* `offset` (`:integer`) - Defaults to `120`.
* `target` (`:string`) - A selector (`"#doc"`) of the element that scrolls the sections, when it is not the page. Defaults to `nil`.
* `class` (`:any`) - Defaults to `nil`.
* Global attributes are accepted.
## Slots

* `item` (required) - Accepts attributes:

  * `href` (`:string`)
  * `class` (`:any`)
  * `style` (`:string`)
  * `id` (`:string`)

---

*Consult [api-reference.md](api-reference.md) for complete listing*
