All files / components/form/pieces search-bar.jsx

55.56% Statements 5/9
100% Branches 0/0
66.67% Functions 2/3
55.56% Lines 5/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59          1x 1x                     1x                                                       1x           1x              
import React from 'react';
import PropTypes from 'prop-types';
 
class SearchBar extends React.Component {
  constructor(props) {
    super(props);
    this.invokeFormPowers = this.invokeFormPowers.bind(this);
  }
 
  invokeFormPowers(e) {
    e.preventDefault();
    e.stopPropagation();
    const searchQuery = document.getElementById(`${this.props.id}-search-input`).value;
    this.props.searchHandler(searchQuery);
  }
 
  render() {
    return (
      <form id={`${this.props.id}-search-form`} onSubmit={this.invokeFormPowers}>
        <div className="input-group">
          <input
            type="text"
            id={`${this.props.id}-search-input`}
            name={`${this.props.id}-search-input`}
            className="form-control"
            placeholder={this.props.placeholder}
            disabled={this.props.disabled}
          />
          <span className="input-group-btn">
            <button
              type="submit"
              name={`${this.props.id}-btn`}
              id={`${this.props.id}-btn`}
              className="btn btn-flat"
              onClick={this.invokeFormPowers}
              disabled={this.props.disabled}
            >
              <i className="fa fa-search" />
            </button>
          </span>
        </div>
      </form>
    );
  }
}
SearchBar.propTypes = {
  disabled: PropTypes.bool,
  id: PropTypes.string,
  placeholder: PropTypes.string,
  searchHandler: PropTypes.func
};
SearchBar.defaultProps = {
  disabled: false,
  id: 'generic-searchbar',
  placeholder: 'Search...'
};
 
export default SearchBar;