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
parent
commit
5a10d29796
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      components/config-provider/__tests__/index.test.js
  2. 2
      components/config-provider/context.tsx
  3. 14
      components/config-provider/index.tsx

12
components/config-provider/__tests__/index.test.js

@ -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');
});
});

2
components/config-provider/context.tsx

@ -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,

14
components/config-provider/index.tsx

@ -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,

Loading…
Cancel
Save