mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-02 03:59:01 +08:00
parent
ff41bfe2fb
commit
4668bf6ddd
@ -1,5 +1,6 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import * as PropTypes from 'prop-types';
|
import * as PropTypes from 'prop-types';
|
||||||
|
import { polyfill } from 'react-lifecycles-compat';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { AntAnchor } from './Anchor';
|
import { AntAnchor } from './Anchor';
|
||||||
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
|
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
|
||||||
@ -12,7 +13,7 @@ export interface AnchorLinkProps {
|
|||||||
className?: string;
|
className?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class AnchorLink extends React.Component<AnchorLinkProps, any> {
|
class AnchorLink extends React.Component<AnchorLinkProps, any> {
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
href: '#',
|
href: '#',
|
||||||
};
|
};
|
||||||
@ -29,10 +30,10 @@ export default class AnchorLink extends React.Component<AnchorLinkProps, any> {
|
|||||||
this.context.antAnchor.registerLink(this.props.href);
|
this.context.antAnchor.registerLink(this.props.href);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps: AnchorLinkProps) {
|
componentDidUpdate({ href: prevHref }: AnchorLinkProps) {
|
||||||
const { href } = nextProps;
|
const { href } = this.props;
|
||||||
if (this.props.href !== href) {
|
if (prevHref !== href) {
|
||||||
this.context.antAnchor.unregisterLink(this.props.href);
|
this.context.antAnchor.unregisterLink(prevHref);
|
||||||
this.context.antAnchor.registerLink(href);
|
this.context.antAnchor.registerLink(href);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -79,3 +80,7 @@ export default class AnchorLink extends React.Component<AnchorLinkProps, any> {
|
|||||||
return <ConfigConsumer>{this.renderAnchorLink}</ConfigConsumer>;
|
return <ConfigConsumer>{this.renderAnchorLink}</ConfigConsumer>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
polyfill(AnchorLink);
|
||||||
|
|
||||||
|
export default AnchorLink;
|
||||||
|
Loading…
Reference in New Issue
Block a user