Browse Source

should not call afterClose when change visible from false to true

pull/14264/head
tangjinzhou 6 years ago
committed by 偏右
parent
commit
13ee0ad52f
  1. 12
      components/tag/__tests__/index.test.js
  2. 10
      components/tag/index.tsx

12
components/tag/__tests__/index.test.js

@ -35,6 +35,18 @@ describe('Tag', () => {
expect(wrapper.find('div.ant-tag:not(.ant-tag-hidden)').length).toBe(1);
});
it('should not call afterClose when change visible from false to true', () => {
const handleAfterClose = jest.fn();
const wrapper = mount(<Tag visible afterClose={handleAfterClose} />);
wrapper.setProps({ visible: false });
jest.runAllTimers();
expect(handleAfterClose).toHaveBeenCalled();
handleAfterClose.mockRestore();
wrapper.setProps({ visible: true });
jest.runAllTimers();
expect(handleAfterClose).not.toHaveBeenCalled();
});
describe('visibility', () => {
it('can be controlled by visible with visible as initial value', () => {
const wrapper = mount(<Tag visible />);

10
components/tag/index.tsx

@ -70,10 +70,12 @@ class Tag extends React.Component<TagProps, TagState> {
this.setVisible(false, e);
};
animationEnd = () => {
const { afterClose } = this.props;
if (afterClose) {
afterClose();
animationEnd = (_: string, existed: boolean) => {
if (!existed) {
const { afterClose } = this.props;
if (afterClose) {
afterClose();
}
}
};

Loading…
Cancel
Save