nook
Browse the docs

Components

Back to top

Native

Return to a named heading, with reduced-motion-aware scrolling and focus restoration.

See the prompt

November release notes

Search now includes archived projects, approval requests stay together, and your weekly digest arrives at the time you choose.

Thanks to every team that shared feedback during the preview. Your existing workspace settings carry over automatically.

Installation

npx nook-ui@latest add back-to-top

Prompt

Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.

Short. For assistants that can run commands in your project.

Plain text
Add the Nook "Back to top" component to this project, exactly as Nook ships it.

Return to a named heading, with reduced-motion-aware scrolling and focus restoration.

Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add back-to-top`. It writes `components/ui/back-to-top.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/back-to-top.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:

```tsx
import { BackToTop } from "@/components/ui/back-to-top";
export default function Example() {
  return (
    <div className="grid w-full max-w-md gap-4">
      <h3
        id="release-start"
        tabIndex={-1}
        className="font-semibold outline-0 focus-visible:outline-2 focus-visible:outline-ring"
      >
        November release notes
      </h3>
      <p className="text-sm text-muted-foreground">
        Search now includes archived projects, approval requests stay together,
        and your weekly digest arrives at the time you choose.
      </p>
      <p className="text-sm text-muted-foreground">
        Thanks to every team that shared feedback during the preview. Your
        existing workspace settings carry over automatically.
      </p>
      <BackToTop targetId="release-start" className="justify-self-start" />
    </div>
  );
}
```

API
- `BackToTop`: Return to a named heading, with reduced-motion-aware scrolling and focus restoration.
  - `targetId` (`string`): ID of the heading or landmark to focus.
  - `threshold` (`number`, default 0): Scroll distance before the control appears.

Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: A real button scrolls to and focuses its target; reduced motion uses instant scrolling.

Done when the component renders like the example in light and dark mode and the project type-checks.

Usage

import { BackToTop } from "@/components/ui/back-to-top";
export default function Example() {
  return (
    <div className="grid w-full max-w-md gap-4">
      <h3
        id="release-start"
        tabIndex={-1}
        className="font-semibold outline-0 focus-visible:outline-2 focus-visible:outline-ring"
      >
        November release notes
      </h3>
      <p className="text-sm text-muted-foreground">
        Search now includes archived projects, approval requests stay together,
        and your weekly digest arrives at the time you choose.
      </p>
      <p className="text-sm text-muted-foreground">
        Thanks to every team that shared feedback during the preview. Your
        existing workspace settings carry over automatically.
      </p>
      <BackToTop targetId="release-start" className="justify-self-start" />
    </div>
  );
}

Examples

Custom label

Frequently asked questions

Can I change my plan later? Yes, any time from Settings, Billing.

Props

BackToTop

Return to a named heading, with reduced-motion-aware scrolling and focus restoration.

PropTypeDefaultDescription
targetIdstring–ID of the heading or landmark to focus.
thresholdnumber0Scroll distance before the control appears.

Accessibility

A real button scrolls to and focuses its target; reduced motion uses instant scrolling.

Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.