mirror of
https://github.com/ant-design/ant-design.git
synced 2025-08-06 16:06:28 +08:00
fix: fix Descriptions size small of CP (#42244)
This commit is contained in:
parent
7de7a8b6e4
commit
d0e29d33b7
@ -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(
|
||||
<ConfigProvider componentSize="small">
|
||||
<Descriptions bordered>
|
||||
<Descriptions.Item label="small">small</Descriptions.Item>
|
||||
</Descriptions>
|
||||
</ConfigProvider>,
|
||||
);
|
||||
expect(container.querySelectorAll('.ant-descriptions-small')).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
@ -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<ScreenMap>({});
|
||||
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',
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user