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(selection-list): highlight on lists with 1 section #27246

Merged
18 changes: 8 additions & 10 deletions src/components/SelectionList/BaseSelectionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,13 @@ function BaseSelectionList({
listRef.current.scrollToLocation({sectionIndex: adjustedSectionIndex, itemIndex, animated, viewOffset: variables.contentHeaderHeight});
};

const selectRow = (item, index) => {
const selectRow = (item) => {
// In single-selection lists we don't care about updating the focused index, because the list is closed after selecting an item
if (canSelectMultiple) {
if (sections.length === 1) {
// If the list has only 1 section (e.g. Workspace Members list), we always focus the next available item
const nextAvailableIndex = _.findIndex(flattenedSections.allOptions, (option, i) => i > index && !option.isDisabled);
setFocusedIndex(nextAvailableIndex);
} else {
// If the list has multiple sections (e.g. Workspace Invite list), we focus the first one after all the selected (selected items are always at the top)
if (sections.length > 1) {
// If the list has only 1 section (e.g. Workspace Members list), we do nothing.
// If the list has multiple sections (e.g. Workspace Invite list), we focus the first one after all the selected (selected items are always at the top).

const selectedOptionsCount = item.isSelected ? flattenedSections.selectedOptions.length - 1 : flattenedSections.selectedOptions.length + 1;
setFocusedIndex(selectedOptionsCount);

Expand All @@ -196,7 +194,7 @@ function BaseSelectionList({
return;
}

selectRow(focusedOption, focusedIndex);
selectRow(focusedOption);
};

/**
Expand Down Expand Up @@ -250,7 +248,7 @@ function BaseSelectionList({
<CheckboxListItem
item={item}
isFocused={isFocused}
onSelectRow={() => selectRow(item, index)}
onSelectRow={() => selectRow(item)}
thiagobrez marked this conversation as resolved.
Show resolved Hide resolved
onDismissError={onDismissError}
/>
);
Expand All @@ -261,7 +259,7 @@ function BaseSelectionList({
item={item}
isFocused={isFocused}
isDisabled={isDisabled}
onSelectRow={() => selectRow(item, index)}
onSelectRow={() => selectRow(item)}
thiagobrez marked this conversation as resolved.
Show resolved Hide resolved
/>
);
};
Expand Down
Loading