All files InputBoxDoneTyping.js

100% Statements 19/19
50% Branches 1/2
100% Functions 6/6
100% Lines 18/18
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 591x   1x 3x   3x 1x 1x 1x       3x 1x     3x 1x 1x 1x     3x 1x     3x                             1x         1x                        
import React, { PropTypes } from 'react';
 
const InputBoxDoneTyping = (props) => {
  let typingTimer;
 
  const handleOnChange = (e) => {
    Eif (props.onChange) {
      const value = e.target.value;
      props.onChange(value);
    }
  };
 
  const doneTyping = (value) => {
    props.doneTyping(value);
  };
 
  const handleOnKeyUp = (e) => {
    clearTimeout(typingTimer);
    const value = e.target.value;
    typingTimer = setTimeout(() => { doneTyping(value); }, props.doneTypingInterval);
  };
 
  const handleOnKeyDown = () => {
    clearTimeout(typingTimer);
  };
 
  return (
    <input
      type="text"
      id={props.id}
      className={props.className}
      placeholder={props.placeholder}
      defaultValue={props.defaultValue}
      autoComplete={props.autoComplete}
      onChange={handleOnChange}
      onKeyUp={handleOnKeyUp}
      onKeyDown={handleOnKeyDown}
      />
  );
};
 
InputBoxDoneTyping.defaultProps = {
  autoComplete: 'on',
  doneTypingInterval: 500,
};
 
InputBoxDoneTyping.propTypes = {
  id: PropTypes.string,
  className: PropTypes.string,
  placeholder: PropTypes.string,
  defaultValue: PropTypes.string,
  autoComplete: PropTypes.oneOf(['on', 'off']),
  onChange: PropTypes.func,
  doneTyping: PropTypes.func.isRequired,
  doneTypingInterval: PropTypes.number,
};
 
export default InputBoxDoneTyping;