Skip to content

Commit

Permalink
should not call afterClose when change visible from false to true
Browse files Browse the repository at this point in the history
  • Loading branch information
tangjinzhou authored and afc163 committed Jan 10, 2019
1 parent 41e2103 commit 13ee0ad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
12 changes: 12 additions & 0 deletions components/tag/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 />);
Expand Down
10 changes: 6 additions & 4 deletions components/tag/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
};

Expand Down

0 comments on commit 13ee0ad

Please sign in to comment.