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. 4
      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); 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', () => { describe('visibility', () => {
it('can be controlled by visible with visible as initial value', () => { it('can be controlled by visible with visible as initial value', () => {
const wrapper = mount(<Tag visible />); const wrapper = mount(<Tag visible />);

4
components/tag/index.tsx

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

Loading…
Cancel
Save