Skip to content

Commit

Permalink
fix: Workspace switcher - Selection disappears after erasing characte…
Browse files Browse the repository at this point in the history
…r with workspace selected.

Signed-off-by: Krishna Gupta <[email protected]>
  • Loading branch information
Krishna2323 committed Jun 23, 2024
1 parent 0176052 commit 01d8742
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/components/SelectionList/BaseSelectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -539,14 +539,16 @@ 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;
const newSelectedIndex =
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 @@ -560,6 +562,7 @@ function BaseSelectionList<TItem extends ListItem>(
textInputValue,
updateAndScrollToFocusedIndex,
prevSelectedOptionsLength,
prevAllOptionsLength,
]);

useEffect(
Expand Down

0 comments on commit 01d8742

Please sign in to comment.