Flutter docs
Default skin

Anchor

Hyperlinks to scroll on one page.

When to use

For displaying anchor hyperlinks on page and jumping between them.

Notes for developers

After version 4.24.0, Anchor was rewritten as a function component. Methods that obtain a ref and call internal instance methods are invalid.

Examples

Basic

The simplest usage.

Horizontal Anchor

Horizontally aligned anchors

Static Anchor

Do not change state when page is scrolling.

Customize the onClick event

Clicking on an anchor does not record history.

Customize the anchor highlight

Customize the anchor highlight.

Set Anchor scroll offset

Anchor target scroll to screen center.

Listening for anchor link change

Listening for anchor link change.

Replace href in history

Replace path in browser history, so back button returns to previous page instead of previous anchor item.

Custom semantic dom styling

You can customize the semantic dom style of Anchor by passing objects/functions through classNames and styles.

API

Anchor, Anchor.Link, and their props are exported from @ceebee/ui/client.

Anchor Props

PropertyDescriptionTypeDefaultVersion
affixFixed mode of Anchorboolean | Omit<AffixProps, 'offsetTop' | 'target' | 'children'>trueobject: 5.19.0
boundsBounding distance of anchor areanumber5—
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-—
getContainerScrolling container() => HTMLElement() => window—
getCurrentAnchorCustomize the anchor highlight(activeLink: string) => string-—
offsetTopPixels to offset from top when calculating position of scrollnumber0—
showInkInFixedWhether show ink-square when affix={false}booleanfalse—
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-—
targetOffsetAnchor scroll offset, default as offsetTop, examplenumber-—
onChangeListening for anchor link change(currentActiveLink: string) => void——
onClickSet the handler to handle click event(e: MouseEvent, link: object) => void-—
itemsData configuration option content, support nesting through children{ key, href, title, target, children }\[] see-5.1.0
directionSet Anchor directionvertical | horizontalvertical5.2.0
replaceReplace items' href in browser history instead of pushing itbooleanfalse5.7.0

AnchorItem

PropertyDescriptionTypeDefaultVersion
keyThe unique identifier of the Anchor Linkstring | number-—
hrefThe target of hyperlinkstring——
targetSpecifies where to display the linked URLstring——
titleThe content of hyperlinkReactNode——
childrenNested Anchor Link, Attention: This attribute does not support horizontal orientationAnchorItem\[]-—
replaceReplace item href in browser history instead of pushing itbooleanfalse5.7.0
targetOffsetCustomize scroll offset for this anchor link. It takes precedence over the targetOffset prop of the Anchor componentnumber-6.4.0

Link Props

PropertyDescriptionTypeDefaultVersion
hrefThe target of hyperlinkstring——
targetSpecifies where to display the linked URLstring——
titleThe content of hyperlinkReactNode——
targetOffsetCustomize scroll offset for this anchor link. It takes precedence over the targetOffset prop of the Anchor componentnumber-6.4.0