From 092e1e705441ba49674d040d97197185bb587529 Mon Sep 17 00:00:00 2001 From: zombiej Date: Mon, 20 Dec 2021 15:43:15 +0800 Subject: [PATCH 1/2] chore: omit of content --- src/BaseSelect.tsx | 27 ++++++++++++++++++--------- src/Select.tsx | 3 +++ tests/Select.test.tsx | 13 +++++++++++++ 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/BaseSelect.tsx b/src/BaseSelect.tsx index ea173e34e..21b54901c 100644 --- a/src/BaseSelect.tsx +++ b/src/BaseSelect.tsx @@ -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'; @@ -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); @@ -69,6 +73,7 @@ export interface BaseSelectPrivateProps { // >>> MISC id: string; prefixCls: string; + omitProps?: string[]; // >>> Value displayValues: DisplayValueType[]; @@ -197,6 +202,7 @@ const BaseSelect = React.forwardRef((props: BaseSelectProps, ref: React.Ref; + + DEFAULT_OMIT_PROPS.forEach((propName) => { + delete domProps[propName]; }); - DEFAULT_OMIT_PROPS.forEach((prop) => { - delete domProps[prop]; + + omitProps?.forEach((propName) => { + delete domProps[propName]; }); // ============================= Mobile ============================= diff --git a/src/Select.tsx b/src/Select.tsx index 9c1e59425..cc89707ee 100644 --- a/src/Select.tsx +++ b/src/Select.tsx @@ -48,6 +48,8 @@ import { toArray } from './utils/commonUtil'; import useFilterOptions from './hooks/useFilterOptions'; import useCache from './hooks/useCache'; +const OMIT_PROPS = ['inputValue'] as const; + export type OnActiveValue = ( active: RawValueType, index: number, @@ -625,6 +627,7 @@ const Select = React.forwardRef( id={mergedId} prefixCls={prefixCls} ref={ref} + omitProps={OMIT_PROPS} // >>> Values displayValues={displayValues} onDisplayValuesChange={onDisplayValuesChange} diff --git a/tests/Select.test.tsx b/tests/Select.test.tsx index facc4fbfa..2106ab0e0 100644 --- a/tests/Select.test.tsx +++ b/tests/Select.test.tsx @@ -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( +