Browse Source

fix: useModal missing prefix (#25967)

* fix: useModal hooks missing style

* add test case
pull/25970/head
二货机器人 4 years ago
committed by GitHub
parent
commit
9fdad14dc0
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      components/config-provider/context.tsx
  2. 2
      components/modal/__tests__/hook.test.js
  3. 7
      components/modal/useModal/HookModal.tsx

4
components/config-provider/context.tsx

@ -11,7 +11,7 @@ export interface ConfigConsumerProps {
getTargetContainer?: () => HTMLElement;
getPopupContainer?: (triggerNode: HTMLElement) => HTMLElement;
rootPrefixCls?: string;
getPrefixCls: (suffixCls: string, customizePrefixCls?: string) => string;
getPrefixCls: (suffixCls?: string, customizePrefixCls?: string) => string;
renderEmpty: RenderEmptyHandler;
csp?: CSPConfig;
autoInsertSpaceInButton?: boolean;
@ -32,7 +32,7 @@ export interface ConfigConsumerProps {
export const ConfigContext = React.createContext<ConfigConsumerProps>({
// We provide a default function for Context without provider
getPrefixCls: (suffixCls: string, customizePrefixCls?: string) => {
getPrefixCls: (suffixCls?: string, customizePrefixCls?: string) => {
if (customizePrefixCls) return customizePrefixCls;
return suffixCls ? `ant-${suffixCls}` : 'ant';

2
components/modal/__tests__/hook.test.js

@ -35,6 +35,8 @@ describe('Modal.hook', () => {
wrapper.find('button').simulate('click');
expect(wrapper.find('.test-hook').text()).toEqual('bamboo');
expect(wrapper.find('.ant-btn').length).toBeTruthy();
expect(wrapper.find('.ant-modal-body').length).toBeTruthy();
// Update instance
instance.update({

7
components/modal/useModal/HookModal.tsx

@ -27,7 +27,10 @@ const HookModal: React.ForwardRefRenderFunction<HookModalRef, HookModalProps> =
) => {
const [visible, setVisible] = React.useState(true);
const [innerConfig, setInnerConfig] = React.useState(config);
const { direction } = React.useContext(ConfigContext);
const { direction, getPrefixCls } = React.useContext(ConfigContext);
const prefixCls = getPrefixCls('modal');
const rootPrefixCls = getPrefixCls();
function close() {
setVisible(false);
@ -47,6 +50,8 @@ const HookModal: React.ForwardRefRenderFunction<HookModalRef, HookModalProps> =
<LocaleReceiver componentName="Modal" defaultLocale={defaultLocale.Modal}>
{(modalLocale: ModalLocale) => (
<ConfirmDialog
prefixCls={prefixCls}
rootPrefixCls={rootPrefixCls}
{...innerConfig}
close={close}
visible={visible}

Loading…
Cancel
Save