Skip to content

Commit

Permalink
Merge branch 'master' of github.com:digipolisantwerp/acpaas-ui_react
Browse files Browse the repository at this point in the history
* 'master' of github.com:digipolisantwerp/acpaas-ui_react:
  fix: remove console log
  fix: prevent oob error
  Bump prismjs from 1.24.1 to 1.25.0
  • Loading branch information
TriangleJuice committed Dec 13, 2021
2 parents 8e8eb9b + 850b0a3 commit 994bdf4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions packages/autocomplete/src/component/Autocomplete.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ class Autocomplete extends Component<Props, IState> {
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
}, () => {
this.scrollToItem()
});
}
if (e.key === "ArrowUp" && cursor > 0) {
if (e.key === "ArrowUp" && cursor > 1) {
this.setState({
open: true,
cursor: cursor - 1
Expand Down Expand Up @@ -176,6 +176,11 @@ class Autocomplete extends Component<Props, IState> {

scrollToItem = () => {
const domNode = ReactDOM.findDOMNode(this['item_' + this.state.cursor]);

if (!domNode) {
return;
}

domNode.scrollIntoView(false)
};

Expand Down

0 comments on commit 994bdf4

Please sign in to comment.