diff --git a/components/anchor/Anchor.tsx b/components/anchor/Anchor.tsx index aea64ec6f1..f5eabbb238 100644 --- a/components/anchor/Anchor.tsx +++ b/components/anchor/Anchor.tsx @@ -174,14 +174,12 @@ const AnchorContent: React.FC = (props) => { ); if (linkNode && spanLinkNode.current) { const { style: inkStyle } = spanLinkNode.current; - inkStyle.top = - anchorDirection !== 'horizontal' - ? `${linkNode.offsetTop + linkNode.clientHeight / 2}px` - : ''; - inkStyle.height = anchorDirection !== 'horizontal' ? `${linkNode.clientHeight}px` : ''; - inkStyle.left = anchorDirection === 'horizontal' ? `${linkNode.offsetLeft}px` : ''; - inkStyle.width = anchorDirection === 'horizontal' ? `${linkNode.clientWidth}px` : ''; - if (anchorDirection === 'horizontal') { + const horizontalAnchor = anchorDirection === 'horizontal'; + inkStyle.top = horizontalAnchor ? '' : `${linkNode.offsetTop + linkNode.clientHeight / 2}px`; + inkStyle.height = horizontalAnchor ? '' : `${linkNode.clientHeight}px`; + inkStyle.left = horizontalAnchor ? `${linkNode.offsetLeft}px` : ''; + inkStyle.width = horizontalAnchor ? `${linkNode.clientWidth}px` : ''; + if (horizontalAnchor) { scrollIntoView(linkNode, { scrollMode: 'if-needed', block: 'nearest',