From 6df046d74cfed10af726a9fbbe268819c4615d36 Mon Sep 17 00:00:00 2001 From: whien Date: Sun, 27 Mar 2016 00:52:31 +0800 Subject: [PATCH] urgent to fixed the delay search bug. --- .../js/manipulation/debounce-search-table.js | 2 +- src/toolbar/ToolBar.js | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/examples/js/manipulation/debounce-search-table.js b/examples/js/manipulation/debounce-search-table.js index 9c541ac2d..b3fb65051 100644 --- a/examples/js/manipulation/debounce-search-table.js +++ b/examples/js/manipulation/debounce-search-table.js @@ -24,7 +24,7 @@ addProducts(5); export default class DebounceSearchTable extends React.Component { render() { const options = { - searchDelayTime: 500 + searchDelayTime: 3000 }; return ( diff --git a/src/toolbar/ToolBar.js b/src/toolbar/ToolBar.js index 2d3df537b..b3dd99c8d 100644 --- a/src/toolbar/ToolBar.js +++ b/src/toolbar/ToolBar.js @@ -20,6 +20,15 @@ class ToolBar extends Component { }; } + componentWillMount() { + const delay = this.props.searchDelayTime ? this.props.searchDelayTime : 0; + this.debounceCallback = this.handleDebounce(() => { + this.props.onSearch(this.refs.seachInput.value); + }, + delay + ); + } + componentWillUnmount() { this.clearTimeout(); } @@ -156,13 +165,9 @@ class ToolBar extends Component { }; } - handleKeyUp = () => { - const delay = this.props.searchDelayTime ? this.props.searchDelayTime : 0; - this.handleDebounce(() => { - this.props.onSearch(this.refs.seachInput.value); - }, - delay - )(); + handleKeyUp = (event) => { + event.persist(); + this.debounceCallback(event); } handleExportCSV = () => {