Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions src/BaseSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import KeyCode from 'rc-util/lib/KeyCode';
import isMobile from 'rc-util/lib/isMobile';
import { useComposeRef } from 'rc-util/lib/ref';
import type { ScrollTo } from 'rc-virtual-list/lib/List';
import pickAttrs from 'rc-util/lib/pickAttrs';
import useMergedState from 'rc-util/lib/hooks/useMergedState';
import useLayoutEffect from 'rc-util/lib/hooks/useLayoutEffect';
import { getSeparatedContent } from './utils/valueUtil';
Expand All @@ -21,12 +20,17 @@ import { BaseSelectContext } from './hooks/useBaseProps';
const DEFAULT_OMIT_PROPS = [
'value',
'onChange',
'onSelect',
'removeIcon',
'placeholder',
'autoFocus',
'maxTagCount',
'maxTagTextLength',
'maxTagPlaceholder',
'choiceTransitionName',
'onInputKeyDown',
'onPopupScroll',
'tabIndex',
];
] as const;

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

Expand Down Expand Up @@ -69,6 +73,7 @@ export interface BaseSelectPrivateProps {
// >>> MISC
id: string;
prefixCls: string;
omitProps?: string[];

// >>> Value
displayValues: DisplayValueType[];
Expand Down Expand Up @@ -197,6 +202,7 @@ const BaseSelect = React.forwardRef((props: BaseSelectProps, ref: React.Ref<Base
showSearch,
tagRender,
direction,
omitProps,

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

const domProps = pickAttrs(restProps, {
aria: true,
attr: true,
data: true,
const domProps = {
...restProps,
} as Omit<keyof typeof restProps, typeof DEFAULT_OMIT_PROPS[number]>;

DEFAULT_OMIT_PROPS.forEach((propName) => {
delete domProps[propName];
});
DEFAULT_OMIT_PROPS.forEach((prop) => {
delete domProps[prop];

omitProps?.forEach((propName) => {
delete domProps[propName];
});

// ============================= Mobile =============================
Expand Down
3 changes: 3 additions & 0 deletions src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ import { toArray } from './utils/commonUtil';
import useFilterOptions from './hooks/useFilterOptions';
import useCache from './hooks/useCache';

const OMIT_PROPS = ['inputValue'];

export type OnActiveValue = (
active: RawValueType,
index: number,
Expand Down Expand Up @@ -625,6 +627,7 @@ const Select = React.forwardRef(
id={mergedId}
prefixCls={prefixCls}
ref={ref}
omitProps={OMIT_PROPS}
// >>> Values
displayValues={displayValues}
onDisplayValuesChange={onDisplayValuesChange}
Expand Down
13 changes: 13 additions & 0 deletions tests/Select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1712,4 +1712,17 @@ describe('Select.Basic', () => {
wrapper.update();
ref.current.scrollTo(100);
});

it('pass props', () => {
// `count` is not a valid dom prop. Just compatible with origin logic.
const wrapper = mount(
<Select
{...({
count: 10,
} as any)}
/>,
);

expect(wrapper.find('div.rc-select').prop('count')).toEqual(10);
});
});