Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ConfigProvider support config Input autoComplete #23455

Merged
merged 3 commits into from Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions components/config-provider/__tests__/index.test.js
Expand Up @@ -3,6 +3,7 @@ import { mount } from 'enzyme';
import ConfigProvider from '..';
import Button from '../../button';
import Table from '../../table';
import Input from '../../input';
import mountTest from '../../../tests/shared/mountTest';

describe('ConfigProvider', () => {
Expand Down Expand Up @@ -54,4 +55,14 @@ describe('ConfigProvider', () => {

expect(wrapper.find('button').props().className).toEqual('bamboo-btn');
});

it('input autoComplete', () => {
const wrapper = mount(
<ConfigProvider input={{ autoComplete: 'off' }}>
<Input />
</ConfigProvider>,
);

expect(wrapper.find('input').props().autoComplete).toEqual('off');
});
});
3 changes: 3 additions & 0 deletions components/config-provider/context.tsx
Expand Up @@ -14,6 +14,9 @@ export interface ConfigConsumerProps {
renderEmpty: RenderEmptyHandler;
csp?: CSPConfig;
autoInsertSpaceInButton?: boolean;
input?: {
autoComplete?: string;
};
locale?: Locale;
pageHeader?: {
ghost: boolean;
Expand Down
1 change: 1 addition & 0 deletions components/config-provider/index.en-US.md
Expand Up @@ -41,6 +41,7 @@ Some components use dynamic style to support wave effect. You can config `csp` p
| componentSize | Config antd component size | `small` \| `middle` \| `large` | - | |
| csp | Set [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) config | { nonce: string } | - | |
| form | Set Form common props | { validateMessages?: [ValidateMessages](/components/form/#validateMessages) } | - | |
| input | Set Input common props | { autoComplete?: string } | - | 4.2.0 |
| renderEmpty | set empty content of components. Ref [Empty](/components/empty/) | Function(componentName: string): ReactNode | - | |
| getPopupContainer | to set the container of the popup element. The default is to create a `div` element in `body`. | Function(triggerNode) | `() => document.body` | |
| locale | language package setting, you can find the packages in [antd/es/locale](http://unpkg.com/antd/es/locale/) | object | |
Expand Down
8 changes: 8 additions & 0 deletions components/config-provider/index.tsx
Expand Up @@ -33,6 +33,9 @@ export interface ConfigProviderProps {
form?: {
validateMessages?: ValidateMessages;
};
input?: {
autoComplete?: string;
};
locale?: Locale;
pageHeader?: {
ghost: boolean;
Expand Down Expand Up @@ -65,6 +68,7 @@ class ConfigProvider extends React.Component<ConfigProviderProps> {
csp,
autoInsertSpaceInButton,
form,
input,
locale,
pageHeader,
componentSize,
Expand Down Expand Up @@ -94,6 +98,10 @@ class ConfigProvider extends React.Component<ConfigProviderProps> {
config.pageHeader = pageHeader;
}

if (input) {
config.input = input;
}

let childNode = children;

// Additional Form provider
Expand Down
1 change: 1 addition & 0 deletions components/config-provider/index.zh-CN.md
Expand Up @@ -42,6 +42,7 @@ return (
| componentSize | 设置 antd 组件大小 | `small` \| `middle` \| `large` | - | |
| csp | 设置 [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) 配置 | { nonce: string } | - | |
| form | 设置 Form 组件的通用属性 | { validateMessages?: [ValidateMessages](/components/form/#validateMessages) } | - | |
| input | 设置 Input 组件的通用属性 | { autoComplete?: string } | - | 4.2.0 |
| renderEmpty | 自定义组件空状态。参考 [空状态](/components/empty/) | Function(componentName: string): ReactNode | - | |
| getPopupContainer | 弹出框(Select, Tooltip, Menu 等等)渲染父节点,默认渲染到 body 上。 | Function(triggerNode) | () => document.body | |
| locale | 语言包配置,语言包可到 [antd/es/locale](http://unpkg.com/antd/es/locale/) 目录下寻找 | object | - | |
Expand Down
12 changes: 9 additions & 3 deletions components/input/Input.tsx
Expand Up @@ -217,7 +217,11 @@ class Input extends React.Component<InputProps, InputState> {
resolveOnChange(this.input, e, this.props.onChange);
};

renderInput = (prefixCls: string, size?: SizeType) => {
renderInput = (
prefixCls: string,
size: SizeType | undefined,
input: ConfigConsumerProps['input'] = {},
) => {
const { className, addonBefore, addonAfter, size: customizeSize, disabled } = this.props;
// Fix https://fb.me/react-unknown-prop
const otherProps = omit(this.props, [
Expand All @@ -236,6 +240,7 @@ class Input extends React.Component<InputProps, InputState> {
]);
return (
<input
autoComplete={input.autoComplete}
{...otherProps}
onChange={this.handleChange}
onFocus={this.onFocus}
Expand Down Expand Up @@ -280,11 +285,12 @@ class Input extends React.Component<InputProps, InputState> {
}
};

renderComponent = ({ getPrefixCls, direction }: ConfigConsumerProps) => {
renderComponent = ({ getPrefixCls, direction, input }: ConfigConsumerProps) => {
const { value, focused } = this.state;
const { prefixCls: customizePrefixCls } = this.props;
const prefixCls = getPrefixCls('input', customizePrefixCls);
this.direction = direction;

return (
<SizeContext.Consumer>
{size => (
Expand All @@ -294,7 +300,7 @@ class Input extends React.Component<InputProps, InputState> {
prefixCls={prefixCls}
inputType="input"
value={fixControlledValue(value)}
element={this.renderInput(prefixCls, size)}
element={this.renderInput(prefixCls, size, input)}
handleReset={this.handleReset}
ref={this.saveClearableInput}
direction={direction}
Expand Down