mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-18 22:36:31 +08:00
warning if user use inputValue
This commit is contained in:
parent
1b3a9d8656
commit
4cac0a9822
@ -4,6 +4,7 @@ import Select from '..';
|
||||
import Icon from '../../icon';
|
||||
import focusTest from '../../../tests/shared/focusTest';
|
||||
import mountTest from '../../../tests/shared/mountTest';
|
||||
import { resetWarned } from '../../_util/warning';
|
||||
|
||||
const { Option } = Select;
|
||||
|
||||
@ -132,4 +133,16 @@ describe('Select', () => {
|
||||
expect(wrapper.render()).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
it('warning if user use `inputValue`', () => {
|
||||
resetWarned();
|
||||
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||
|
||||
mount(<Select inputValue="" />);
|
||||
expect(errorSpy).toHaveBeenLastCalledWith(
|
||||
'Warning: [antd: Select] `inputValue` is deprecated. Please use `searchValue` instead.',
|
||||
);
|
||||
|
||||
errorSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
|
@ -45,6 +45,7 @@ Select component to select value from options.
|
||||
| optionFilterProp | Which prop value of option will be used for filter if filterOption is true | string | value | |
|
||||
| optionLabelProp | Which prop value of option will render as content of select. [Example](https://codesandbox.io/s/antd-reproduction-template-tk678) | string | `value` for `combobox`, `children` for other modes | |
|
||||
| placeholder | Placeholder of select | string\|ReactNode | - | |
|
||||
| searchValue | Search input value | string | - | 3.23.2 |
|
||||
| showArrow | Whether to show the drop-down arrow | boolean | true | 3.2.1 |
|
||||
| showSearch | Whether show search input in single mode. | boolean | false | |
|
||||
| size | Size of Select input. `default` `large` `small` | string | default | |
|
||||
@ -54,7 +55,6 @@ Select component to select value from options.
|
||||
| menuItemSelectedIcon | The custom menuItemSelected icon with multiple options | ReactNode | - | 3.11.0 |
|
||||
| tokenSeparators | Separator used to tokenize on tag/multiple mode | string\[] | | |
|
||||
| value | Current selected option. | string\|string\[]\<br />number\|number\[]\<br />LabeledValue\|LabeledValue[] | - | |
|
||||
| inputValue | Current search text | string | - | |
|
||||
| onBlur | Called when blur | function | - | |
|
||||
| onChange | Called when select an option or input value change, or value of input is changed in combobox mode | function(value, option:Option/Array<Option>) | - | |
|
||||
| onDeselect | Called when a option is deselected, param is the selected option's value. Only called for multiple or tags, effective in multiple or tags mode only. | function(string\|number\|LabeledValue) | - | |
|
||||
|
@ -54,6 +54,7 @@ export type SelectValue = string | string[] | number | number[] | LabeledValue |
|
||||
export interface SelectProps<T = SelectValue> extends AbstractSelectProps {
|
||||
value?: T;
|
||||
inputValue?: string;
|
||||
searchValue?: string;
|
||||
defaultValue?: T;
|
||||
mode?: 'default' | 'multiple' | 'tags' | 'combobox' | string;
|
||||
optionLabelProp?: string;
|
||||
@ -110,9 +111,6 @@ const SelectPropTypes = {
|
||||
id: PropTypes.string,
|
||||
};
|
||||
|
||||
// => It is needless to export the declaration of below two inner components.
|
||||
// export { Option, OptGroup };
|
||||
|
||||
export default class Select<T = SelectValue> extends React.Component<SelectProps<T>, {}> {
|
||||
static Option = Option as React.ClassicComponentClass<OptionProps>;
|
||||
|
||||
@ -140,6 +138,12 @@ export default class Select<T = SelectValue> extends React.Component<SelectProps
|
||||
'it will be removed in next major version, ' +
|
||||
'please use AutoComplete instead',
|
||||
);
|
||||
|
||||
warning(
|
||||
!('inputValue' in props),
|
||||
'Select',
|
||||
'`inputValue` is deprecated. Please use `searchValue` instead.',
|
||||
);
|
||||
}
|
||||
|
||||
getNotFoundContent(renderEmpty: RenderEmptyHandler) {
|
||||
@ -153,14 +157,6 @@ export default class Select<T = SelectValue> extends React.Component<SelectProps
|
||||
}
|
||||
|
||||
return renderEmpty('Select');
|
||||
|
||||
// if (this.isCombobox()) {
|
||||
// // AutoComplete don't have notFoundContent defaultly
|
||||
// return notFoundContent === undefined ? null : notFoundContent;
|
||||
// }
|
||||
|
||||
// return renderEmpty('Select');
|
||||
// // return notFoundContent === undefined ? locale.notFoundContent : notFoundContent;
|
||||
}
|
||||
|
||||
saveSelect = (node: any) => {
|
||||
@ -210,6 +206,8 @@ export default class Select<T = SelectValue> extends React.Component<SelectProps
|
||||
clearIcon,
|
||||
menuItemSelectedIcon,
|
||||
showArrow,
|
||||
inputValue,
|
||||
searchValue,
|
||||
...restProps
|
||||
} = this.props;
|
||||
const rest = omit(restProps, ['inputIcon']);
|
||||
@ -271,6 +269,7 @@ export default class Select<T = SelectValue> extends React.Component<SelectProps
|
||||
showArrow={showArrow}
|
||||
{...rest}
|
||||
{...modeConfig}
|
||||
inputValue={searchValue || inputValue}
|
||||
prefixCls={prefixCls}
|
||||
className={cls}
|
||||
optionLabelProp={optionLabelProp || 'children'}
|
||||
|
@ -46,6 +46,7 @@ title: Select
|
||||
| optionFilterProp | 搜索时过滤对应的 option 属性,如设置为 children 表示对内嵌内容进行搜索。[示例](https://codesandbox.io/s/antd-reproduction-template-tk678) | string | value | |
|
||||
| optionLabelProp | 回填到选择框的 Option 的属性值,默认是 Option 的子元素。比如在子元素需要高亮效果时,此值可以设为 `value`。 | string | `children` (combobox 模式下为 `value`) | |
|
||||
| placeholder | 选择框默认文字 | string | - | |
|
||||
| searchValue | 搜索框文本 | string | - | 3.23.2 |
|
||||
| showArrow | 是否显示下拉小箭头 | boolean | true | 3.2.1 |
|
||||
| showSearch | 使单选模式可搜索 | boolean | false | |
|
||||
| size | 选择框大小,可选 `large` `small` | string | default | |
|
||||
|
Loading…
Reference in New Issue
Block a user