From ec33f75bc052052987abe8870188f6b61e7b847d Mon Sep 17 00:00:00 2001 From: Amumu Date: Sun, 19 Mar 2023 23:20:16 +0800 Subject: [PATCH] chore: code style improve (#41335) --- components/anchor/Anchor.tsx | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) 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',