Skip to content

Commit cdeeceb

Browse files
crazyairSohaibRaza
authored andcommitted
fix: 修复 Tag onClick 为 undefined 的判断方式 (ant-design#40023)
* fix: 修复 Tag onClick 为 undefined 的判断方式 * feat: function
1 parent ffd230b commit cdeeceb

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

components/tag/__tests__/index.test.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ import mountTest from '../../../tests/shared/mountTest';
88
import rtlTest from '../../../tests/shared/rtlTest';
99
import { act, render, fireEvent } from '../../../tests/utils';
1010

11+
(global as any).isVisible = true;
12+
13+
jest.mock('rc-util/lib/Dom/isVisible', () => {
14+
const mockFn = () => (global as any).isVisible;
15+
return mockFn;
16+
});
17+
18+
function waitRaf() {
19+
act(() => {
20+
jest.advanceTimersByTime(100);
21+
});
22+
}
23+
1124
describe('Tag', () => {
1225
mountTest(Tag);
1326
mountTest(Tag.CheckableTag);
@@ -152,4 +165,10 @@ describe('Tag', () => {
152165
expect(onChange).toHaveBeenCalledWith(true);
153166
});
154167
});
168+
it('should onClick is undefined', async () => {
169+
const { container } = render(<Tag onClick={undefined} />);
170+
fireEvent.click(container.querySelectorAll('.ant-tag')[0]);
171+
waitRaf();
172+
expect(document.querySelector('.ant-wave')).toBeFalsy();
173+
});
155174
});

components/tag/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ const InternalTag: React.ForwardRefRenderFunction<HTMLSpanElement, TagProps> = (
119119
};
120120

121121
const isNeedWave =
122-
'onClick' in props || (children && (children as React.ReactElement<any>).type === 'a');
122+
typeof props.onClick === 'function' ||
123+
(children && (children as React.ReactElement<any>).type === 'a');
123124
const iconNode = icon || null;
124125
const kids = iconNode ? (
125126
<>

0 commit comments

Comments
 (0)