From a63ef2f199d31db5eb9bb9e37148d9d360be4c52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=85=95=E9=99=B6?= Date: Tue, 29 Sep 2015 19:08:17 +0800 Subject: [PATCH] [fixed]: check item length before calling scrollinto view the state of highlightIndex will not be set to null when I change the value of input box, so exception will be thrown when it is going to find the highlighted dom element --- lib/Autocomplete.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Autocomplete.js b/lib/Autocomplete.js index daceb0ed..aa0ad9a1 100644 --- a/lib/Autocomplete.js +++ b/lib/Autocomplete.js @@ -68,7 +68,7 @@ let Autocomplete = React.createClass({ }, maybeScrollItemIntoView () { - if (this.state.isOpen === true && this.state.highlightedIndex !== null) { + if (this.state.isOpen === true && this.state.highlightedIndex !== null && this.getFilteredItems().length > 0) { var itemNode = React.findDOMNode(this.refs[`item-${this.state.highlightedIndex}`]) var menuNode = React.findDOMNode(this.refs.menu) scrollIntoView(itemNode, menuNode, { onlyScrollIfNeeded: true })