ant-design-vue
Version:
An enterprise-class UI design language and Vue-based implementation
85 lines • 4.22 kB
JavaScript
import _typeof from "@babel/runtime/helpers/esm/typeof";
import warning, { noteOnce } from '../../vc-util/warning';
import { convertChildrenToData } from './legacyUtil';
import { toArray } from './commonUtil';
import { isValidElement } from '../../_util/props-util';
import { isMultiple } from '../BaseSelect';
function warningProps(props) {
var mode = props.mode,
options = props.options,
children = props.children,
backfill = props.backfill,
allowClear = props.allowClear,
placeholder = props.placeholder,
getInputElement = props.getInputElement,
showSearch = props.showSearch,
onSearch = props.onSearch,
defaultOpen = props.defaultOpen,
autofocus = props.autofocus,
labelInValue = props.labelInValue,
value = props.value,
inputValue = props.inputValue,
optionLabelProp = props.optionLabelProp;
var multiple = isMultiple(mode);
var mergedShowSearch = showSearch !== undefined ? showSearch : multiple || mode === 'combobox';
var mergedOptions = options || convertChildrenToData(children);
// `tags` should not set option as disabled
warning(mode !== 'tags' || mergedOptions.every(function (opt) {
return !opt.disabled;
}), 'Please avoid setting option to disabled in tags mode since user can always type text as tag.');
// `combobox` should not use `optionLabelProp`
warning(mode !== 'combobox' || !optionLabelProp, '`combobox` mode not support `optionLabelProp`. Please set `value` on Option directly.');
// Only `combobox` support `backfill`
warning(mode === 'combobox' || !backfill, '`backfill` only works with `combobox` mode.');
// Only `combobox` support `getInputElement`
warning(mode === 'combobox' || !getInputElement, '`getInputElement` only work with `combobox` mode.');
// Customize `getInputElement` should not use `allowClear` & `placeholder`
noteOnce(mode !== 'combobox' || !getInputElement || !allowClear || !placeholder, 'Customize `getInputElement` should customize clear and placeholder logic instead of configuring `allowClear` and `placeholder`.');
// `onSearch` should use in `combobox` or `showSearch`
if (onSearch && !mergedShowSearch && mode !== 'combobox' && mode !== 'tags') {
warning(false, '`onSearch` should work with `showSearch` instead of use alone.');
}
noteOnce(!defaultOpen || autofocus, '`defaultOpen` makes Select open without focus which means it will not close by click outside. You can set `autofocus` if needed.');
if (value !== undefined && value !== null) {
var values = toArray(value);
warning(!labelInValue || values.every(function (val) {
return _typeof(val) === 'object' && ('key' in val || 'value' in val);
}), '`value` should in shape of `{ value: string | number, label?: any }` when you set `labelInValue` to `true`');
warning(!multiple || Array.isArray(value), '`value` should be array when `mode` is `multiple` or `tags`');
}
// Syntactic sugar should use correct children type
if (children) {
var invalidateChildType = null;
children.some(function (node) {
if (!isValidElement(node) || !node.type) {
return false;
}
var type = node.type;
if (type.isSelectOption) {
return false;
}
if (type.isSelectOptGroup) {
var _node$children;
var childs = ((_node$children = node.children) === null || _node$children === void 0 ? void 0 : _node$children.default()) || [];
var allChildrenValid = childs.every(function (subNode) {
if (!isValidElement(subNode) || !node.type || subNode.type.isSelectOption) {
return true;
}
invalidateChildType = subNode.type;
return false;
});
if (allChildrenValid) {
return false;
}
return true;
}
invalidateChildType = type;
return true;
});
if (invalidateChildType) {
warning(false, "`children` should be `Select.Option` or `Select.OptGroup` instead of `".concat(invalidateChildType.displayName || invalidateChildType.name || invalidateChildType, "`."));
}
warning(inputValue === undefined, '`inputValue` is deprecated, please use `searchValue` instead.');
}
}
export default warningProps;