mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-17 23:50:52 +08:00
feat: config-provider support Input className and style properties (#43227)
* feat: config-provider support Input className and style properties
* feat: config-provider support Form className and style properties
* Revert "feat: config-provider support Form className and style properties"
This reverts commit 183010d40a
.
* feat: support styles & classNames
* test: optimize test
This commit is contained in:
parent
4214fc7502
commit
4eb6b51f34
@ -9,6 +9,7 @@ import Descriptions from '../../descriptions';
|
|||||||
import Divider from '../../divider';
|
import Divider from '../../divider';
|
||||||
import Empty from '../../empty';
|
import Empty from '../../empty';
|
||||||
import Image from '../../image';
|
import Image from '../../image';
|
||||||
|
import Input from '../../input';
|
||||||
import Mentions from '../../mentions';
|
import Mentions from '../../mentions';
|
||||||
import Modal from '../../modal';
|
import Modal from '../../modal';
|
||||||
import Pagination from '../../pagination';
|
import Pagination from '../../pagination';
|
||||||
@ -256,6 +257,43 @@ describe('ConfigProvider support style and className props', () => {
|
|||||||
expect(element).toHaveStyle({ backgroundColor: 'red' });
|
expect(element).toHaveStyle({ backgroundColor: 'red' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Should Input className & style & classNames & styles works', () => {
|
||||||
|
const { container } = render(
|
||||||
|
<ConfigProvider
|
||||||
|
input={{
|
||||||
|
className: 'cp-input',
|
||||||
|
style: { backgroundColor: 'red' },
|
||||||
|
classNames: {
|
||||||
|
input: 'cp-classNames-input',
|
||||||
|
prefix: 'cp-classNames-prefix',
|
||||||
|
},
|
||||||
|
styles: {
|
||||||
|
input: {
|
||||||
|
color: 'blue',
|
||||||
|
},
|
||||||
|
prefix: {
|
||||||
|
color: 'black',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Input placeholder="Basic usage" prefix="¥" />
|
||||||
|
</ConfigProvider>,
|
||||||
|
);
|
||||||
|
|
||||||
|
const wrapperElement = container.querySelector<HTMLDivElement>('.ant-input-affix-wrapper');
|
||||||
|
expect(wrapperElement).toHaveClass('cp-input');
|
||||||
|
expect(wrapperElement).toHaveStyle({ backgroundColor: 'red' });
|
||||||
|
|
||||||
|
const prefixElement = container.querySelector<HTMLDivElement>('.ant-input-prefix');
|
||||||
|
expect(prefixElement).toHaveClass('cp-classNames-prefix');
|
||||||
|
expect(prefixElement).toHaveStyle({ color: 'black' });
|
||||||
|
|
||||||
|
const inputElement = container.querySelector<HTMLDivElement>('.ant-input');
|
||||||
|
expect(inputElement).toHaveClass('cp-classNames-input');
|
||||||
|
expect(inputElement).toHaveStyle({ color: 'blue' });
|
||||||
|
});
|
||||||
|
|
||||||
it('Should Mentions className & style works', () => {
|
it('Should Mentions className & style works', () => {
|
||||||
const { container } = render(
|
const { container } = render(
|
||||||
<ConfigProvider
|
<ConfigProvider
|
||||||
|
@ -3,6 +3,7 @@ import * as React from 'react';
|
|||||||
import type { Options } from 'scroll-into-view-if-needed';
|
import type { Options } from 'scroll-into-view-if-needed';
|
||||||
import type { ButtonProps } from '../button';
|
import type { ButtonProps } from '../button';
|
||||||
import type { RequiredMark } from '../form/Form';
|
import type { RequiredMark } from '../form/Form';
|
||||||
|
import type { InputProps } from '../input';
|
||||||
import type { Locale } from '../locale';
|
import type { Locale } from '../locale';
|
||||||
import type { SpaceProps } from '../space';
|
import type { SpaceProps } from '../space';
|
||||||
import type { AliasToken, MapToken, OverrideToken, SeedToken } from '../theme/interface';
|
import type { AliasToken, MapToken, OverrideToken, SeedToken } from '../theme/interface';
|
||||||
@ -57,8 +58,10 @@ export interface ConfigConsumerProps {
|
|||||||
renderEmpty?: RenderEmptyHandler;
|
renderEmpty?: RenderEmptyHandler;
|
||||||
csp?: CSPConfig;
|
csp?: CSPConfig;
|
||||||
autoInsertSpaceInButton?: boolean;
|
autoInsertSpaceInButton?: boolean;
|
||||||
input?: {
|
input?: ComponentStyleConfig & {
|
||||||
autoComplete?: string;
|
autoComplete?: string;
|
||||||
|
classNames?: InputProps['classNames'];
|
||||||
|
styles?: InputProps['styles'];
|
||||||
};
|
};
|
||||||
pagination?: ComponentStyleConfig & { showSizeChanger?: boolean };
|
pagination?: ComponentStyleConfig & { showSizeChanger?: boolean };
|
||||||
locale?: Locale;
|
locale?: Locale;
|
||||||
|
@ -111,14 +111,14 @@ const {
|
|||||||
| empty | Set Empty common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| empty | Set Empty common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
| form | Set Form common props | { validateMessages?: [ValidateMessages](/components/form/#validatemessages), requiredMark?: boolean \| `optional`, scrollToFirstError?: boolean \| [Options](https://github.com/stipsan/scroll-into-view-if-needed/tree/ece40bd9143f48caf4b99503425ecb16b0ad8249#options) } | - | requiredMark: 4.8.0; colon: 4.18.0; scrollToFirstError: 5.2.0 |
|
| form | Set Form common props | { validateMessages?: [ValidateMessages](/components/form/#validatemessages), requiredMark?: boolean \| `optional`, scrollToFirstError?: boolean \| [Options](https://github.com/stipsan/scroll-into-view-if-needed/tree/ece40bd9143f48caf4b99503425ecb16b0ad8249#options) } | - | requiredMark: 4.8.0; colon: 4.18.0; scrollToFirstError: 5.2.0 |
|
||||||
| image | Set Image common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| image | Set Image common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
| input | Set Input common props | { autoComplete?: string } | - | 4.2.0 |
|
| input | Set Input common props | { autoComplete?: string, className?: string, style?: React.CSSProperties } | - | 4.2.0 |
|
||||||
| mentions | Set Mentions common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| mentions | Set Mentions common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
| modal | Set Modal common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| modal | Set Modal common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
| pagination | Set Pagination common props | { showSizeChanger?: boolean, className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| pagination | Set Pagination common props | { showSizeChanger?: boolean, className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
| radio | Set Radio common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| radio | Set Radio common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
| result | Set Result common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| result | Set Result common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
| segmented | Set Segmented common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| segmented | Set Segmented common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
| select | Set Select common props | { className?: string, showSearch?: boolean, style?: React.CSSProperties } | - | |
|
| select | Set Select common props | { className?: string, showSearch?: boolean, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
| slider | Set Slider common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| slider | Set Slider common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
| space | Set Space common props, ref [Space](/components/space) | { size: `small` \| `middle` \| `large` \| `number`, className?: string, style?: React.CSSProperties, classNames?: { item: string }, styles?: { item: React.CSSProperties } } | - | 5.6.0 |
|
| space | Set Space common props, ref [Space](/components/space) | { size: `small` \| `middle` \| `large` \| `number`, className?: string, style?: React.CSSProperties, classNames?: { item: string }, styles?: { item: React.CSSProperties } } | - | 5.6.0 |
|
||||||
| spin | Set Spin common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| spin | Set Spin common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
|
@ -9,6 +9,7 @@ import type { Options } from 'scroll-into-view-if-needed';
|
|||||||
import warning from '../_util/warning';
|
import warning from '../_util/warning';
|
||||||
import type { RequiredMark } from '../form/Form';
|
import type { RequiredMark } from '../form/Form';
|
||||||
import ValidateMessagesContext from '../form/validateMessagesContext';
|
import ValidateMessagesContext from '../form/validateMessagesContext';
|
||||||
|
import type { InputProps } from '../input';
|
||||||
import type { Locale } from '../locale';
|
import type { Locale } from '../locale';
|
||||||
import LocaleProvider, { ANT_MARK } from '../locale';
|
import LocaleProvider, { ANT_MARK } from '../locale';
|
||||||
import type { LocaleContextProps } from '../locale/context';
|
import type { LocaleContextProps } from '../locale/context';
|
||||||
@ -107,7 +108,9 @@ export interface ConfigProviderProps {
|
|||||||
colon?: boolean;
|
colon?: boolean;
|
||||||
scrollToFirstError?: Options | boolean;
|
scrollToFirstError?: Options | boolean;
|
||||||
};
|
};
|
||||||
input?: {
|
input?: ComponentStyleConfig & {
|
||||||
|
classNames?: InputProps['classNames'];
|
||||||
|
styles?: InputProps['styles'];
|
||||||
autoComplete?: string;
|
autoComplete?: string;
|
||||||
};
|
};
|
||||||
select?: ComponentStyleConfig & {
|
select?: ComponentStyleConfig & {
|
||||||
@ -255,6 +258,7 @@ const ProviderChildren: React.FC<ProviderChildrenProps> = (props) => {
|
|||||||
slider,
|
slider,
|
||||||
breadcrumb,
|
breadcrumb,
|
||||||
pagination,
|
pagination,
|
||||||
|
input,
|
||||||
empty,
|
empty,
|
||||||
radio,
|
radio,
|
||||||
} = props;
|
} = props;
|
||||||
@ -318,6 +322,7 @@ const ProviderChildren: React.FC<ProviderChildrenProps> = (props) => {
|
|||||||
divider,
|
divider,
|
||||||
steps,
|
steps,
|
||||||
image,
|
image,
|
||||||
|
input,
|
||||||
mentions,
|
mentions,
|
||||||
modal,
|
modal,
|
||||||
result,
|
result,
|
||||||
|
@ -113,14 +113,14 @@ const {
|
|||||||
| empty | 设置 Empty 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| empty | 设置 Empty 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
| form | 设置 Form 组件的通用属性 | { validateMessages?: [ValidateMessages](/components/form-cn#validatemessages), requiredMark?: boolean \| `optional`, colon?: boolean, scrollToFirstError?: boolean \| [Options](https://github.com/stipsan/scroll-into-view-if-needed/tree/ece40bd9143f48caf4b99503425ecb16b0ad8249#options)} | - | requiredMark: 4.8.0; colon: 4.18.0; scrollToFirstError: 5.2.0 |
|
| form | 设置 Form 组件的通用属性 | { validateMessages?: [ValidateMessages](/components/form-cn#validatemessages), requiredMark?: boolean \| `optional`, colon?: boolean, scrollToFirstError?: boolean \| [Options](https://github.com/stipsan/scroll-into-view-if-needed/tree/ece40bd9143f48caf4b99503425ecb16b0ad8249#options)} | - | requiredMark: 4.8.0; colon: 4.18.0; scrollToFirstError: 5.2.0 |
|
||||||
| image | 设置 Image 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| image | 设置 Image 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
| input | 设置 Input 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| input | 设置 Input 组件的通用属性 | { autoComplete?: string, className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
| mentions | 设置 Mentions 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| mentions | 设置 Mentions 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
| modal | 设置 Modal 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| modal | 设置 Modal 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
| pagination | 设置 Pagination 组件的通用属性 | { showSizeChanger?: boolean, className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| pagination | 设置 Pagination 组件的通用属性 | { showSizeChanger?: boolean, className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
| radio | 设置 Radio 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| radio | 设置 Radio 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
| result | 设置 Result 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| result | 设置 Result 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
| segmented | 设置 Segmented 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| segmented | 设置 Segmented 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
| select | 设置 Select 组件的通用属性 | { className?: string, showSearch?: boolean, style?: React.CSSProperties } | - | |
|
| select | 设置 Select 组件的通用属性 | { className?: string, showSearch?: boolean, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
| slider | 设置 Slider 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| slider | 设置 Slider 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
| space | 设置 Space 的通用属性,参考 [Space](/components/space-cn) | { size: `small` \| `middle` \| `large` \| `number`, className?: string, style?: React.CSSProperties, classNames?: { item: string }, styles?: { item: React.CSSProperties } } | - | 5.6.0 |
|
| space | 设置 Space 的通用属性,参考 [Space](/components/space-cn) | { size: `small` \| `middle` \| `large` \| `number`, className?: string, style?: React.CSSProperties, classNames?: { item: string }, styles?: { item: React.CSSProperties } } | - | 5.6.0 |
|
||||||
| spin | 设置 Spin 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| spin | 设置 Spin 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
|
@ -80,6 +80,8 @@ const Input = forwardRef<InputRef, InputProps>((props, ref) => {
|
|||||||
addonAfter,
|
addonAfter,
|
||||||
addonBefore,
|
addonBefore,
|
||||||
className,
|
className,
|
||||||
|
style,
|
||||||
|
styles,
|
||||||
rootClassName,
|
rootClassName,
|
||||||
onChange,
|
onChange,
|
||||||
classNames: classes,
|
classNames: classes,
|
||||||
@ -163,9 +165,11 @@ const Input = forwardRef<InputRef, InputProps>((props, ref) => {
|
|||||||
disabled={mergedDisabled}
|
disabled={mergedDisabled}
|
||||||
onBlur={handleBlur}
|
onBlur={handleBlur}
|
||||||
onFocus={handleFocus}
|
onFocus={handleFocus}
|
||||||
|
style={{ ...input?.style, ...style }}
|
||||||
|
styles={{ ...input?.styles, ...styles }}
|
||||||
suffix={suffixNode}
|
suffix={suffixNode}
|
||||||
allowClear={mergedAllowClear}
|
allowClear={mergedAllowClear}
|
||||||
className={classNames(className, rootClassName, compactItemClassnames)}
|
className={classNames(className, rootClassName, compactItemClassnames, input?.className)}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
addonAfter={
|
addonAfter={
|
||||||
addonAfter && (
|
addonAfter && (
|
||||||
@ -187,6 +191,7 @@ const Input = forwardRef<InputRef, InputProps>((props, ref) => {
|
|||||||
}
|
}
|
||||||
classNames={{
|
classNames={{
|
||||||
...classes,
|
...classes,
|
||||||
|
...input?.classNames,
|
||||||
input: classNames(
|
input: classNames(
|
||||||
{
|
{
|
||||||
[`${prefixCls}-sm`]: mergedSize === 'small',
|
[`${prefixCls}-sm`]: mergedSize === 'small',
|
||||||
@ -196,6 +201,7 @@ const Input = forwardRef<InputRef, InputProps>((props, ref) => {
|
|||||||
},
|
},
|
||||||
!inputHasPrefixSuffix && getStatusClassNames(prefixCls, mergedStatus),
|
!inputHasPrefixSuffix && getStatusClassNames(prefixCls, mergedStatus),
|
||||||
classes?.input,
|
classes?.input,
|
||||||
|
input?.classNames?.input,
|
||||||
hashId,
|
hashId,
|
||||||
),
|
),
|
||||||
}}
|
}}
|
||||||
|
Loading…
Reference in New Issue
Block a user