1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-11-10 09:22:25 +03:00

Correctly positioning the selected element if list shrinks in size

This commit is contained in:
wmwragg
2016-09-12 14:07:51 +01:00
parent 28dcbb2a78
commit 7d58968ea6

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
var selected = this.state.selected;
var maxSelected = this._maxSelected(this.props.addressList);
var maxSelected = this._maxSelected(props.addressList);
if (selected > maxSelected) {
selected = maxSelected;
this.setState({ selected: maxSelected });
}
},
componentDidUpdate: function() {
// As the user scrolls with the arrow keys keep the selected item
// at the top of the window.
if (this.scrollElement && this.props.addressList.length > 0 && !this.state.hover) {