mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-07 17:44:35 +08:00
fix: anchorLink href update
This commit is contained in:
parent
d2c34e32a1
commit
14e0cc0161
@ -27,6 +27,14 @@ 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) {
|
||||||
|
const { href } = nextProps;
|
||||||
|
if (this.props.href !== href) {
|
||||||
|
this.context.antAnchor.unregisterLink(this.props.href);
|
||||||
|
this.context.antAnchor.registerLink(href);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
this.context.antAnchor.unregisterLink(this.props.href);
|
this.context.antAnchor.unregisterLink(this.props.href);
|
||||||
}
|
}
|
||||||
|
@ -90,4 +90,20 @@ describe('Anchor Render', () => {
|
|||||||
wrapper.setProps({ children: null });
|
wrapper.setProps({ children: null });
|
||||||
expect(wrapper.instance().links).toEqual([]);
|
expect(wrapper.instance().links).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should update links when link href update', async () => {
|
||||||
|
let anchorInstance = null;
|
||||||
|
function AnchorUpdate({ href }) {
|
||||||
|
return (
|
||||||
|
<Anchor ref={c => anchorInstance = c}>
|
||||||
|
<Link href={href} title="API" />
|
||||||
|
</Anchor>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const wrapper = mount(<AnchorUpdate href="#API" />);
|
||||||
|
|
||||||
|
expect(anchorInstance.links).toEqual(['#API']);
|
||||||
|
wrapper.setProps({ href: '#API_1' });
|
||||||
|
expect(anchorInstance.links).toEqual(['#API_1']);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user