Anchor
Anchor builds in-page navigation for long documentation or settings screens.
@duskmoon-dev/components/anchor 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.
Anchor is most often configured through `items`, `targetOffset`, `bounds`, `offsetTop`.
Renders nested item links and tracks active href on click
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 Anchor from its package subpath, then render it with the core props.
import "@duskmoon-dev/components/styles.css";
import { Anchor } from "@duskmoon-dev/components/anchor";
export function Example() {
return (<Anchor
affix={false}
showInkInFixed
items={[
{
href: "#intro",
title: "Intro",
children: [{ href: "#demos", title: "Demos" }]
}
]}
/>);
} Renders nested item links and tracks active href on click
test-backedAnchor scenario from the component test coverage: renders nested item links and tracks active href on click.
import "@duskmoon-dev/components/styles.css";
import { Anchor } from "@duskmoon-dev/components/anchor";
export function AnchorRendersNestedItemLinksDemo() {
return (<Anchor
affix={false}
showInkInFixed
items={[
{
href: "#intro",
title: "Intro",
children: [{ href: "#demos", title: "Demos" }]
}
]}
/>);
} Supports Anchor.Link children and hash changes
test-backedAnchor scenario from the component test coverage: supports anchor.link children and hash changes.
import "@duskmoon-dev/components/styles.css";
import { Anchor } from "@duskmoon-dev/components/anchor";
export function AnchorSupportsAnchorLinkChildrenDemo() {
return (<Anchor
affix={false}
showInkInFixed
items={[
{
href: "#intro",
title: "Intro",
children: [{ href: "#demos", title: "Demos" }]
}
]}
/>);
} Accepts nav props, className, ref, and getCurrentAnchor
test-backedAnchor scenario from the component test coverage: accepts nav props, classname, ref, and getcurrentanchor.
import "@duskmoon-dev/components/styles.css";
import { Anchor } from "@duskmoon-dev/components/anchor";
export function AnchorAcceptsNavPropsClassNameDemo() {
return (<Anchor
affix={false}
showInkInFixed
items={[
{
href: "#intro",
title: "Intro",
children: [{ href: "#demos", title: "Demos" }]
}
]}
/>);
} Theme aware
Docs previews inherit the DuskMoon data-theme value. Use the header switch to compare light and dark rendering.
<div data-theme="sunshine">
<Anchor
affix={false}
showInkInFixed
items={[
{
href: "#intro",
title: "Intro",
children: [{ href: "#demos", title: "Demos" }]
}
]}
/>
</div>
<div data-theme="moonlight">
<Anchor
affix={false}
showInkInFixed
items={[
{
href: "#intro",
title: "Intro",
children: [{ href: "#demos", title: "Demos" }]
}
]}
/>
</div> API
The API reference below lists every parsed exported type or interface for Anchor. Start with `items`, `targetOffset`, `bounds`, `offsetTop` for common usage.
packages/components/src/components/anchor/Anchor.types.ts
Scenarios: packages/components/src/components/anchor/Anchor.test.tsx | Prop | Type | Required | Description |
|---|---|---|---|
items | AnchorItem[] | No | items configures Anchor. |
targetOffset | number | No | targetOffset configures Anchor. |
bounds | number | No | bounds configures Anchor. |
offsetTop | number | No | offsetTop configures Anchor. |
getContainer | () => Window | HTMLElement | No | getContainer configures Anchor. |
getCurrentAnchor | (activeLink: string) => string | No | getCurrentAnchor configures Anchor. |
affix | boolean | No | affix configures Anchor. |
showInkInFixed | boolean | No | showInkInFixed configures Anchor. |
onClick | ( | No | onClick configures Anchor. |
event | MouseEvent<HTMLElement>, | Yes | event configures Anchor. |
link | { title: ReactNode; href: string }, | Yes | link configures Anchor. |
onChange | (currentActiveLink: string) => void | No | onChange configures Anchor. |
| Prop | Type | Required | Description |
|---|---|---|---|
key | string | No | key configures Anchor. |
href | string | Yes | href configures Anchor. |
title | ReactNode | Yes | title configures Anchor. |
target | string | No | target configures Anchor. |
children | AnchorItem[] | No | children configures Anchor. |
| Prop | Type | Required | Description |
|---|---|---|---|
href | string | Yes | href configures Anchor. |
title | ReactNode | Yes | title configures Anchor. |
target | string | No | target configures Anchor. |
children | ReactNode | No | children configures Anchor. |
onClick | ComponentProps<"a">["onClick"] | No | onClick configures Anchor. |
ForwardRefExoticComponent< AnchorLinkProps & RefAttributes<HTMLAnchorElement> > ForwardRefExoticComponent< AnchorProps & RefAttributes<HTMLElement> > & { Link: AnchorLinkComponent