Affix
Affix pins supporting actions or navigation to the viewport while the surrounding document continues to scroll.
@duskmoon-dev/components/affix 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.
Affix is most often configured through `offsetTop`, `offsetBottom`, `target`, `onChange`.
Renders children and toggles fixed state on target scroll
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 Affix from its package subpath, then render it with the core props.
import "@duskmoon-dev/components/styles.css";
import { Affix } from "@duskmoon-dev/components/affix";
export function Example() {
return (<Affix
onChange={(value) => console.log(value)}
>
DuskMoon Affix
</Affix>);
} Renders children and toggles fixed state on target scroll
test-backedAffix scenario from the component test coverage: renders children and toggles fixed state on target scroll.
import "@duskmoon-dev/components/styles.css";
import { Affix } from "@duskmoon-dev/components/affix";
export function AffixRendersChildrenAndTogglesDemo() {
return (<Affix
// Renders children and toggles fixed state on target scroll
onChange={(value) => console.log(value)}
>
DuskMoon Affix
</Affix>);
} Theme aware
Docs previews inherit the DuskMoon data-theme value. Use the header switch to compare light and dark rendering.
<div data-theme="sunshine">
<Affix
onChange={(value) => console.log(value)}
>
DuskMoon Affix
</Affix>
</div>
<div data-theme="moonlight">
<Affix
onChange={(value) => console.log(value)}
>
DuskMoon Affix
</Affix>
</div> API
The API reference below lists every parsed exported type or interface for Affix. Start with `offsetTop`, `offsetBottom`, `target`, `onChange` for common usage.
packages/components/src/components/affix/Affix.types.ts
Scenarios: packages/components/src/components/affix/Affix.test.tsx | Prop | Type | Required | Description |
|---|---|---|---|
offsetTop | number | No | offsetTop configures Affix. |
offsetBottom | number | No | offsetBottom configures Affix. |
target | () => Window | HTMLElement | null | No | target configures Affix. |
onChange | (affixed?: boolean) => void | No | onChange configures Affix. |
children | ReactNode | No | children configures Affix. |