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 member select highlight issue #27646

Closed
wants to merge 2 commits into from
Closed
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
30 changes: 13 additions & 17 deletions src/components/SelectionList/BaseSelectionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,36 +168,32 @@ function BaseSelectionList({
listRef.current.scrollToLocation({sectionIndex: adjustedSectionIndex, itemIndex, animated, viewOffset: variables.contentHeaderHeight});
};

const selectRow = (item, index) => {
const selectFocusedOption = () => {
const focusedOption = flattenedSections.allOptions[focusedIndex];

if (!focusedOption || focusedOption.isDisabled) {
return;
}

// 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);
const nextAvailableIndex = _.findIndex(flattenedSections.allOptions, (option, i) => i > focusedIndex && !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)
const selectedOptionsCount = item.isSelected ? flattenedSections.selectedOptions.length - 1 : flattenedSections.selectedOptions.length + 1;
const selectedOptionsCount = focusedOption.isSelected ? flattenedSections.selectedOptions.length - 1 : flattenedSections.selectedOptions.length + 1;
setFocusedIndex(selectedOptionsCount);

if (!item.isSelected) {
if (!focusedOption.isSelected) {
// If we're selecting an item, scroll to it's position at the top, so we can see it
scrollToIndex(Math.max(selectedOptionsCount - 1, 0), true);
}
}
}

onSelectRow(item);
};

const selectFocusedOption = () => {
const focusedOption = flattenedSections.allOptions[focusedIndex];

if (!focusedOption || focusedOption.isDisabled) {
return;
}

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

/**
Expand Down Expand Up @@ -254,7 +250,7 @@ function BaseSelectionList({
<UserListItem
item={item}
isFocused={isItemFocused}
onSelectRow={() => selectRow(item, index)}
onSelectRow={() => onSelectRow(item)}
onDismissError={onDismissError}
showTooltip={showTooltip}
/>
Expand All @@ -266,7 +262,7 @@ function BaseSelectionList({
item={item}
isFocused={isItemFocused}
isDisabled={isDisabled}
onSelectRow={() => selectRow(item, index)}
onSelectRow={() => onSelectRow(item)}
/>
);
};
Expand Down