feat(Anchor): fix getCurrentAnchor offset

This commit is contained in:
shaodahong 2019-08-04 14:32:31 +08:00 committed by shao
parent 554d8cb3e3
commit 32621cf41a

View File

@ -240,8 +240,11 @@ export default class Anchor extends React.Component<AnchorProps, AnchorState> {
return;
}
const { activeLink } = this.state;
const { offsetTop, bounds } = this.props;
const currentActiveLink = this.getCurrentAnchor(offsetTop, bounds);
const { offsetTop, bounds, targetOffset } = this.props;
const currentActiveLink = this.getCurrentAnchor(
targetOffset !== undefined ? targetOffset : offsetTop || 0,
bounds,
);
if (activeLink !== currentActiveLink) {
this.setState({
activeLink: currentActiveLink,