Browse Source
fix: useModal missing prefix (#25967)
* fix: useModal hooks missing style
* add test case
pull/25970/head
二货机器人
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
10 additions and
3 deletions
-
components/config-provider/context.tsx
-
components/modal/__tests__/hook.test.js
-
components/modal/useModal/HookModal.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'; |
|
|
|
|
|
@ -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({ |
|
|
|
|
|
@ -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} |
|
|
|