fix: 修复 Tag onClick 为 undefined 的判断方式 (#40023)

* fix: 修复 Tag onClick 为 undefined 的判断方式

* feat: function
This commit is contained in:
叶枫 2023-01-05 10:24:14 +08:00 committed by GitHub
parent c74b93b2df
commit 81a1ffd53c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -8,6 +8,19 @@ import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest';
import { act, render, fireEvent } from '../../../tests/utils';
(global as any).isVisible = true;
jest.mock('rc-util/lib/Dom/isVisible', () => {
const mockFn = () => (global as any).isVisible;
return mockFn;
});
function waitRaf() {
act(() => {
jest.advanceTimersByTime(100);
});
}
describe('Tag', () => {
mountTest(Tag);
mountTest(Tag.CheckableTag);
@ -152,4 +165,10 @@ describe('Tag', () => {
expect(onChange).toHaveBeenCalledWith(true);
});
});
it('should onClick is undefined', async () => {
const { container } = render(<Tag onClick={undefined} />);
fireEvent.click(container.querySelectorAll('.ant-tag')[0]);
waitRaf();
expect(document.querySelector('.ant-wave')).toBeFalsy();
});
});

View File

@ -119,7 +119,8 @@ const InternalTag: React.ForwardRefRenderFunction<HTMLSpanElement, TagProps> = (
};
const isNeedWave =
'onClick' in props || (children && (children as React.ReactElement<any>).type === 'a');
typeof props.onClick === 'function' ||
(children && (children as React.ReactElement<any>).type === 'a');
const iconNode = icon || null;
const kids = iconNode ? (
<>