Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
showSearch,
onSearch,
defaultOpen,
autoFocus,
labelInValue,
value,
inputValue,
optionLabelProp,
} = props;
const multiple = mode === 'multiple' || mode === 'tags';
const mergedShowSearch = showSearch !== undefined ? showSearch : multiple || mode === 'combobox';
const mergedOptions = options || convertChildrenToData(children);
// `tags` should not set option as disabled
warning(
mode !== 'tags' ||
mergedOptions.every((opt: { disabled?: boolean } & OptionGroupData) => !opt.disabled),
'Please avoid setting option to disabled in tags mode since user can always type text as tag.',
);
// `combobox` & `tags` should option be `string` type
if (mode === 'tags' || mode === 'combobox') {
const hasNumberValue = mergedOptions.some(item => {
if (item.options) {
return item.options.some(
(opt: OptionData) => typeof ('value' in opt ? opt.value : opt.key) === 'number',
);
}
return typeof ('value' in item ? item.value : item.key) === 'number';
});
if (item.options) {
return item.options.some(
(opt: OptionData) => typeof ('value' in opt ? opt.value : opt.key) === 'number',
);
}
return typeof ('value' in item ? item.value : item.key) === 'number';
});
warning(
!hasNumberValue,
'`value` of Option should not use number type when `mode` is `tags` or `combobox`.',
);
}
// `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,
!hasNumberValue,
'`value` of Option should not use number type when `mode` is `tags` or `combobox`.',
);
}
// `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(
}
// [Legacy] Support `key` as `value`
return prevItem.key === value;
}) as LabelValueType;
}
if (prevValItem && typeof prevValItem === 'object' && 'label' in prevValItem) {
result.label = prevValItem.label;
if (
item &&
typeof prevValItem.label === 'string' &&
typeof item[optionLabelProp] === 'string' &&
prevValItem.label.trim() !== item[optionLabelProp].trim()
) {
warning(false, '`label` of `value` is not same as `label` in Select options.');
}
} else if (item && optionLabelProp in item) {
result.label = item[optionLabelProp];
} else {
result.label = value;
}
// [Legacy] We need fill `key` as `value` to compatible old code usage
result.key = result.value;
return result;
};
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 \`${invalidateChildType.displayName ||
invalidateChildType.name ||
invalidateChildType}\`.`,
);
}
warning(
inputValue === undefined,
'`inputValue` is deprecated, please use `searchValue` instead.',
);
}
}
function warningFixed(flattenColumns: { fixed?: FixedType }[]) {
let allFixLeft = true;
for (let i = 0; i < flattenColumns.length; i += 1) {
const col = flattenColumns[i];
if (allFixLeft && col.fixed !== 'left') {
allFixLeft = false;
} else if (!allFixLeft && col.fixed === 'left') {
warning(false, `Index ${i - 1} of \`columns\` missing \`fixed='left'\` prop.`);
break;
}
}
let allFixRight = true;
for (let i = flattenColumns.length - 1; i >= 0; i -= 1) {
const col = flattenColumns[i];
if (allFixRight && col.fixed !== 'right') {
allFixRight = false;
} else if (!allFixRight && col.fixed === 'right') {
warning(false, `Index ${i + 1} of \`columns\` missing \`fixed='right'\` prop.`);
break;
}
}
}
get() {
warning(
false,
'Return type is option instead of Option instance. Please read value directly instead of reading from `props`.',
);
return newOption;
},
});
headerProps.colWidths = flattenColumns.map(({ width }, index) => {
const colWidth = index === columns.length - 1 ? (width as number) - scrollbarSize : width;
if (typeof colWidth === 'number' && !Number.isNaN(colWidth)) {
return colWidth;
}
warning(
false,
'When use `components.body` with render props. Each column should have a fixed value.',
);
return 0;
}) as number[];
} else {
export function warning(valid: boolean, message: string) {
warn(valid, `[@ant-design/icons] ${message}`);
}
export function getMotion({
prefixCls,
motion,
openAnimation,
openTransitionName,
}: GetMotionProps): MotionType {
if (motion) {
return motion;
}
if (typeof openAnimation === 'object' && openAnimation) {
warning(
false,
'Object type of `openAnimation` is removed. Please use `motion` instead.',
);
} else if (typeof openAnimation === 'string') {
return {
motionName: `${prefixCls}-open-${openAnimation}`,
};
}
if (openTransitionName) {
return {
motionName: openTransitionName,
};
}
return null;