1
- import React from 'react' ;
1
+ import React , { isValidElement } from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
3
import classNames from 'classnames' ;
4
4
import { polyfill } from 'react-lifecycles-compat' ;
@@ -126,6 +126,10 @@ class Search extends React.Component {
126
126
disabled : PropTypes . bool ,
127
127
locale : PropTypes . object ,
128
128
rtl : PropTypes . bool ,
129
+ /**
130
+ * 可配置的icons,包括 search 等
131
+ */
132
+ icons : PropTypes . object ,
129
133
} ;
130
134
131
135
static defaultProps = {
@@ -142,6 +146,7 @@ class Search extends React.Component {
142
146
onFilterChange : func . noop ,
143
147
hasClear : false ,
144
148
disabled : false ,
149
+ icons : { } ,
145
150
} ;
146
151
147
152
constructor ( props ) {
@@ -237,6 +242,7 @@ class Search extends React.Component {
237
242
visible,
238
243
locale,
239
244
rtl,
245
+ icons,
240
246
...others
241
247
} = this . props ;
242
248
@@ -250,26 +256,31 @@ class Search extends React.Component {
250
256
251
257
let searchIcon = null ,
252
258
filterSelect = null ,
253
- searchBtn = null ;
259
+ searchBtn = null ,
260
+ iconsSearch = icons . search ;
261
+
262
+ if ( ! isValidElement ( icons . search ) && icons . search ) {
263
+ iconsSearch = < span > { icons . search } </ span > ;
264
+ }
254
265
255
266
if ( shape === 'simple' ) {
256
267
const cls = classNames ( {
257
268
[ `${ prefix } search-icon` ] : true ,
258
269
[ buttonProps . className ] : ! ! buttonProps . className ,
270
+ [ `${ prefix } search-symbol-icon` ] : ! iconsSearch ,
259
271
} ) ;
260
272
hasIcon &&
261
- ( searchIcon = (
262
- < Icon
263
- type = "search"
264
- tabIndex = "0"
265
- role = "button"
266
- aria-disabled = { disabled }
267
- aria-label = { locale . buttonText }
268
- { ...buttonProps }
269
- className = { cls }
270
- onClick = { this . onSearch }
271
- onKeyDown = { this . onKeyDown }
272
- />
273
+ ( searchIcon = React . cloneElement (
274
+ iconsSearch || < Icon type = "search" /> ,
275
+ {
276
+ role : 'button' ,
277
+ 'aria-disabled' : disabled ,
278
+ 'aria-label' : locale . buttonText ,
279
+ ...buttonProps ,
280
+ className : cls ,
281
+ onClick : this . onSearch ,
282
+ onKeyDown : this . onKeyDown ,
283
+ }
273
284
) ) ;
274
285
} else {
275
286
const cls = classNames ( {
@@ -287,7 +298,14 @@ class Search extends React.Component {
287
298
onClick = { this . onSearch }
288
299
onKeyDown = { this . onKeyDown }
289
300
>
290
- { hasIcon ? < Icon type = "search" /> : null }
301
+ { hasIcon
302
+ ? iconsSearch || (
303
+ < Icon
304
+ type = "search"
305
+ className = { `${ prefix } search-symbol-icon` }
306
+ />
307
+ )
308
+ : null }
291
309
{ searchText ? (
292
310
< span className = { `${ prefix } search-btn-text` } >
293
311
{ searchText }
0 commit comments