Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Anchor): add customScroll API to support custom scroll behavior #4386

Merged
merged 8 commits into from
Nov 19, 2024
5 changes: 5 additions & 0 deletions src/anchor/anchor-item-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ export default {
type: [String, Function] as PropType<TdAnchorItemProps['title']>,
default: '',
},
/** 禁用点击锚点链接后自动滚动到目标元素,滚动行为由用户或浏览器处理(如scroll-behavior: smooth) */
disableScroll: {
type: Boolean,
default: false,
},
};
2 changes: 1 addition & 1 deletion src/anchor/anchor-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default defineComponent({
};
const handleClick = (e: MouseEvent) => {
const { href, title } = props;
anchor.handleScrollTo(href);
if (!props.disableScroll) anchor.handleScrollTo(href);
anchor.handleLinkClick({ href, title: isString(title) ? title : undefined, e });
};
const renderTitle = () => {
Expand Down
1 change: 1 addition & 0 deletions src/anchor/anchor.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ click | `(link: { href: string; title: string; e: MouseEvent })` | 锚点被点
href | String | - | 必需。锚点链接, 如果是 hash 模式需要加上当前 path | Y
target | String | _self | 锚点文本。可选项:_self/_blank/_parent/_top | N
title | String / Slot / Function | '' | 锚点文本。TS 类型:`string \| TNode`。[通用类型定义](https://github.com/Tencent/tdesign-vue-next/blob/develop/src/common.ts) | N
disableScroll | Boolean | false | 禁用点击锚点链接后自动滚动到目标元素,滚动行为由用户或浏览器处理(如scroll-behavior: smooth)

### AnchorTarget Props

Expand Down
5 changes: 5 additions & 0 deletions src/anchor/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,9 @@ export interface TdAnchorItemProps {
* @default ''
*/
title?: string | TNode;
/**
* 禁用点击锚点链接后自动滚动到目标元素,滚动行为由用户或浏览器处理(如scroll-behavior: smooth)
* @default false
*/
disableScroll?: boolean;
}
Loading