Browse Source

Merge pull request #164 from smiclea/searchinput

User primary search icon if search is not empty
Dorin Paslaru 8 years ago
parent
commit
4b49a13fd4
1 changed files with 13 additions and 3 deletions
  1. 13 3
      src/components/molecules/SearchInput/index.jsx

+ 13 - 3
src/components/molecules/SearchInput/index.jsx

@@ -62,6 +62,7 @@ type State = {
   open: boolean,
   open: boolean,
   hover?: boolean,
   hover?: boolean,
   focus?: boolean,
   focus?: boolean,
+  value: string,
 }
 }
 class SearchInput extends React.Component<Props, State> {
 class SearchInput extends React.Component<Props, State> {
   static defaultProps = {
   static defaultProps = {
@@ -76,6 +77,7 @@ class SearchInput extends React.Component<Props, State> {
 
 
     this.state = {
     this.state = {
       open: false,
       open: false,
+      value: '',
     }
     }
 
 
     // $FlowIssue
     // $FlowIssue
@@ -120,7 +122,7 @@ class SearchInput extends React.Component<Props, State> {
   render() {
   render() {
     return (
     return (
       <Wrapper
       <Wrapper
-        open={this.state.open || this.props.alwaysOpen}
+        open={this.state.open || this.props.alwaysOpen || this.state.value !== ''}
         onMouseDown={() => { this.itemMouseDown = true }}
         onMouseDown={() => { this.itemMouseDown = true }}
         onMouseUp={() => { this.itemMouseDown = false }}
         onMouseUp={() => { this.itemMouseDown = false }}
         onMouseEnter={() => { this.handleMouseEnter() }}
         onMouseEnter={() => { this.handleMouseEnter() }}
@@ -129,13 +131,21 @@ class SearchInput extends React.Component<Props, State> {
         <Input
         <Input
           _ref={input => { this.input = input }}
           _ref={input => { this.input = input }}
           placeholder={this.props.placeholder}
           placeholder={this.props.placeholder}
-          onChange={e => { this.props.onChange(e.target.value) }}
+          onChange={e => {
+            this.setState({ value: e.target.value })
+            this.props.onChange(e.target.value)
+          }}
+          value={this.state.value}
           onFocus={() => { this.handleFocus() }}
           onFocus={() => { this.handleFocus() }}
           onBlur={() => { this.handleBlur() }}
           onBlur={() => { this.handleBlur() }}
           loading={this.props.loading}
           loading={this.props.loading}
         />
         />
         <SearchButtonStyled
         <SearchButtonStyled
-          primary={this.state.open || (this.props.alwaysOpen && (this.state.hover || this.state.focus))}
+          primary={
+            this.state.open ||
+            (this.props.alwaysOpen && (this.state.hover || this.state.focus)) ||
+            (this.state.value !== '' && (this.state.hover || this.state.focus))
+          }
           onClick={() => { this.handleSearchButtonClick() }}
           onClick={() => { this.handleSearchButtonClick() }}
         />
         />
         {this.props.loading ? <StatusIconStyled status="RUNNING" /> : null}
         {this.props.loading ? <StatusIconStyled status="RUNNING" /> : null}