showTooltip can display the title of link when it exceeds the max-width. The default value is false.
import React from 'react';
import { Anchor } from '@douyinfe/semi-ui';
() => {
const getContainer = () => {
return document.querySelector('window');
};
return (
<div>
<Anchor
showTooltip={true}
getContainer={getContainer}
targetOffset={60}
offsetTop={100}
>
<Anchor.Link href="#Show_Tooltip" title="Tooltip is a useful tool that displays the entire content when text is abbreviated." />
<Anchor.Link href="#Components" title="Components" />
<Anchor.Link href="#Design" title="Design" />
<Anchor.Link href="#Blocks" title="Blocks" />
<Anchor.Link href="#Theme" title="Theme" />
</Anchor>
</div>
);
};
Tooltip Position
You can change the Tooltip position with position property. It only works when showTooltip is true.
import React from 'react';
import { Anchor } from '@douyinfe/semi-ui';
() => {
const getContainer = () => {
return document.querySelector('window');
};
return (
<div>
<Anchor
showTooltip={true}
position={'right'}
getContainer={getContainer}
targetOffset={60}
offsetTop={100}
>
<Anchor.Link href="#Tooltip_Position" title="Tooltip is a useful tool that displays the entire content when text is abbreviated." />
<Anchor.Link href="#Components" title="Components" />
<Anchor.Link href="#Design" title="Design" />
<Anchor.Link href="#Blocks" title="Blocks" />
<Anchor.Link href="#Theme" title="Theme" />
</Anchor>
</div>
);
};
API Reference
Anchor
PROPERTIES
INSTRUCTIONS
TYPE
DEFAULT
VERSION
autoCollapse
Dynamically display child link
boolean
false
className
Class name
string
-
defaultAnchor
Default highlight anchor
string
-
getContainer
Scroll container
() => HTMLElement
window
maxHeight
max-height of Anchor
string | number
750px
maxWidth
max-width of Anchor
string | number
200px
offsetTop
Trigger the current link switch when the scrolling content reaches a specified offset from the top of the container
number
0
onChange
Change event
(currentLink, previousLink) => void
-
onClick
Click event
(event, currentLink) => void
-
position
Tooltip position,same as position property of Tooltip component
string
-
railTheme
Style of scroll rail,one of primary,tertiary,muted
string
primary
scrollMotion
Animation of scroll behavior
boolean
false
showTooltip
Toggle whether to show tooltip, if passed in as object: type,type of component to show tooltip, support Tooltip and Popover, the default is Tooltip; opts, properties that will be passed directly to the component. The object form setting is provided since version 2.36.0
Why didn't my link highlight and slide to follow?
Check whether you can scroll to the specified position by clicking the anchor:
No, it means there is a problem with the id. check whether the id exists in the document;
Yes, it may be that the scrolling container is not set correctly to ensure that the content of the document is wrapped in the scrolling container. The default scrolling container is window. If your container is a div of .my-container, you should set the scrolling container to this div.
import React from 'react';
import { Anchor } from '@douyinfe/semi-ui';
function App() {
const getContainer = () => {
return document.querySelector('.my-container');
};
return (
<Anchor
/* Other props */
getContainer={getContainer}
>
/* Links */
</Anchor>
)
}