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: Descriptions lost border style when children is falsy #47191

Merged
merged 1 commit into from
Jan 27, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions components/descriptions/Cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface CellProps {
label?: React.ReactNode;
content?: React.ReactNode;
colon?: boolean;
type?: 'label' | 'content' | 'item';
}

const Cell: React.FC<CellProps> = (props) => {
Expand All @@ -32,6 +33,7 @@ const Cell: React.FC<CellProps> = (props) => {
label,
content,
colon,
type,
} = props;

const Component = component as keyof JSX.IntrinsicElements;
Expand All @@ -41,8 +43,8 @@ const Cell: React.FC<CellProps> = (props) => {
<Component
className={classNames(
{
[`${itemPrefixCls}-item-label`]: notEmpty(label),
[`${itemPrefixCls}-item-content`]: notEmpty(content),
[`${itemPrefixCls}-item-label`]: type === 'label',
[`${itemPrefixCls}-item-content`]: type === 'content',
},
className,
)}
Expand Down
5 changes: 4 additions & 1 deletion components/descriptions/Row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import DescriptionsContext from './DescriptionsContext';

interface CellConfig {
component: string | [string, string];
type: string;
type: 'label' | 'content' | 'item';
showLabel?: boolean;
showContent?: boolean;
}
Expand Down Expand Up @@ -54,6 +54,7 @@ function renderCells(
bordered={bordered}
label={showLabel ? label : null}
content={showContent ? children : null}
type={type}
/>
);
}
Expand All @@ -69,6 +70,7 @@ function renderCells(
itemPrefixCls={itemPrefixCls}
bordered={bordered}
label={label}
type="label"
/>,
<Cell
key={`content-${key || index}`}
Expand All @@ -79,6 +81,7 @@ function renderCells(
itemPrefixCls={itemPrefixCls}
bordered={bordered}
content={children}
type="content"
/>,
];
},
Expand Down
18 changes: 18 additions & 0 deletions components/descriptions/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -377,4 +377,22 @@ describe('Descriptions', () => {
expect.anything(),
);
});

// https://github.com/ant-design/ant-design/issues/47151
it('should has .ant-descriptions-item-content className when children is falsy', () => {
const wrapper = render(
<Descriptions
bordered
items={[
{
key: '1',
label: null,
children: null,
},
]}
/>,
);
expect(wrapper.container.querySelectorAll('.ant-descriptions-item-label')).toHaveLength(1);
expect(wrapper.container.querySelectorAll('.ant-descriptions-item-content')).toHaveLength(1);
});
});