Skip to content

Commit

Permalink
feat: ConfigProvider support select.showSearch (#39531)
Browse files Browse the repository at this point in the history
  • Loading branch information
YinDongFang committed Dec 14, 2022
1 parent ec76041 commit bcd3230
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions components/config-provider/__tests__/index.test.tsx
Expand Up @@ -7,6 +7,7 @@ import { act, fireEvent, render } from '../../../tests/utils';
import Button from '../../button';
import Input from '../../input';
import Table from '../../table';
import Select from '../../select';

describe('ConfigProvider', () => {
mountTest(() => (
Expand Down Expand Up @@ -113,6 +114,15 @@ describe('ConfigProvider', () => {
expect(container.querySelector('input')?.autocomplete).toEqual('off');
});

it('select showSearch', () => {
const { container } = render(
<ConfigProvider select={{ showSearch: true }}>
<Select />
</ConfigProvider>,
);
expect(container.querySelectorAll('.ant-select-show-search').length).toBe(1);
});

it('render empty', () => {
let rendered = false;
let cacheRenderEmpty;
Expand Down
3 changes: 3 additions & 0 deletions components/config-provider/context.tsx
Expand Up @@ -63,6 +63,9 @@ export interface ConfigConsumerProps {
colon?: boolean;
};
theme?: ThemeConfig;
select?: {
showSearch?: boolean;
};
}

const defaultGetPrefixCls = (suffixCls?: string, customizePrefixCls?: string) => {
Expand Down
1 change: 1 addition & 0 deletions components/config-provider/index.en-US.md
Expand Up @@ -57,6 +57,7 @@ Some components use dynamic style to support wave effect. You can config `csp` p
| getTargetContainer | Config Affix, Anchor scroll target container | () => HTMLElement | () => window | 4.2.0 |
| iconPrefixCls | Set icon prefix className | string | `anticon` | 4.11.0 |
| input | Set Input common props | { autoComplete?: string } | - | 4.2.0 |
| select | Set Select common props | { showSearch?: boolean } | - | |
| locale | Language package setting, you can find the packages in [antd/locale](http://unpkg.com/antd/locale/) | object | - | |
| prefixCls | Set prefix className | string | `ant` | |
| renderEmpty | Set empty content of components. Ref [Empty](/components/empty/) | function(componentName: string): ReactNode | - | |
Expand Down
4 changes: 4 additions & 0 deletions components/config-provider/index.tsx
Expand Up @@ -53,6 +53,7 @@ const PASSED_PROPS: Exclude<keyof ConfigConsumerProps, 'rootPrefixCls' | 'getPre
'input',
'pagination',
'form',
'select',
];

export interface ConfigProviderProps {
Expand All @@ -72,6 +73,9 @@ export interface ConfigProviderProps {
input?: {
autoComplete?: string;
};
select?: {
showSearch?: boolean;
};
pagination?: {
showSizeChanger?: boolean;
};
Expand Down
1 change: 1 addition & 0 deletions components/config-provider/index.zh-CN.md
Expand Up @@ -58,6 +58,7 @@ export default () => (
| getTargetContainer | 配置 Affix、Anchor 滚动监听容器。 | () => HTMLElement | () => window | 4.2.0 |
| iconPrefixCls | 设置图标统一样式前缀 | string | `anticon` | 4.11.0 |
| input | 设置 Input 组件的通用属性 | { autoComplete?: string } | - | 4.2.0 |
| select | 设置 Select 组件的通用属性 | { showSearch?: boolean } | - | |
| locale | 语言包配置,语言包可到 [antd/locale](http://unpkg.com/antd/locale/) 目录下寻找 | object | - | |
| prefixCls | 设置统一样式前缀 | string | `ant` | |
| renderEmpty | 自定义组件空状态。参考 [空状态](/components/empty/) | function(componentName: string): ReactNode | - | |
Expand Down
2 changes: 2 additions & 0 deletions components/select/index.tsx
Expand Up @@ -91,6 +91,7 @@ const InternalSelect = <OptionType extends BaseOptionType | DefaultOptionType =
direction,
virtual,
dropdownMatchSelectWidth,
select,
} = React.useContext(ConfigContext);
const size = React.useContext(SizeContext);

Expand Down Expand Up @@ -202,6 +203,7 @@ const InternalSelect = <OptionType extends BaseOptionType | DefaultOptionType =
ref={ref as any}
virtual={virtual}
dropdownMatchSelectWidth={dropdownMatchSelectWidth}
showSearch={select?.showSearch}
{...selectProps}
transitionName={getTransitionName(
rootPrefixCls,
Expand Down

0 comments on commit bcd3230

Please sign in to comment.