JGuang

ConfigProvider

ConfigProvider · Ant Design

Preview
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

ConfigProvider

Provide a uniform configuration support for components.

Usage

This component provides a configuration to all React components underneath itself via the context API. In the render tree all components will have access to the provided config.

import React from 'react';
import { ConfigProvider } from 'antd';

// ...
const Demo: React.FC = () => (
  <ConfigProvider direction="rtl">
    <App />
  </ConfigProvider>
);

export default Demo;

Content Security Policy

Some components use dynamic style to support wave effect. You can config csp prop if Content Security Policy (CSP) is enabled:

<ConfigProvider csp={{ nonce: 'YourNonceCode' }}>
  <Button>My Button</Button>
</ConfigProvider>

Examples

  • Locale · locale
  • Direction · direction
  • Component size · size
  • Theme · theme
  • Custom Wave · wave
  • Static function · holderRender

API

PropertyDescriptionTypeDefaultVersion
componentDisabledConfig antd component disabledboolean-4.21.0
componentSizeConfig antd component sizesmall | medium | large-
cspSet Content Security Policy config{ nonce: string }-
directionSet direction of layout. See demoltr | rtlltr
getPopupContainerTo set the container of the popup element. The default is to create a div element in body(trigger?: HTMLElement) => HTMLElement | ShadowRoot() => document.body
getTargetContainerConfig Affix, Anchor scroll target container() => HTMLElement | Window | ShadowRoot() => window4.2.0
iconPrefixClsSet icon prefix classNamestringanticon4.11.0
localeLanguage package setting, you can find the packages in antd/localeobject-
popupMatchSelectWidthDetermine whether the dropdown menu and the select input are the same width. Default set min-width same as input. Will ignore when value less than select width. false will disable virtual scrollboolean | number-5.5.0
popupOverflowSelect like component popup logic. Can set to show in viewport or follow window scroll'viewport' | 'scroll' Native explanatory image'viewport'5.5.0
prefixClsSet prefix classNamestringant
renderEmptySet empty content of components. Ref Emptyfunction(componentName: string): ReactNode-
themeSet theme, ref Customize ThemeTheme-5.0.0
variantSet variant of data entry componentsoutlined | filled | borderless-5.19.0
virtualDisable virtual scroll when set to falseboolean-4.3.0
warningConfig warning level, when strict is false, it will aggregate deprecated information into a single message{ strict: boolean }-5.10.0
autoInsertSpaceInButtonButton auto spacing config, please use button={{ autoInsertSpace: boolean }} insteadboolean--
dropdownMatchSelectWidthDetermine whether the dropdown menu and the select input are the same width, please use popupMatchSelectWidth insteadboolean--

ConfigProvider.config()

Setting Modal, Message, Notification static config. Does not work on hooks.

ConfigProvider.config({
  // 5.13.0+
  holderRender: (children) => (
    <ConfigProvider
      prefixCls="ant"
      iconPrefixCls="anticon"
      theme={{ token: { colorPrimary: 'red' } }}
    >
      {children}
    </ConfigProvider>
  ),
});

ConfigProvider.useConfig() <Badge>5.3.0+</Badge>

Get the value of the parent Provider, Such as DisabledContextProvider, SizeContextProvider.

const {
  componentDisabled, // 5.3.0+
  componentSize, // 5.3.0+
} = ConfigProvider.useConfig();
PropertyDescriptionTypeDefaultVersion
componentDisabledantd component disabled stateboolean-5.3.0
componentSizeantd component size statesmall | medium | large-5.3.0

Component Config

The following config keys set common props for corresponding components or global effects. See the related APIs for details:

  • affix: Affix (supported since 6.0.0)
  • alert: Alert (supported since 5.7.0)
  • anchor: Anchor (supported since 6.0.0)
  • app: App (supported since 6.3.0)
  • avatar: Avatar (supported since 5.7.0)
  • badge: Badge (supported since 5.7.0)
  • borderBeam: BorderBeam (supported since 6.4.0)
  • breadcrumb: Breadcrumb (supported since 5.7.0)
  • button: Button (supported since 5.6.0)
  • card: Card (supported since 5.14.0)
  • cardMeta: Card.Meta (supported since 6.0.0)
  • calendar: Calendar (supported since 6.0.0)
  • carousel: Carousel (supported since 5.7.0)
  • cascader: Cascader (supported since 5.13.0)
  • checkbox: Checkbox (supported since 6.0.0)
  • collapse: Collapse (supported since 5.15.0)
  • colorPicker: ColorPicker (supported since 6.3.0)
  • datePicker: DatePicker (supported since 5.7.0)
  • rangePicker: RangePicker (supported since 5.11.0)
  • descriptions: Descriptions (supported since 5.23.0)
  • divider: Divider (supported since 5.10.0)
  • drawer: Drawer (supported since 5.10.0)
  • dropdown: Dropdown (supported since 5.11.0)
  • empty: Empty (supported since 5.23.0)
  • flex: Flex (supported since 5.10.0)
  • floatButton: FloatButton (supported since 6.0.0)
  • floatButtonGroup: FloatButton.Group (supported since 5.16.0)
  • form: Form (supported since 4.8.0)
  • image: Image (supported since 5.14.0)
  • input: Input (supported since 4.2.0)
  • inputNumber: InputNumber (supported since 5.19.0)
  • otp: Input.OTP (supported since 6.0.0)
  • inputPassword: Input.Password (supported since 6.4.0)
  • inputSearch: Input.Search (supported since 6.4.0)
  • textArea: Input.TextArea (supported since 5.15.0)
  • layout: Layout (supported since 5.7.0)
  • list: List (supported since 5.7.0)
  • listy: Listy (supported since 6.6.0)
  • masonry: Masonry (supported since 6.0.0)
  • menu: Menu (supported since 5.15.0)
  • mentions: Mentions (supported since 5.13.0)
  • message: Message (supported since 5.7.0)
  • modal: Modal (supported since 5.10.0)
  • notification: Notification (supported since 5.14.0)
  • pagination: Pagination (supported since 6.0.0)
  • progress: Progress (supported since 5.7.0)
  • radio: Radio (supported since 6.0.0)
  • rate: Rate (supported since 5.7.0)
  • result: Result (supported since 6.0.0)
  • ribbon: Badge.Ribbon (supported since 6.0.0)
  • skeleton: Skeleton (supported since 6.0.0)
  • segmented: Segmented (supported since 6.0.0)
  • select: Select (supported since 5.13.0)
  • slider: Slider (supported since 5.23.0)
  • switch: Switch (supported since 6.0.0)
  • space: Space (supported since 5.6.0)
  • splitter: Splitter (supported since 5.21.0)
  • spin: Spin (supported since 5.20.0)
  • statistic: Statistic (supported since 6.0.0)
  • steps: Steps (supported since 5.10.0)
  • table: Table (supported since 6.2.0)
  • tabs: Tabs (supported since 5.14.0)
  • tag: Tag (supported since 5.14.0)
  • timeline: Timeline (supported since 6.0.0)
  • timePicker: TimePicker (supported since 5.13.0)
  • tour: Tour (supported since 5.14.0)
  • tooltip: Tooltip (supported since 6.1.0)
  • popover: Popover (supported since 5.23.0)
  • popconfirm: Popconfirm (supported since 5.23.0)
  • qrcode: QRCode (supported since 6.0.0)
  • transfer: Transfer (supported since 5.7.0)
  • tree: Tree (supported since 6.0.0)
  • treeSelect: TreeSelect (supported since 5.19.0)
  • typography: Typography (supported since 6.4.0)
  • upload: Upload (supported since 5.27.0)
  • watermark: Watermark (supported since 6.0.0)
  • wave: WaveConfig (supported since 5.8.0)

WaveConfig

PropertyDescriptionTypeDefaultVersion
disabledWhether to disable wave effectbooleanfalse
showEffectCustomized wave effect(node: HTMLElement, info: { className, token, component }) => void-
triggerTypeThe event that triggers wave effectclick | pointerdown | pointerup | mousedown | mouseupclick6.4.0

FAQ

How to contribute a new language?

See <Adding new language>.

Date-related components locale is not working?

See FAQ Date-related-components-locale-is-not-working?

Modal throw error when setting getPopupContainer?

Related issue: https://github.com/ant-design/ant-design/issues/19974

When you config getPopupContainer to parentNode globally, Modal will throw error of triggerNode is undefined because it did not have a triggerNode. You can try the fix below.

 <ConfigProvider
-  getPopupContainer={triggerNode => triggerNode.parentNode}
+  getPopupContainer={node => {
+    if (node) {
+      return node.parentNode;
+    }
+    return document.body;
+  }}
 >
   <App />
 </ConfigProvider>

Why can't ConfigProvider props (like prefixCls and theme) affect ReactNode inside message.info, notification.open, Modal.confirm?

antd will dynamic create React instance by ReactDOM.render when call message methods. Whose context is different with origin code located context. We recommend useMessage, useNotification and useModal which , the methods came from message/notification/Modal has been deprecated in 5.x.

Locale is not working with Vite in production mode?

Related issue: #39045

In production mode of Vite, default exports from cjs file should be used like this: enUS.default. So you can directly import locale from es/ directory like import enUS from 'antd/es/locale/en_US' to make dev and production have the same behavior.

prefixCls priority(The former is covered by the latter)

  1. ConfigProvider.config({ prefixCls: 'prefix-1' })
  2. ConfigProvider.config({ holderRender: (children) => <ConfigProvider prefixCls="prefix-2">{children}</ConfigProvider> })
  3. message.config({ prefixCls: 'prefix-3' })

Shared native props

Tips: The following generic properties apply to most antd components; those not supported are described separately.

PropertyDescriptionTypeDefault
styleThe additional styleCSSProperties-
classNameThe additional css classstring-
rootClassNameClassName on the root elementstring-
autoFocusAuto focus when component mounted, only effective for focusable elements like forms, links, etc.booleanfalse

Install and reproduce an example

npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

Use ConfigProvider and native App; configure dayjs locale separately. Each example lists its complete source files and additional pinned dependencies in View code. Example names select demos, not universal component props. See the resource setup guide for theme, locale and SSR.

Native type references

The source viewer includes unchanged native implementations and the following source declarations. Inherited types remain in their native packages. English source comments are preserved as code reference.

  • vendor/components/config-provider/DisabledContext.tsx
  • vendor/components/config-provider/MotionWrapper.tsx
  • vendor/components/config-provider/PropWarning.tsx
  • vendor/components/config-provider/SizeContext.tsx
  • vendor/components/config-provider/context.ts
  • vendor/components/config-provider/defaultRenderEmpty.tsx
  • vendor/components/config-provider/index.tsx

Source and license

https://github.com/ant-design/ant-design/tree/4a39f54842eade4e565ab336ef6097cd7e723cdd

Original bilingual prose and executable examples are retained. Website-only embeds and token tables are expanded locally. Ant Design is MIT; separately listed dependency notices also apply. Upload previews block outbound requests and do not provide a backend.