Correctly positioning the selected element if list shrinks in size

pull/21833/head
wmwragg 2016-09-12 14:07:51 +01:00
parent 28dcbb2a78
commit 7d58968ea6
1 changed files with 5 additions and 3 deletions

View File

@ -37,14 +37,16 @@ module.exports = React.createClass({
}; };
}, },
componentDidUpdate: function() { componentWillReceiveProps: function(props) {
// Make sure the selected item isn't outside the list bounds // Make sure the selected item isn't outside the list bounds
var selected = this.state.selected; var selected = this.state.selected;
var maxSelected = this._maxSelected(this.props.addressList); var maxSelected = this._maxSelected(props.addressList);
if (selected > maxSelected) { if (selected > maxSelected) {
selected = maxSelected; this.setState({ selected: maxSelected });
} }
},
componentDidUpdate: function() {
// As the user scrolls with the arrow keys keep the selected item // As the user scrolls with the arrow keys keep the selected item
// at the top of the window. // at the top of the window.
if (this.scrollElement && this.props.addressList.length > 0 && !this.state.hover) { if (this.scrollElement && this.props.addressList.length > 0 && !this.state.hover) {