This is an automated email from the ASF dual-hosted git repository. elizabeth pushed a commit to branch elizabeth/fix-resize-bug in repository https://gitbox.apache.org/repos/asf/superset.git
commit 883bb5a7df464bbec00073b15d93e5b55b5efe41 Author: Beto Dealmeida <[email protected]> AuthorDate: Tue Jul 29 14:01:10 2025 -0400 feat: focus on text input when modal opens (#34379) --- .../controls/VizTypeControl/VizTypeControl.test.tsx | 21 +++++++++++++++++++++ .../controls/VizTypeControl/VizTypeGallery.tsx | 7 +++++++ 2 files changed, 28 insertions(+) diff --git a/superset-frontend/src/explore/components/controls/VizTypeControl/VizTypeControl.test.tsx b/superset-frontend/src/explore/components/controls/VizTypeControl/VizTypeControl.test.tsx index 4e6665a1e6..fd93c33de2 100644 --- a/superset-frontend/src/explore/components/controls/VizTypeControl/VizTypeControl.test.tsx +++ b/superset-frontend/src/explore/components/controls/VizTypeControl/VizTypeControl.test.tsx @@ -41,6 +41,9 @@ import { import TableChartPlugin from '../../../../../plugins/plugin-chart-table/src'; import VizTypeControl, { VIZ_TYPE_CONTROL_TEST_ID } from './index'; +// Mock scrollIntoView to avoid errors in test environment +jest.mock('scroll-into-view-if-needed', () => jest.fn()); + jest.useFakeTimers(); class MainPreset extends Preset { @@ -256,4 +259,22 @@ describe('VizTypeControl', () => { expect(defaultProps.onChange).toHaveBeenCalledWith(VizType.Line); }); + + it('Search input is focused when modal opens', async () => { + // Mock the focus method to track if it was called + const focusSpy = jest.fn(); + const originalFocus = HTMLInputElement.prototype.focus; + HTMLInputElement.prototype.focus = focusSpy; + + await waitForRenderWrapper(); + + const searchInput = screen.getByTestId(getTestId('search-input')); + + // Verify that focus() was called on the search input + expect(focusSpy).toHaveBeenCalled(); + expect(searchInput).toBeInTheDocument(); + + // Restore the original focus method + HTMLInputElement.prototype.focus = originalFocus; + }); }); diff --git a/superset-frontend/src/explore/components/controls/VizTypeControl/VizTypeGallery.tsx b/superset-frontend/src/explore/components/controls/VizTypeControl/VizTypeGallery.tsx index 8453f56dad..b5f888e7c0 100644 --- a/superset-frontend/src/explore/components/controls/VizTypeControl/VizTypeGallery.tsx +++ b/superset-frontend/src/explore/components/controls/VizTypeControl/VizTypeGallery.tsx @@ -575,6 +575,13 @@ export default function VizTypeGallery(props: VizTypeGalleryProps) { setIsSearchFocused(true); }, []); + // Auto-focus the search input when the modal opens + useEffect(() => { + if (searchInputRef.current) { + searchInputRef.current.focus(); + } + }, []); + const changeSearch: ChangeEventHandler<HTMLInputElement> = useCallback( event => setSearchInputValue(event.target.value), [],
