From 0ef0476baf62c016efe744ef4b1d6a07ff5dd181 Mon Sep 17 00:00:00 2001 From: Mehmet Salih Yavuz Date: Fri, 3 Oct 2025 18:47:04 +0300 Subject: [PATCH 1/2] fix(Select): prevent closing the dropdown when clicked on the single tag --- .../src/components/Select/Select.tsx | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/superset-frontend/packages/superset-ui-core/src/components/Select/Select.tsx b/superset-frontend/packages/superset-ui-core/src/components/Select/Select.tsx index bf8c99263d43..e8300f6eb39d 100644 --- a/superset-frontend/packages/superset-ui-core/src/components/Select/Select.tsx +++ b/superset-frontend/packages/superset-ui-core/src/components/Select/Select.tsx @@ -24,6 +24,7 @@ import { useMemo, useState, useCallback, + useRef, ClipboardEvent, Ref, ReactElement, @@ -143,6 +144,32 @@ const Select = forwardRef( : 1 : (propsMaxTagCount ?? MAX_TAG_COUNT); + // Prevent maxTagCount change during click events to avoid click target disappearing + const [stableMaxTagCount, setStableMaxTagCount] = useState(maxTagCount); + const isOpeningRef = useRef(false); + + useEffect(() => { + if (oneLine) { + if (isDropdownVisible && !isOpeningRef.current) { + // Mark that we're in the opening process + isOpeningRef.current = true; + // Use requestAnimationFrame to ensure DOM has settled after the click + requestAnimationFrame(() => { + setStableMaxTagCount(0); + isOpeningRef.current = false; + }); + return; + } + if (!isDropdownVisible) { + // When closing, immediately show the first tag + setStableMaxTagCount(1); + isOpeningRef.current = false; + } + return; + } + setStableMaxTagCount(maxTagCount); + }, [maxTagCount, isDropdownVisible, oneLine]); + const mappedMode = isSingleMode ? undefined : 'multiple'; const sortSelectedFirst = useCallback( @@ -599,16 +626,16 @@ const Select = forwardRef( const omittedCount = useMemo(() => { const num_selected = ensureIsArray(selectValue).length; - const num_shown = maxTagCount as number; + const num_shown = stableMaxTagCount as number; return num_selected - num_shown - (selectAllMode ? 1 : 0); - }, [maxTagCount, selectAllMode, selectValue]); + }, [stableMaxTagCount, selectAllMode, selectValue]); const customMaxTagPlaceholder = () => `+ ${omittedCount > 0 ? omittedCount : 1} ...`; // We can't remove the + tag so when Select All // is the only item omitted, we subtract one from maxTagCount - let actualMaxTagCount = maxTagCount; + let actualMaxTagCount = stableMaxTagCount; if ( actualMaxTagCount !== 'responsive' && omittedCount === 0 && From d613a0aa9015eb1584a7f8877f9ca02568a2c8c5 Mon Sep 17 00:00:00 2001 From: Mehmet Salih Yavuz Date: Fri, 3 Oct 2025 18:52:23 +0300 Subject: [PATCH 2/2] test(Select): add tests for the fix --- .../src/components/Select/Select.test.tsx | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/superset-frontend/packages/superset-ui-core/src/components/Select/Select.test.tsx b/superset-frontend/packages/superset-ui-core/src/components/Select/Select.test.tsx index 93608a5031a6..e13c98c5473f 100644 --- a/superset-frontend/packages/superset-ui-core/src/components/Select/Select.test.tsx +++ b/superset-frontend/packages/superset-ui-core/src/components/Select/Select.test.tsx @@ -779,6 +779,38 @@ test('Renders only an overflow tag if dropdown is open in oneLine mode', async ( expect(withinSelector.getByText('+ 2 ...')).toBeVisible(); }); +// Test for checking the issue described in: https://github.com/apache/superset/issues/35132 +test('Maintains stable maxTagCount to prevent click target disappearing in oneLine mode', async () => { + render( + ,