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' ;
@@ -130,22 +130,27 @@ export interface BaseSelectPrivateProps {
130
130
export type BaseSelectPropsWithoutPrivate = Omit < BaseSelectProps , keyof BaseSelectPrivateProps > ;
131
131
132
132
export interface BaseSelectProps extends BaseSelectPrivateProps , React . AriaAttributes {
133
+ // Style
133
134
className ?: string ;
134
135
style ?: React . CSSProperties ;
135
136
classNames ?: Partial < Record < BaseSelectSemanticName , string > > ;
136
137
styles ?: Partial < Record < BaseSelectSemanticName , React . CSSProperties > > ;
137
- title ?: string ;
138
+
139
+ // Selector
138
140
showSearch ?: boolean ;
139
141
tagRender ?: ( props : CustomTagProps ) => React . ReactElement ;
140
142
direction ?: 'ltr' | 'rtl' ;
141
- maxLength ?: number ;
142
- showScrollBar ?: boolean | 'optional' ;
143
+ autoFocus ?: boolean ;
144
+ placeholder ?: React . ReactNode ;
145
+ maxCount ?: number ;
146
+
143
147
// MISC
148
+ title ?: string ;
144
149
tabIndex ?: number ;
145
- autoFocus ?: boolean ;
146
150
notFoundContent ?: React . ReactNode ;
147
- placeholder ?: React . ReactNode ;
148
151
onClear ?: ( ) => void ;
152
+ maxLength ?: number ;
153
+ showScrollBar ?: boolean | 'optional' ;
149
154
150
155
choiceTransitionName ?: string ;
151
156
@@ -224,6 +229,8 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
224
229
id,
225
230
prefixCls,
226
231
className,
232
+ styles,
233
+ classNames,
227
234
showSearch,
228
235
tagRender,
229
236
showScrollBar = 'optional' ,
@@ -236,6 +243,7 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
236
243
emptyOptions,
237
244
notFoundContent = 'Not Found' ,
238
245
onClear,
246
+ maxCount,
239
247
240
248
// Mode
241
249
mode,
@@ -283,8 +291,6 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
283
291
placement,
284
292
builtinPlacements,
285
293
getPopupContainer,
286
- styles : baseSelectStyles ,
287
- classNames : baseSelectClassNames ,
288
294
289
295
// Focus
290
296
showAction = [ ] ,
@@ -410,18 +416,8 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
410
416
[ tokenSeparators ] ,
411
417
) ;
412
418
413
- const {
414
- maxCount,
415
- rawValues,
416
- classNames : selectClassNames ,
417
- styles : selectStyles ,
418
- } = React . useContext < SelectContextProps > ( SelectContext ) || { } ;
419
-
420
- const contextClassNames = baseSelectClassNames ?? selectClassNames ;
421
- const contextStyles = baseSelectStyles ?? selectStyles ;
422
-
423
419
const onInternalSearch = ( searchText : string , fromTyping : boolean , isCompositing : boolean ) => {
424
- if ( multiple && isValidCount ( maxCount ) && rawValues ?. size >= maxCount ) {
420
+ if ( multiple && isValidCount ( maxCount ) && displayValues . length >= maxCount ) {
425
421
return ;
426
422
}
427
423
let ret = true ;
@@ -431,7 +427,7 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
431
427
const separatedList = getSeparatedContent (
432
428
searchText ,
433
429
tokenSeparators ,
434
- isValidCount ( maxCount ) ? maxCount - rawValues . size : undefined ,
430
+ isValidCount ( maxCount ) ? maxCount - displayValues . length : undefined ,
435
431
) ;
436
432
437
433
// Check if match the `tokenSeparators`
@@ -708,8 +704,8 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
708
704
multiple,
709
705
toggleOpen : onToggleOpen ,
710
706
showScrollBar,
711
- styles : contextStyles ,
712
- classNames : contextClassNames ,
707
+ styles,
708
+ classNames,
713
709
} ) ,
714
710
[
715
711
props ,
@@ -721,6 +717,8 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
721
717
multiple ,
722
718
onToggleOpen ,
723
719
showScrollBar ,
720
+ styles ,
721
+ classNames ,
724
722
] ,
725
723
) ;
726
724
@@ -735,10 +733,10 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
735
733
if ( showSuffixIcon ) {
736
734
arrowNode = (
737
735
< TransBtn
738
- className = { classNames ( `${ prefixCls } -arrow` , contextClassNames ?. suffix , {
736
+ className = { cls ( `${ prefixCls } -arrow` , classNames ?. suffix , {
739
737
[ `${ prefixCls } -arrow-loading` ] : loading ,
740
738
} ) }
741
- style = { contextStyles ?. suffix }
739
+ style = { styles ?. suffix }
742
740
customizeIcon = { suffixIcon }
743
741
customizeIconProps = { {
744
742
loading,
@@ -779,7 +777,7 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
779
777
const optionList = < OptionList ref = { listRef } /> ;
780
778
781
779
// ============================= Select =============================
782
- const mergedClassName = classNames ( prefixCls , className , {
780
+ const mergedClassName = cls ( prefixCls , className , {
783
781
[ `${ prefixCls } -focused` ] : mockFocused ,
784
782
[ `${ prefixCls } -multiple` ] : multiple ,
785
783
[ `${ prefixCls } -single` ] : ! multiple ,
@@ -828,8 +826,8 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
828
826
) : (
829
827
< Selector
830
828
{ ...props }
831
- prefixClassName = { contextClassNames ?. prefix }
832
- prefixStyle = { contextStyles ?. prefix }
829
+ prefixClassName = { classNames ?. prefix }
830
+ prefixStyle = { styles ?. prefix }
833
831
domRef = { selectorDomRef }
834
832
prefixCls = { prefixCls }
835
833
inputElement = { customizeInputElement }
0 commit comments