MCPcopy Create free account
hub / github.com/react-component/select / warningProps

Function warningProps

src/utils/warningPropsUtil.ts:16–158  ·  view source on GitHub ↗
(props: SelectProps)

Source from the content-addressed store, hash-verified

14import { convertChildrenToData } from './legacyUtil';
15
16function warningProps(props: SelectProps) {
17 const {
18 mode,
19 options,
20 children,
21 backfill,
22 allowClear,
23 placeholder,
24 getInputElement,
25 showSearch,
26 onSearch,
27 defaultOpen,
28 autoFocus,
29 labelInValue,
30 value,
31 inputValue,
32 optionLabelProp,
33 } = props;
34
35 const multiple = isMultiple(mode);
36 const mergedShowSearch = showSearch !== undefined ? showSearch : multiple || mode === 'combobox';
37 const mergedOptions = options || convertChildrenToData(children);
38
39 // `tags` should not set option as disabled
40 warning(
41 mode !== 'tags' || mergedOptions.every((opt: { disabled?: boolean }) => !opt.disabled),
42 'Please avoid setting option to disabled in tags mode since user can always type text as tag.',
43 );
44
45 // `combobox` & `tags` should option be `string` type
46 if (mode === 'tags' || mode === 'combobox') {
47 const hasNumberValue = mergedOptions.some((item) => {
48 if (item.options) {
49 return item.options.some(
50 (opt: BaseOptionType) => typeof ('value' in opt ? opt.value : opt.key) === 'number',
51 );
52 }
53 return typeof ('value' in item ? item.value : item.key) === 'number';
54 });
55
56 warning(
57 !hasNumberValue,
58 '`value` of Option should not use number type when `mode` is `tags` or `combobox`.',
59 );
60 }
61
62 // `combobox` should not use `optionLabelProp`
63 warning(
64 mode !== 'combobox' || !optionLabelProp,
65 '`combobox` mode not support `optionLabelProp`. Please set `value` on Option directly.',
66 );
67
68 // Only `combobox` support `backfill`
69 warning(mode === 'combobox' || !backfill, '`backfill` only works with `combobox` mode.');
70
71 // Only `combobox` support `getInputElement`
72 warning(
73 mode === 'combobox' || !getInputElement,

Callers 1

Select.tsxFile · 0.85

Calls 3

isMultipleFunction · 0.90
convertChildrenToDataFunction · 0.90
toArrayFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…