mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-12 04:13:13 +08:00
fix: ConfigProvider with nest prefixCls (#23423)
* fix: ConfigProvider with nest prefixCls * update * update * update
This commit is contained in:
parent
3d76859bbc
commit
5a10d29796
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user