diff --git a/src/components/SelectionList/BaseSelectionList.tsx b/src/components/SelectionList/BaseSelectionList.tsx index b92b4cef862f..b3d79bca271c 100644 --- a/src/components/SelectionList/BaseSelectionList.tsx +++ b/src/components/SelectionList/BaseSelectionList.tsx @@ -539,6 +539,7 @@ function BaseSelectionList( 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. @@ -546,7 +547,8 @@ function BaseSelectionList( 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); @@ -560,6 +562,7 @@ function BaseSelectionList( textInputValue, updateAndScrollToFocusedIndex, prevSelectedOptionsLength, + prevAllOptionsLength, ]); useEffect(