@@ -2,7 +2,11 @@ import React from 'react';
2
2
import classNames from 'classnames' ;
3
3
import CSSMotionList from 'rc-animate/lib/CSSMotionList' ;
4
4
import TransBtn from '../TransBtn' ;
5
- import { LabelValueType , RawValueType } from '../interface/generator' ;
5
+ import {
6
+ LabelValueType ,
7
+ RawValueType ,
8
+ CustomTagProps ,
9
+ } from '../interface/generator' ;
6
10
import { RenderNode } from '../interface' ;
7
11
import { InnerSelectorProps } from '.' ;
8
12
import Input from './Input' ;
@@ -17,8 +21,11 @@ interface SelectorProps extends InnerSelectorProps {
17
21
// Tags
18
22
maxTagCount ?: number ;
19
23
maxTagTextLength ?: number ;
20
- maxTagPlaceholder ?: React . ReactNode | ( ( omittedValues : LabelValueType [ ] ) => React . ReactNode ) ;
24
+ maxTagPlaceholder ?:
25
+ | React . ReactNode
26
+ | ( ( omittedValues : LabelValueType [ ] ) => React . ReactNode ) ;
21
27
tokenSeparators ?: string [ ] ;
28
+ tagRender ?: ( props : CustomTagProps ) => React . ReactElement ;
22
29
23
30
// Motion
24
31
choiceTransitionName ?: string ;
@@ -48,7 +55,9 @@ const SelectSelector: React.FC<SelectorProps> = ({
48
55
49
56
maxTagCount,
50
57
maxTagTextLength,
51
- maxTagPlaceholder = ( omittedValues : LabelValueType [ ] ) => `+ ${ omittedValues . length } ...` ,
58
+ maxTagPlaceholder = ( omittedValues : LabelValueType [ ] ) =>
59
+ `+ ${ omittedValues . length } ...` ,
60
+ tagRender,
52
61
53
62
onSelect,
54
63
onInputChange,
@@ -122,27 +131,47 @@ const SelectSelector: React.FC<SelectorProps> = ({
122
131
>
123
132
{ ( { key, label, value, disabled : itemDisabled , className, style } ) => {
124
133
const mergedKey = key || value ;
125
-
126
- return (
134
+ const closable = key !== REST_TAG_KEY && ! itemDisabled ;
135
+ const onMouseDown = ( event : React . MouseEvent ) => {
136
+ event . preventDefault ( ) ;
137
+ event . stopPropagation ( ) ;
138
+ } ;
139
+ const onClose = ( event ?: React . MouseEvent ) => {
140
+ if ( event ) event . stopPropagation ( ) ;
141
+ onSelect ( value , { selected : false } ) ;
142
+ } ;
143
+
144
+ return typeof tagRender === 'function' ? (
145
+ < span
146
+ key = { mergedKey }
147
+ onMouseDown = { onMouseDown }
148
+ className = { className }
149
+ style = { style }
150
+ >
151
+ { tagRender ( {
152
+ label,
153
+ value,
154
+ disabled : itemDisabled ,
155
+ closable,
156
+ onClose,
157
+ } ) }
158
+ </ span >
159
+ ) : (
127
160
< span
128
161
key = { mergedKey }
129
162
className = { classNames ( className , `${ prefixCls } -selection-item` , {
130
163
[ `${ prefixCls } -selection-item-disabled` ] : itemDisabled ,
131
164
} ) }
132
165
style = { style }
133
166
>
134
- < span className = { `${ prefixCls } -selection-item-content` } > { label } </ span >
135
- { key !== REST_TAG_KEY && ! itemDisabled && (
167
+ < span className = { `${ prefixCls } -selection-item-content` } >
168
+ { label }
169
+ </ span >
170
+ { closable && (
136
171
< TransBtn
137
172
className = { `${ prefixCls } -selection-item-remove` }
138
- onMouseDown = { event => {
139
- event . preventDefault ( ) ;
140
- event . stopPropagation ( ) ;
141
- } }
142
- onClick = { event => {
143
- event . stopPropagation ( ) ;
144
- onSelect ( value , { selected : false } ) ;
145
- } }
173
+ onMouseDown = { onMouseDown }
174
+ onClick = { onClose }
146
175
customizeIcon = { removeIcon }
147
176
>
148
177
×
@@ -158,7 +187,10 @@ const SelectSelector: React.FC<SelectorProps> = ({
158
187
< >
159
188
{ selectionNode }
160
189
161
- < span className = { `${ prefixCls } -selection-search` } style = { { width : inputWidth } } >
190
+ < span
191
+ className = { `${ prefixCls } -selection-search` }
192
+ style = { { width : inputWidth } }
193
+ >
162
194
< Input
163
195
ref = { inputRef }
164
196
open = { open }
@@ -177,13 +209,19 @@ const SelectSelector: React.FC<SelectorProps> = ({
177
209
/>
178
210
179
211
{ /* Measure Node */ }
180
- < span ref = { measureRef } className = { `${ prefixCls } -selection-search-mirror` } aria-hidden >
212
+ < span
213
+ ref = { measureRef }
214
+ className = { `${ prefixCls } -selection-search-mirror` }
215
+ aria-hidden
216
+ >
181
217
{ searchValue }
182
218
</ span >
183
219
</ span >
184
220
185
221
{ ! values . length && ! searchValue && (
186
- < span className = { `${ prefixCls } -selection-placeholder` } > { placeholder } </ span >
222
+ < span className = { `${ prefixCls } -selection-placeholder` } >
223
+ { placeholder }
224
+ </ span >
187
225
) }
188
226
</ >
189
227
) ;
0 commit comments