Skip to content
synccn

Back to Top

New

Appears after scrolling, with a progress ring.

Scroll down in this panel

Installation

$ pnpm dlx shadcn@latest add @synccn/back-to-top

First time in this project? Connect synccn with one command.

Usage

import { BackToTop } from "@/components/ui/nav-extras";<BackToTop />

API reference

Generated from the component's TypeScript types, so it always matches the code.

BackToTop

Appears after scrolling down; scrolls back to the top. Pass a container ref, or it watches the window.

  • target
    React.RefObject<HTMLElement | null>

    Scroll container to watch. Defaults to the page.

  • threshold
    number

    Default 300

    Pixels scrolled before the button appears.

  • className
    string

    Extra classes for the root element.

Dependencies

Read from the component's imports when the site builds. The CLI installs all of these for you.

Helpers

  • lib/utilscn (merges class names)
  • lib/hooksuseClickOutside (closes on an outside click), useEscape (closes on Escape)

npm packages

Accessibility

From the source

Read from this component's code when the site builds, so it can't drift.

  • ARIA attributes: aria-current, aria-expanded, aria-hidden, aria-label
  • Closes with Escape
  • Closes when you click or tap outside