feat(ConfigProvider): support Modal centered global config (#52343)
Some checks are pending
Publish Any Commit / build (push) Waiting to run
🔀 Sync mirror to Gitee / mirror (push) Waiting to run
✅ test / lint (push) Waiting to run
✅ test / test-react-legacy (16, 1/2) (push) Waiting to run
✅ test / test-react-legacy (16, 2/2) (push) Waiting to run
✅ test / test-react-legacy (17, 1/2) (push) Waiting to run
✅ test / test-react-legacy (17, 2/2) (push) Waiting to run
✅ test / test-node (push) Waiting to run
✅ test / test-react-latest (dom, 1/2) (push) Waiting to run
✅ test / test-react-latest (dom, 2/2) (push) Waiting to run
✅ test / test-react-latest-dist (dist, 1/2) (push) Blocked by required conditions
✅ test / test-react-latest-dist (dist, 2/2) (push) Blocked by required conditions
✅ test / test-react-latest-dist (dist-min, 1/2) (push) Blocked by required conditions
✅ test / test-react-latest-dist (dist-min, 2/2) (push) Blocked by required conditions
✅ test / test-coverage (push) Blocked by required conditions
✅ test / build (push) Waiting to run
✅ test / test lib/es module (es, 1/2) (push) Waiting to run
✅ test / test lib/es module (es, 2/2) (push) Waiting to run
✅ test / test lib/es module (lib, 1/2) (push) Waiting to run
✅ test / test lib/es module (lib, 2/2) (push) Waiting to run
👁️ Visual Regression Persist Start / test image (push) Waiting to run

This commit is contained in:
Guo Yunhe 2025-01-13 15:44:59 +08:00 committed by GitHub
parent d7512d5190
commit d74f5918b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 2 deletions

View File

@ -145,7 +145,7 @@ export type DescriptionsConfig = ComponentStyleConfig &
export type EmptyConfig = ComponentStyleConfig & Pick<EmptyProps, 'classNames' | 'styles'>;
export type ModalConfig = ComponentStyleConfig &
Pick<ModalProps, 'classNames' | 'styles' | 'closeIcon' | 'closable'>;
Pick<ModalProps, 'classNames' | 'styles' | 'closeIcon' | 'closable' | 'centered'>;
export type TabsConfig = ComponentStyleConfig &
Pick<TabsProps, 'indicator' | 'indicatorSize' | 'more' | 'moreIcon' | 'addIcon' | 'removeIcon'>;

View File

@ -99,7 +99,7 @@ const Modal: React.FC<ModalProps> = (props) => {
const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls, rootCls);
const wrapClassNameExtended = classNames(wrapClassName, {
[`${prefixCls}-centered`]: !!centered,
[`${prefixCls}-centered`]: centered ?? modalContext?.centered,
[`${prefixCls}-wrap-rtl`]: direction === 'rtl',
});

View File

@ -6,6 +6,7 @@ import { resetWarned } from '../../_util/warning';
import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest';
import { createEvent, fireEvent, render } from '../../../tests/utils';
import ConfigProvider from '../../config-provider';
jest.mock('rc-util/lib/Portal');
@ -208,4 +209,27 @@ describe('Modal', () => {
'--ant-modal-xxl-width': '40%',
});
});
it('Should support centered prop', () => {
render(<Modal open centered />);
expect(document.querySelector('.ant-modal-centered')).toBeTruthy();
});
it('Should support centered global config', () => {
render(
<ConfigProvider modal={{ centered: true }}>
<Modal open />
</ConfigProvider>,
);
expect(document.querySelector('.ant-modal-centered')).toBeTruthy();
});
it('Should prefer centered prop over centered global config', () => {
render(
<ConfigProvider modal={{ centered: true }}>
<Modal open centered={false} />
</ConfigProvider>,
);
expect(document.querySelector('.ant-modal-centered')).toBeFalsy();
});
});