Browse Source

refactor: anchor

pull/4134/head
tangjinzhou 4 years ago
parent
commit
de4693c321
  1. 5
      components/anchor/Anchor.tsx
  2. 11
      components/anchor/AnchorLink.tsx

5
components/anchor/Anchor.tsx

@ -78,7 +78,7 @@ export default defineComponent({
inheritAttrs: false,
props: anchorProps,
emits: ['change', 'click'],
setup(props, { emit, attrs, slots }) {
setup(props, { emit, attrs, slots, expose }) {
const { prefixCls, getTargetContainer, direction } = useConfigInject('anchor', props);
const inkNodeRef = ref();
const anchorRef = ref();
@ -159,6 +159,9 @@ export default defineComponent({
getContainer,
});
};
expose({
scrollTo: handleScrollTo,
});
const handleScroll = () => {
if (state.animating) {
return;

11
components/anchor/AnchorLink.tsx

@ -12,9 +12,6 @@ import classNames from '../_util/classNames';
import useConfigInject from '../_util/hooks/useConfigInject';
import { useInjectAnchor } from './context';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function noop(..._any: any[]): any {}
const anchorLinkProps = {
prefixCls: PropTypes.string,
href: PropTypes.string.def('#'),
@ -27,7 +24,9 @@ export type AnchorLinkProps = Partial<ExtractPropTypes<typeof anchorLinkProps>>;
export default defineComponent({
name: 'AAnchorLink',
props: anchorLinkProps,
slots: ['title'],
setup(props, { slots }) {
let mergedTitle = null;
const {
handleClick: contextHandleClick,
scrollTo,
@ -38,9 +37,8 @@ export default defineComponent({
const { prefixCls } = useConfigInject('anchor', props);
const handleClick = (e: Event) => {
// antAnchor.scrollTo(props.href);
const { href, title } = props;
contextHandleClick(e, { title, href });
const { href } = props;
contextHandleClick(e, { title: mergedTitle, href });
scrollTo(href);
};
@ -66,6 +64,7 @@ export default defineComponent({
const { href, target } = props;
const pre = prefixCls.value;
const title = getPropsSlot(slots, props, 'title');
mergedTitle = title;
const active = activeLink.value === href;
const wrapperClassName = classNames(`${pre}-link`, {
[`${pre}-link-active`]: active,

Loading…
Cancel
Save