Created
July 2, 2016 10:44
-
Star
(140)
You must be signed in to star a gist -
Fork
(25)
You must be signed in to fork a gist
-
-
Save krambertech/76afec49d7508e89e028fce14894724c to your computer and use it in GitHub Desktop.
Revisions
-
krambertech renamed this gist
Jul 2, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
krambertech created this gist
Jul 2, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,54 @@ import React, { Component } from 'react'; import TextField from 'components/base/TextField'; const WAIT_INTERVAL = 1000; const ENTER_KEY = 13; export default class TextSearch extends Component { constructor(props) { super(); this.state = { value: props.value }; } componentWillMount() { this.timer = null; } handleChange(value) { clearTimeout(this.timer); this.setState({ value }); this.timer = setTimeout(::this.triggerChange, WAIT_INTERVAL); } handleKeyDown(e) { if (e.keyCode === ENTER_KEY) { ::this.triggerChange(); } } triggerChange() { const { value } = this.state; this.props.onChange(value); } render() { const { className } = this.props; return ( <TextField className={className} placeholder={l('Search')} value={this.state.value} onChange={::this.handleChange} onKeyDown={::this.handleKeyDown} /> ); } }