Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复 Tag onClick 为 undefined,鼠标点击也会出现边框样式 #40023

Merged
merged 2 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions components/tag/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
});
});
3 changes: 2 additions & 1 deletion components/tag/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

解决什么问题?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crazyair 来改一下 Changelog ?

Copy link
Member Author

@crazyair crazyair Jan 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<Tooltip title="title">
    <Tag>demo</Tag>
</Tooltip>

hover 的 Tooltip,会给 children 注入 onClick,导致鼠标点击 Tag 会出现边框样式

const iconNode = icon || null;
const kids = iconNode ? (
<>
Expand Down