@@ -12,17 +12,21 @@ import Icon from '../icon';
12
12
class SearchBar extends React . Component {
13
13
static propTypes = {
14
14
placeholder : React . PropTypes . string ,
15
+ searchName : React . PropTypes . string ,
15
16
onChange : React . PropTypes . func ,
16
17
onClear : React . PropTypes . func ,
17
18
onCancel : React . PropTypes . func ,
19
+ onSubmit : React . PropTypes . func ,
18
20
lang : React . PropTypes . object
19
21
} ;
20
22
21
23
static defaultProps = {
22
24
placeholder : '搜索' ,
25
+ searchName : 'q' ,
23
26
onChange : undefined ,
24
27
onClear : undefined ,
25
28
onCancel : undefined ,
29
+ onSubmit : undefined ,
26
30
lang : {
27
31
cancel : '取消'
28
32
}
@@ -50,21 +54,30 @@ class SearchBar extends React.Component {
50
54
if ( this . props . onChange ) this . props . onChange ( '' , e ) ;
51
55
}
52
56
57
+ submitHandle ( e ) {
58
+ if ( this . props . onSubmit ) {
59
+ e . preventDefault ( ) ;
60
+ e . stopPropagation ( ) ;
61
+ this . props . onSubmit ( this . state . text , e ) ;
62
+ }
63
+ }
64
+
53
65
render ( ) {
54
- const { children, placeholder, className, ...others } = this . props ;
66
+ const { children, placeholder, className, searchName , ...others } = this . props ;
55
67
const clz = classNames ( {
56
68
'weui_search_bar' : true ,
57
69
'weui_search_focusing' : this . state . focus
58
70
} , className ) ;
59
71
60
72
return (
61
73
< div className = { clz } >
62
- < form className = 'weui_search_outer' >
74
+ < form className = 'weui_search_outer' onSubmit = { this . submitHandle . bind ( this ) } >
63
75
< div className = 'weui_search_inner' >
64
76
< Icon value = 'search' />
65
77
< input
66
78
ref = 'searchInput'
67
79
type = 'search'
80
+ name = { searchName }
68
81
className = 'weui_search_input'
69
82
placeholder = { placeholder }
70
83
onFocus = { e => this . setState ( { focus :true } ) }
0 commit comments