1
1
import type { AlignType , BuildInPlacements } from '@rc-component/trigger/lib/interface' ;
2
- import classNames from 'classnames' ;
2
+ import cls from 'classnames' ;
3
3
import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect' ;
4
4
import useMergedState from '@rc-component/util/lib/hooks/useMergedState' ;
5
5
import isMobile from '@rc-component/util/lib/isMobile' ;
@@ -27,8 +27,6 @@ import type { RefTriggerProps } from '../SelectTrigger';
27
27
import SelectTrigger from '../SelectTrigger' ;
28
28
import TransBtn from '../TransBtn' ;
29
29
import { getSeparatedContent , isValidCount } from '../utils/valueUtil' ;
30
- import SelectContext from '../SelectContext' ;
31
- import type { SelectContextProps } from '../SelectContext' ;
32
30
import Polite from './Polite' ;
33
31
export type BaseSelectSemanticName = 'prefix' | 'suffix' | 'input' ;
34
32
@@ -130,22 +128,27 @@ export interface BaseSelectPrivateProps {
130
128
export type BaseSelectPropsWithoutPrivate = Omit < BaseSelectProps , keyof BaseSelectPrivateProps > ;
131
129
132
130
export interface BaseSelectProps extends BaseSelectPrivateProps , React . AriaAttributes {
131
+ // Style
133
132
className ?: string ;
134
133
style ?: React . CSSProperties ;
135
134
classNames ?: Partial < Record < BaseSelectSemanticName , string > > ;
136
135
styles ?: Partial < Record < BaseSelectSemanticName , React . CSSProperties > > ;
137
- title ?: string ;
136
+
137
+ // Selector
138
138
showSearch ?: boolean ;
139
139
tagRender ?: ( props : CustomTagProps ) => React . ReactElement ;
140
140
direction ?: 'ltr' | 'rtl' ;
141
- maxLength ?: number ;
142
- showScrollBar ?: boolean | 'optional' ;
141
+ autoFocus ?: boolean ;
142
+ placeholder ?: React . ReactNode ;
143
+ maxCount ?: number ;
144
+
143
145
// MISC
146
+ title ?: string ;
144
147
tabIndex ?: number ;
145
- autoFocus ?: boolean ;
146
148
notFoundContent ?: React . ReactNode ;
147
- placeholder ?: React . ReactNode ;
148
149
onClear ?: ( ) => void ;
150
+ maxLength ?: number ;
151
+ showScrollBar ?: boolean | 'optional' ;
149
152
150
153
choiceTransitionName ?: string ;
151
154
@@ -224,6 +227,8 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
224
227
id,
225
228
prefixCls,
226
229
className,
230
+ styles,
231
+ classNames,
227
232
showSearch,
228
233
tagRender,
229
234
showScrollBar = 'optional' ,
@@ -236,6 +241,7 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
236
241
emptyOptions,
237
242
notFoundContent = 'Not Found' ,
238
243
onClear,
244
+ maxCount,
239
245
240
246
// Mode
241
247
mode,
@@ -408,15 +414,8 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
408
414
[ tokenSeparators ] ,
409
415
) ;
410
416
411
- const {
412
- maxCount,
413
- rawValues,
414
- classNames : selectClassNames ,
415
- styles,
416
- } = React . useContext < SelectContextProps > ( SelectContext ) || { } ;
417
-
418
417
const onInternalSearch = ( searchText : string , fromTyping : boolean , isCompositing : boolean ) => {
419
- if ( multiple && isValidCount ( maxCount ) && rawValues ?. size >= maxCount ) {
418
+ if ( multiple && isValidCount ( maxCount ) && displayValues . length >= maxCount ) {
420
419
return ;
421
420
}
422
421
let ret = true ;
@@ -426,7 +425,7 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
426
425
const separatedList = getSeparatedContent (
427
426
searchText ,
428
427
tokenSeparators ,
429
- isValidCount ( maxCount ) ? maxCount - rawValues . size : undefined ,
428
+ isValidCount ( maxCount ) ? maxCount - displayValues . length : undefined ,
430
429
) ;
431
430
432
431
// Check if match the `tokenSeparators`
@@ -703,6 +702,8 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
703
702
multiple,
704
703
toggleOpen : onToggleOpen ,
705
704
showScrollBar,
705
+ styles,
706
+ classNames,
706
707
} ) ,
707
708
[
708
709
props ,
@@ -714,6 +715,8 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
714
715
multiple ,
715
716
onToggleOpen ,
716
717
showScrollBar ,
718
+ styles ,
719
+ classNames ,
717
720
] ,
718
721
) ;
719
722
@@ -728,7 +731,7 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
728
731
if ( showSuffixIcon ) {
729
732
arrowNode = (
730
733
< TransBtn
731
- className = { classNames ( `${ prefixCls } -arrow` , selectClassNames ?. suffix , {
734
+ className = { cls ( `${ prefixCls } -arrow` , classNames ?. suffix , {
732
735
[ `${ prefixCls } -arrow-loading` ] : loading ,
733
736
} ) }
734
737
style = { styles ?. suffix }
@@ -772,7 +775,7 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
772
775
const optionList = < OptionList ref = { listRef } /> ;
773
776
774
777
// ============================= Select =============================
775
- const mergedClassName = classNames ( prefixCls , className , {
778
+ const mergedClassName = cls ( prefixCls , className , {
776
779
[ `${ prefixCls } -focused` ] : mockFocused ,
777
780
[ `${ prefixCls } -multiple` ] : multiple ,
778
781
[ `${ prefixCls } -single` ] : ! multiple ,
@@ -821,7 +824,7 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
821
824
) : (
822
825
< Selector
823
826
{ ...props }
824
- prefixClassName = { selectClassNames ?. prefix }
827
+ prefixClassName = { classNames ?. prefix }
825
828
prefixStyle = { styles ?. prefix }
826
829
domRef = { selectorDomRef }
827
830
prefixCls = { prefixCls }
0 commit comments