diff --git a/CHANGELOG.md b/CHANGELOG.md index a7406faf..e7642992 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/). ## [Unreleased] +### Fixed +- `Autocomplete` - prevent crash when going to index 0 ## v6.2.0 - 2021-12-07 diff --git a/package-lock.json b/package-lock.json index 733aceef..b7843351 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23907,9 +23907,9 @@ } }, "prismjs": { - "version": "1.24.1", - "resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.24.1.tgz", - "integrity": "sha512-mNPsedLuk90RVJioIky8ANZEwYm5w9LcvCXrxHlwf4fNVSn8jEipMybMkWUyyF0JhnC+C4VcOVSBuHRKs1L5Ow==", + "version": "1.25.0", + "resolved": "https://registry.npmjs.org/prismjs/-/prismjs-1.25.0.tgz", + "integrity": "sha512-WCjJHl1KEWbnkQom1+SzftbtXMKQoezOCYs5rECqMN+jP+apI7ftoflyqigqzopSO3hMhTEb0mFClA8lkolgEg==", "dev": true }, "private": { diff --git a/packages/autocomplete/src/component/Autocomplete.jsx b/packages/autocomplete/src/component/Autocomplete.jsx index f623ad3d..9e9c8171 100644 --- a/packages/autocomplete/src/component/Autocomplete.jsx +++ b/packages/autocomplete/src/component/Autocomplete.jsx @@ -108,7 +108,7 @@ class Autocomplete extends Component { tap(e => { e.preventDefault(); const {results, cursor} = this.state; - if (e.key === "ArrowDown" && cursor < results.length - 1) { + if (e.key === "ArrowDown" && cursor < results.length) { this.setState({ open: true, cursor: cursor + 1 @@ -116,7 +116,7 @@ class Autocomplete extends Component { this.scrollToItem() }); } - if (e.key === "ArrowUp" && cursor > 0) { + if (e.key === "ArrowUp" && cursor > 1) { this.setState({ open: true, cursor: cursor - 1 @@ -176,6 +176,11 @@ class Autocomplete extends Component { scrollToItem = () => { const domNode = ReactDOM.findDOMNode(this['item_' + this.state.cursor]); + + if (!domNode) { + return; + } + domNode.scrollIntoView(false) };