BackTop
BackTop gives long pages a persistent return-to-top affordance.
@duskmoon-dev/components/back-top Usage
When to use
- Use it when users need to move between sections, pages, steps, or contextual actions.
- Expose current and disabled state so navigation remains clear to keyboard and screen-reader users.
Implementation notes
Features
Covers the route, section, step, or action-list patterns that help users move through an interface.
Shows selected, active, open, or current props where the component exposes them.
BackTop is most often configured through `visibilityHeight`, `target`.
Becomes visible after target scroll and scrolls target to top
Feature Demos
Feature demos are authored for the component page, then supplemented with behavior scenarios from the component test coverage.
Basic usage
Import the component stylesheet and BackTop from its package subpath, then render it with the core props.
import "@duskmoon-dev/components/styles.css";
import { BackTop } from "@duskmoon-dev/components/back-top";
export function Example() {
return (<BackTop visibilityHeight={0}>Back to top</BackTop>);
} Becomes visible after target scroll and scrolls target to top
test-backedBackTop scenario from the component test coverage: becomes visible after target scroll and scrolls target to top.
import "@duskmoon-dev/components/styles.css";
import { BackTop } from "@duskmoon-dev/components/back-top";
export function BackTopBecomesVisibleAfterTargetDemo() {
return (<BackTop visibilityHeight={0}>Back to top</BackTop>);
} Theme aware
Docs previews inherit the DuskMoon data-theme value. Use the header switch to compare light and dark rendering.
<div data-theme="sunshine">
<BackTop visibilityHeight={0}>Back to top</BackTop>
</div>
<div data-theme="moonlight">
<BackTop visibilityHeight={0}>Back to top</BackTop>
</div> API
The API reference below lists every parsed exported type or interface for BackTop. Start with `visibilityHeight`, `target` for common usage.
packages/components/src/components/back-top/BackTop.types.ts
Scenarios: packages/components/src/components/back-top/BackTop.test.tsx | Prop | Type | Required | Description |
|---|---|---|---|
visibilityHeight | number | No | visibilityHeight configures BackTop. |
target | () => Window | HTMLElement | null | No | target configures BackTop. |
children | ReactNode | No | children configures BackTop. |