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

Fix scroll behavior when single item is selected #34485

Merged
merged 7 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
8 changes: 7 additions & 1 deletion src/components/SelectionList/BaseSelectionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function BaseSelectionList({
shouldShowTooltips = true,
shouldUseDynamicMaxToRenderPerBatch = false,
rightHandSideComponent,
shouldScrollToTopOnSelect = true,
}) {
const theme = useTheme();
const styles = useThemeStyles();
Expand Down Expand Up @@ -372,8 +373,13 @@ function BaseSelectionList({
return;
}

// scroll is unnecessary if multiple options cannot be selected
if (!canSelectMultiple) {
return;
}
neonbhai marked this conversation as resolved.
Show resolved Hide resolved

// set the focus on the first item when the sections list is changed
if (sections.length > 0) {
if (sections.length > 0 && shouldScrollToTopOnSelect) {
updateAndScrollToFocusedIndex(0);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
3 changes: 3 additions & 0 deletions src/components/SelectionList/selectionListPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ const propTypes = {

/** Right hand side component to display in the list item. Function has list item passed as the param */
rightHandSideComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),

/** Whether to scroll to top when an option is selected */
shouldScrollToTopOnSelect: PropTypes.bool,
};

export {propTypes, baseListItemPropTypes, radioListItemPropTypes, userListItemPropTypes};
Loading