Browse Source
fix: ConfigProvider with nest prefixCls (#23423)
* fix: ConfigProvider with nest prefixCls
* update
* update
* update
pull/23426/head
二货机器人
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
22 additions and
6 deletions
-
components/config-provider/__tests__/index.test.js
-
components/config-provider/context.tsx
-
components/config-provider/index.tsx
|
|
@ -42,4 +42,16 @@ describe('ConfigProvider', () => { |
|
|
|
|
|
|
|
expect(wrapper.text()).toContain('empty placeholder'); |
|
|
|
}); |
|
|
|
|
|
|
|
it('nest prefixCls', () => { |
|
|
|
const wrapper = mount( |
|
|
|
<ConfigProvider prefixCls="bamboo"> |
|
|
|
<ConfigProvider> |
|
|
|
<Button /> |
|
|
|
</ConfigProvider> |
|
|
|
</ConfigProvider>, |
|
|
|
); |
|
|
|
|
|
|
|
expect(wrapper.find('button').props().className).toEqual('bamboo-btn'); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
@ -29,7 +29,7 @@ export const ConfigContext = React.createContext<ConfigConsumerProps>({ |
|
|
|
getPrefixCls: (suffixCls: string, customizePrefixCls?: string) => { |
|
|
|
if (customizePrefixCls) return customizePrefixCls; |
|
|
|
|
|
|
|
return `ant-${suffixCls}`; |
|
|
|
return suffixCls ? `ant-${suffixCls}` : 'ant'; |
|
|
|
}, |
|
|
|
|
|
|
|
renderEmpty: defaultRenderEmpty, |
|
|
|
|
|
@ -45,12 +45,16 @@ export interface ConfigProviderProps { |
|
|
|
} |
|
|
|
|
|
|
|
class ConfigProvider extends React.Component<ConfigProviderProps> { |
|
|
|
getPrefixCls = (suffixCls: string, customizePrefixCls?: string) => { |
|
|
|
const { prefixCls = 'ant' } = this.props; |
|
|
|
getPrefixClsWrapper = (context: ConfigConsumerProps) => { |
|
|
|
return (suffixCls: string, customizePrefixCls?: string) => { |
|
|
|
const { prefixCls } = this.props; |
|
|
|
|
|
|
|
if (customizePrefixCls) return customizePrefixCls; |
|
|
|
if (customizePrefixCls) return customizePrefixCls; |
|
|
|
|
|
|
|
return suffixCls ? `${prefixCls}-${suffixCls}` : prefixCls; |
|
|
|
const mergedPrefixCls = prefixCls || context.getPrefixCls(''); |
|
|
|
|
|
|
|
return suffixCls ? `${mergedPrefixCls}-${suffixCls}` : mergedPrefixCls; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
renderProvider = (context: ConfigConsumerProps, legacyLocale: Locale) => { |
|
|
@ -70,7 +74,7 @@ class ConfigProvider extends React.Component<ConfigProviderProps> { |
|
|
|
|
|
|
|
const config: ConfigConsumerProps = { |
|
|
|
...context, |
|
|
|
getPrefixCls: this.getPrefixCls, |
|
|
|
getPrefixCls: this.getPrefixClsWrapper(context), |
|
|
|
csp, |
|
|
|
autoInsertSpaceInButton, |
|
|
|
locale: locale || legacyLocale, |
|
|
|