diff --git a/src/containers/list-monitor.jsx b/src/containers/list-monitor.jsx index d6e8bf7ae2e32f37b3006bf6ac3c80e58bacb1bf..c4b40584eb0cba9cecb479f9b7bf01ab9528fecb 100644 --- a/src/containers/list-monitor.jsx +++ b/src/containers/list-monitor.jsx @@ -72,7 +72,7 @@ class ListMonitor extends React.Component { else if (e.key === 'ArrowDown') navigateDirection = 1; if (navigateDirection) { this.handleDeactivate(); // Submit in-progress edits - const newIndex = (previouslyActiveIndex + navigateDirection) % this.props.value.length; + const newIndex = this.wrapListIndex(previouslyActiveIndex + navigateDirection, this.props.value.length); this.setState({ activeIndex: newIndex, activeValue: this.props.value[newIndex] @@ -87,7 +87,7 @@ class ListMonitor extends React.Component { .concat([newListItemValue]) .concat(listValue.slice(previouslyActiveIndex + newValueOffset)); setVariableValue(vm, targetId, variableId, newListValue); - const newIndex = (previouslyActiveIndex + newValueOffset) % newListValue.length; + const newIndex = this.wrapListIndex(previouslyActiveIndex + newValueOffset, newListValue.length); this.setState({ activeIndex: newIndex, activeValue: newListItemValue @@ -144,6 +144,11 @@ class ListMonitor extends React.Component { window.addEventListener('mouseup', onMouseUp); } + + wrapListIndex (index, length) { + return (index + length) % length; + } + render () { const { vm, // eslint-disable-line no-unused-vars