Skip to content

Commit 4d0e40b

Browse files
authored
chore: omit of content (#689)
* chore: omit of content * fix: compile
1 parent 86feb4a commit 4d0e40b

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

src/BaseSelect.tsx

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import KeyCode from 'rc-util/lib/KeyCode';
44
import isMobile from 'rc-util/lib/isMobile';
55
import { useComposeRef } from 'rc-util/lib/ref';
66
import type { ScrollTo } from 'rc-virtual-list/lib/List';
7-
import pickAttrs from 'rc-util/lib/pickAttrs';
87
import useMergedState from 'rc-util/lib/hooks/useMergedState';
98
import useLayoutEffect from 'rc-util/lib/hooks/useLayoutEffect';
109
import { getSeparatedContent } from './utils/valueUtil';
@@ -21,12 +20,17 @@ import { BaseSelectContext } from './hooks/useBaseProps';
2120
const DEFAULT_OMIT_PROPS = [
2221
'value',
2322
'onChange',
24-
'onSelect',
23+
'removeIcon',
2524
'placeholder',
2625
'autoFocus',
26+
'maxTagCount',
27+
'maxTagTextLength',
28+
'maxTagPlaceholder',
29+
'choiceTransitionName',
2730
'onInputKeyDown',
31+
'onPopupScroll',
2832
'tabIndex',
29-
];
33+
] as const;
3034

3135
export type RenderNode = React.ReactNode | ((props: any) => React.ReactNode);
3236

@@ -69,6 +73,7 @@ export interface BaseSelectPrivateProps {
6973
// >>> MISC
7074
id: string;
7175
prefixCls: string;
76+
omitProps?: string[];
7277

7378
// >>> Value
7479
displayValues: DisplayValueType[];
@@ -197,6 +202,7 @@ const BaseSelect = React.forwardRef((props: BaseSelectProps, ref: React.Ref<Base
197202
showSearch,
198203
tagRender,
199204
direction,
205+
omitProps,
200206

201207
// Value
202208
displayValues,
@@ -269,13 +275,16 @@ const BaseSelect = React.forwardRef((props: BaseSelectProps, ref: React.Ref<Base
269275
const mergedShowSearch =
270276
(showSearch !== undefined ? showSearch : multiple) || mode === 'combobox';
271277

272-
const domProps = pickAttrs(restProps, {
273-
aria: true,
274-
attr: true,
275-
data: true,
278+
const domProps = {
279+
...restProps,
280+
} as Omit<keyof typeof restProps, typeof DEFAULT_OMIT_PROPS[number]>;
281+
282+
DEFAULT_OMIT_PROPS.forEach((propName) => {
283+
delete domProps[propName];
276284
});
277-
DEFAULT_OMIT_PROPS.forEach((prop) => {
278-
delete domProps[prop];
285+
286+
omitProps?.forEach((propName) => {
287+
delete domProps[propName];
279288
});
280289

281290
// ============================= Mobile =============================

src/Select.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ import { toArray } from './utils/commonUtil';
4848
import useFilterOptions from './hooks/useFilterOptions';
4949
import useCache from './hooks/useCache';
5050

51+
const OMIT_PROPS = ['inputValue'];
52+
5153
export type OnActiveValue = (
5254
active: RawValueType,
5355
index: number,
@@ -625,6 +627,7 @@ const Select = React.forwardRef(
625627
id={mergedId}
626628
prefixCls={prefixCls}
627629
ref={ref}
630+
omitProps={OMIT_PROPS}
628631
// >>> Values
629632
displayValues={displayValues}
630633
onDisplayValuesChange={onDisplayValuesChange}

tests/Select.test.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,4 +1712,17 @@ describe('Select.Basic', () => {
17121712
wrapper.update();
17131713
ref.current.scrollTo(100);
17141714
});
1715+
1716+
it('pass props', () => {
1717+
// `count` is not a valid dom prop. Just compatible with origin logic.
1718+
const wrapper = mount(
1719+
<Select
1720+
{...({
1721+
count: 10,
1722+
} as any)}
1723+
/>,
1724+
);
1725+
1726+
expect(wrapper.find('div.rc-select').prop('count')).toEqual(10);
1727+
});
17151728
});

0 commit comments

Comments
 (0)