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: Workspace switcher - Selection disappears after erasing character with workspace selected. #44222

Merged
merged 4 commits into from
Jun 27, 2024
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
8 changes: 6 additions & 2 deletions src/components/SelectionList/BaseSelectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -540,14 +540,17 @@ function BaseSelectionList<TItem extends ListItem>(

const prevTextInputValue = usePrevious(textInputValue);
const prevSelectedOptionsLength = usePrevious(flattenedSections.selectedOptions.length);
const prevAllOptionsLength = usePrevious(flattenedSections.allOptions.length);

useEffect(() => {
// Avoid changing focus if the textInputValue remains unchanged.
if ((prevTextInputValue === textInputValue && flattenedSections.selectedOptions.length === prevSelectedOptionsLength) || flattenedSections.allOptions.length === 0) {
return;
}
// Remove the focus if the search input is empty or selected options length is changed else focus on the first non disabled item
const newSelectedIndex = textInputValue === '' || flattenedSections.selectedOptions.length !== prevSelectedOptionsLength ? -1 : 0;
// Remove the focus if the search input is empty or selected options length is changed (and allOptions length remains the same)
// else focus on the first non disabled item
const newSelectedIndex =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hoangzinh 👋 , I think this might be a add on here, but we should had removed the focus if the search input is empty and prev search input not empty, the bug was caught during regression testing here, So not quite sure if the behaviour changed over the months.

This caused #50562

textInputValue === '' || (flattenedSections.selectedOptions.length !== prevSelectedOptionsLength && prevAllOptionsLength === flattenedSections.allOptions.length) ? -1 : 0;

// reseting the currrent page to 1 when the user types something
setCurrentPage(1);
Expand All @@ -561,6 +564,7 @@ function BaseSelectionList<TItem extends ListItem>(
textInputValue,
updateAndScrollToFocusedIndex,
prevSelectedOptionsLength,
prevAllOptionsLength,
]);

useEffect(
Expand Down
Loading