Skip to content

Commit 5cb28e9

Browse files
committed
feat: Add omitDOMProps to support customize omit
1 parent d905e39 commit 5cb28e9

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

src/Select.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ import generateSelector, { SelectProps, RefSelectProps } from './generate';
4747
import { DefaultValueType } from './interface/generator';
4848
import warningProps from './utils/warningPropsUtil';
4949

50+
const OMIT_PROPS = [
51+
'removeIcon',
52+
'placeholder',
53+
'autoFocus',
54+
'maxTagCount',
55+
'maxTagTextLength',
56+
'maxTagPlaceholder',
57+
'choiceTransitionName',
58+
'onInputKeyDown',
59+
];
60+
5061
const RefSelect = generateSelector<SelectOptionsType>({
5162
prefixCls: 'rc-select',
5263
components: {
@@ -60,6 +71,13 @@ const RefSelect = generateSelector<SelectOptionsType>({
6071
findValueOption: findSelectValueOption,
6172
warningProps,
6273
fillOptionsWithMissingValue,
74+
omitDOMProps: (props: object) => {
75+
const cloneProps = { ...props };
76+
OMIT_PROPS.forEach(prop => {
77+
delete cloneProps[prop];
78+
});
79+
return cloneProps;
80+
},
6381
});
6482

6583
export type SelectProps<ValueType extends DefaultValueType = DefaultValueType> = SelectProps<

src/generate.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ export interface GenerateConfig<OptionsType extends object[]> {
158158
optionLabelProp: string,
159159
labelInValue: boolean,
160160
) => OptionsType;
161+
omitDOMProps: (props: object) => object;
161162
}
162163

163164
/**
@@ -183,6 +184,7 @@ export default function generateSelector<
183184
findValueOption,
184185
warningProps,
185186
fillOptionsWithMissingValue,
187+
omitDOMProps,
186188
} = config;
187189

188190
// Use raw define since `React.FC` not support generic
@@ -219,7 +221,6 @@ export default function generateSelector<
219221
clearIcon,
220222
showArrow,
221223
inputIcon,
222-
removeIcon,
223224
menuItemSelectedIcon,
224225

225226
// Others
@@ -228,11 +229,9 @@ export default function generateSelector<
228229
defaultActiveFirstOption,
229230
notFoundContent = 'Not Found',
230231
optionLabelProp,
231-
placeholder,
232232
backfill,
233233
getInputElement,
234234
getPopupContainer,
235-
autoFocus,
236235

237236
// Dropdown
238237
listHeight = 200,
@@ -247,18 +246,11 @@ export default function generateSelector<
247246
showAction = [],
248247

249248
// Tags
250-
maxTagCount,
251-
maxTagTextLength,
252-
maxTagPlaceholder,
253249
tokenSeparators,
254250

255-
// Motion
256-
choiceTransitionName,
257-
258251
// Events
259252
onPopupScroll,
260253
onDropdownVisibleChange,
261-
onInputKeyDown,
262254
onFocus,
263255
onBlur,
264256
onKeyUp,
@@ -269,9 +261,11 @@ export default function generateSelector<
269261
onSelect,
270262
onDeselect,
271263

272-
...domProps
264+
...restProps
273265
} = props;
274266

267+
const domProps = omitDOMProps(restProps);
268+
275269
const selectorRef = React.useRef<RefSelectorProps>(null);
276270
const listRef = React.useRef<RefOptionListProps>(null);
277271

0 commit comments

Comments
 (0)