Skip to content

Commit

Permalink
fix: CheckableTag miss CP tag
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Sep 2, 2023
1 parent 8099247 commit e21907a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 6 additions & 0 deletions components/config-provider/__tests__/style.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';

import ConfigProvider from '..';
import { fireEvent, render } from '../../../tests/utils';
import Alert from '../../alert';
Expand Down Expand Up @@ -942,11 +943,16 @@ describe('ConfigProvider support style and className props', () => {
const { container } = render(
<ConfigProvider tag={{ className: 'cp-tag', style: { backgroundColor: 'blue' } }}>
<Tag>Test</Tag>
<Tag.CheckableTag checked>CheckableTag</Tag.CheckableTag>
</ConfigProvider>,
);
const element = container.querySelector<HTMLSpanElement>('.ant-tag');
expect(element).toHaveClass('cp-tag');
expect(element).toHaveStyle({ backgroundColor: 'blue' });

const checkableElement = container.querySelector<HTMLSpanElement>('.ant-tag-checkable');
expect(checkableElement).toHaveClass('cp-tag');
expect(checkableElement).toHaveStyle({ backgroundColor: 'blue' });
});

it('Should Table className & style works', () => {
Expand Down
19 changes: 16 additions & 3 deletions components/tag/CheckableTag.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import classNames from 'classnames';
import * as React from 'react';
import classNames from 'classnames';

import { ConfigContext } from '../config-provider';
import useStyle from './style';

Expand All @@ -21,13 +22,14 @@ export interface CheckableTagProps {
const CheckableTag: React.FC<CheckableTagProps> = (props) => {
const {
prefixCls: customizePrefixCls,
style,
className,
checked,
onChange,
onClick,
...restProps
} = props;
const { getPrefixCls } = React.useContext(ConfigContext);
const { getPrefixCls, tag } = React.useContext(ConfigContext);

const handleClick = (e: React.MouseEvent<HTMLSpanElement, MouseEvent>) => {
onChange?.(!checked);
Expand All @@ -44,11 +46,22 @@ const CheckableTag: React.FC<CheckableTagProps> = (props) => {
{
[`${prefixCls}-checkable-checked`]: checked,
},
tag?.className,
className,
hashId,
);

return wrapSSR(<span {...restProps} className={cls} onClick={handleClick} />);
return wrapSSR(
<span
{...restProps}
style={{
...style,
...tag?.style,
}}
className={cls}
onClick={handleClick}
/>,
);
};

export default CheckableTag;

0 comments on commit e21907a

Please sign in to comment.