From 01d874294df7f5371598dd2cc626f16c804eb829 Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Sun, 23 Jun 2024 21:25:06 +0530 Subject: [PATCH 1/2] fix: Workspace switcher - Selection disappears after erasing character with workspace selected. Signed-off-by: Krishna Gupta --- src/components/SelectionList/BaseSelectionList.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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( From 26500383370361e231d752f07b25d0f3fe89b343 Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Tue, 25 Jun 2024 16:07:12 +0530 Subject: [PATCH 2/2] update comment. Signed-off-by: Krishna Gupta --- src/components/SelectionList/BaseSelectionList.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/SelectionList/BaseSelectionList.tsx b/src/components/SelectionList/BaseSelectionList.tsx index b3d79bca271c..88ea81f14a17 100644 --- a/src/components/SelectionList/BaseSelectionList.tsx +++ b/src/components/SelectionList/BaseSelectionList.tsx @@ -546,7 +546,8 @@ function BaseSelectionList( 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 + // 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 = textInputValue === '' || (flattenedSections.selectedOptions.length !== prevSelectedOptionsLength && prevAllOptionsLength === flattenedSections.allOptions.length) ? -1 : 0;