From d0e29d33b74df60753043492ff9cb92cd3092fd7 Mon Sep 17 00:00:00 2001
From: huiwang <37385554+wanghui2021@users.noreply.github.com>
Date: Wed, 10 May 2023 14:09:25 +0800
Subject: [PATCH] fix: fix Descriptions size small of CP (#42244)
---
components/descriptions/__tests__/index.test.tsx | 12 ++++++++++++
components/descriptions/index.tsx | 8 ++++++--
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/components/descriptions/__tests__/index.test.tsx b/components/descriptions/__tests__/index.test.tsx
index 0968ee2c04..07359b39f6 100644
--- a/components/descriptions/__tests__/index.test.tsx
+++ b/components/descriptions/__tests__/index.test.tsx
@@ -4,6 +4,7 @@ import Descriptions from '..';
import mountTest from '../../../tests/shared/mountTest';
import { resetWarned } from '../../_util/warning';
import { render } from '../../../tests/utils';
+import ConfigProvider from '../../config-provider';
describe('Descriptions', () => {
mountTest(Descriptions);
@@ -267,4 +268,15 @@ describe('Descriptions', () => {
expect(container).toHaveAttribute('data-id', '12345');
expect(container).toHaveAttribute('aria-describedby', 'some-label');
});
+
+ it('Descriptions should inherit the size from ConfigProvider if the componentSize is set ', () => {
+ const { container } = render(
+
+
+ small
+
+ ,
+ );
+ expect(container.querySelectorAll('.ant-descriptions-small')).toHaveLength(1);
+ });
});
diff --git a/components/descriptions/index.tsx b/components/descriptions/index.tsx
index bdd90448ff..e59827e8d7 100644
--- a/components/descriptions/index.tsx
+++ b/components/descriptions/index.tsx
@@ -11,6 +11,7 @@ import DescriptionsItem from './Item';
import Row from './Row';
import useStyle from './style';
+import SizeContext from '../config-provider/SizeContext';
export interface DescriptionsContextProps {
labelStyle?: React.CSSProperties;
@@ -127,7 +128,7 @@ function Descriptions({
className,
rootClassName,
style,
- size,
+ size: customizeSize,
labelStyle,
contentStyle,
...restProps
@@ -137,6 +138,9 @@ function Descriptions({
const [screens, setScreens] = React.useState({});
const mergedColumn = getColumn(column, screens);
+ const size = React.useContext(SizeContext);
+ const mergedSize = customizeSize ?? size;
+
const [wrapSSR, hashId] = useStyle(prefixCls);
const responsiveObserver = useResponsiveObserver();
@@ -167,7 +171,7 @@ function Descriptions({
className={classNames(
prefixCls,
{
- [`${prefixCls}-${size}`]: size && size !== 'default',
+ [`${prefixCls}-${mergedSize}`]: mergedSize && mergedSize !== 'default',
[`${prefixCls}-bordered`]: !!bordered,
[`${prefixCls}-rtl`]: direction === 'rtl',
},