Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always scroll to the top where there are new options selected #9798

Merged
merged 2 commits into from
Jul 12, 2022
Merged
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions src/components/OptionsSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ class OptionsSelector extends Component {
allOptions: newOptions,
focusedIndex: newFocusedIndex,
}, () => {
// If we just selected a new options on a multiple-selection page, scroll to the top
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
if (this.props.selectedOptions.length > prevProps.selectedOptions.length) {
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) {
return;
}
Expand Down Expand Up @@ -315,8 +322,7 @@ class OptionsSelector extends Component {
return;
}

// Scroll back to the top and focus the first unselected item from the list (i.e: the best result according to the current search term)
this.scrollToIndex(0);
// Focus the first unselected item from the list (i.e: the best result according to the current search term)
this.setState({
focusedIndex: this.props.selectedOptions.length,
});
Expand Down