Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/components/OptionsSelector/BaseOptionsSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ class BaseOptionsSelector extends Component {
});
return;
}

const newFocusedIndex = this.props.selectedOptions.length;
const isNewFocusedIndex = newFocusedIndex !== this.state.focusedIndex;

// eslint-disable-next-line react/no-did-update-set-state
this.setState(
{
Expand All @@ -117,13 +118,13 @@ class BaseOptionsSelector extends Component {
},
() => {
// If we just toggled an option on a multi-selection page or cleared the search input, scroll to top
if (this.props.selectedOptions.length !== prevProps.selectedOptions.length || this.props.value === '') {
if (this.props.selectedOptions.length !== prevProps.selectedOptions.length || (!!prevProps.value && !this.props.value)) {
this.scrollToIndex(0);
return;
}

// Otherwise, scroll to the focused index (as long as it's in range)
if (this.state.allOptions.length <= this.state.focusedIndex) {
if (this.state.allOptions.length <= this.state.focusedIndex || !isNewFocusedIndex) {
return;
}
this.scrollToIndex(this.state.focusedIndex);
Expand Down