From 3fb596cc97a116647c095e97f5c32eb927cc5689 Mon Sep 17 00:00:00 2001 From: Vivek JM Date: Thu, 12 Nov 2026 01:09:58 +0530 Subject: [PATCH 1/3] fix(searchbar): hide the clear button when empty --- src/components/Searchbar.tsx | 10 +++++----- .../Appbar/__snapshots__/Appbar.test.tsx.snap | 5 +++-- src/components/__tests__/Searchbar.test.tsx | 17 +++++++++++++++++ .../__snapshots__/Searchbar.test.tsx.snap | 10 ++++++---- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/components/Searchbar.tsx b/src/components/Searchbar.tsx index f1f6adbbfd..011d45815e 100644 --- a/src/components/Searchbar.tsx +++ b/src/components/Searchbar.tsx @@ -300,10 +300,8 @@ const Searchbar = ({ {loading ? ( ) : ( - // Clear icon should be always rendered within Searchbar – it's transparent, - // without touch events, when there is no value. It's done to avoid issues - // with the abruptly stopping ripple effect and changing bar width on web, - // when clearing the value. + // Keep the clear button mounted so its ripple can finish and clearing + // the value does not cause a layout shift on web. ( diff --git a/src/components/__tests__/Appbar/__snapshots__/Appbar.test.tsx.snap b/src/components/__tests__/Appbar/__snapshots__/Appbar.test.tsx.snap index 5ff794c9c0..5009f1d4ff 100644 --- a/src/components/__tests__/Appbar/__snapshots__/Appbar.test.tsx.snap +++ b/src/components/__tests__/Appbar/__snapshots__/Appbar.test.tsx.snap @@ -382,7 +382,7 @@ exports[`Appbar does not pass any additional props to Searchbar 1`] = ` { "busy": undefined, "checked": undefined, - "disabled": false, + "disabled": true, "expanded": undefined, "selected": undefined, } @@ -396,9 +396,10 @@ exports[`Appbar does not pass any additional props to Searchbar 1`] = ` } } accessible={true} + aria-hidden={true} centered={true} collapsable={false} - focusable={true} + focusable={false} hitSlop={ { "bottom": 6, diff --git a/src/components/__tests__/Searchbar.test.tsx b/src/components/__tests__/Searchbar.test.tsx index ac39f78662..0f07688a9a 100644 --- a/src/components/__tests__/Searchbar.test.tsx +++ b/src/components/__tests__/Searchbar.test.tsx @@ -65,6 +65,23 @@ it('does not respond to touch on the clear icon when search has no value', async expect(onClearIconPressMock).not.toHaveBeenCalled(); }); +it('exposes the clear button only while there is a search value', async () => { + const { rerender } = await render(); + + expect(screen.queryByRole('button', { name: 'clear' })).toBeNull(); + expect( + screen.getByRole('button', { name: 'clear', includeHiddenElements: true }) + ).toHaveProp('focusable', false); + + await rerender(); + + expect(screen.getByRole('button', { name: 'clear' })).toBeEnabled(); + + await rerender(); + + expect(screen.queryByRole('button', { name: 'clear' })).toBeNull(); +}); + it('defines onClearIconPress action and checks if it is called when close button is pressed', async () => { const onClearIconPressMock = jest.fn(); await render( diff --git a/src/components/__tests__/__snapshots__/Searchbar.test.tsx.snap b/src/components/__tests__/__snapshots__/Searchbar.test.tsx.snap index c200e71706..8931ff2d77 100644 --- a/src/components/__tests__/__snapshots__/Searchbar.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/Searchbar.test.tsx.snap @@ -723,7 +723,7 @@ exports[`renders searchbar in "view" mode 1`] = ` { "busy": undefined, "checked": undefined, - "disabled": false, + "disabled": true, "expanded": undefined, "selected": undefined, } @@ -737,9 +737,10 @@ exports[`renders searchbar in "view" mode 1`] = ` } } accessible={true} + aria-hidden={true} centered={true} collapsable={false} - focusable={true} + focusable={false} hitSlop={ { "bottom": 6, @@ -1126,7 +1127,7 @@ exports[`renders with placeholder 1`] = ` { "busy": undefined, "checked": undefined, - "disabled": false, + "disabled": true, "expanded": undefined, "selected": undefined, } @@ -1140,9 +1141,10 @@ exports[`renders with placeholder 1`] = ` } } accessible={true} + aria-hidden={true} centered={true} collapsable={false} - focusable={true} + focusable={false} hitSlop={ { "bottom": 6, From 923ef629304933a05124c0be4fb873f085beeb19 Mon Sep 17 00:00:00 2001 From: Vivek JM Date: Sat, 5 Dec 2026 12:29:04 +0530 Subject: [PATCH 2/3] fix(searchbar): keep the clear ripple and restore input focus --- src/components/Searchbar/Searchbar.tsx | 3 +- .../Appbar/__snapshots__/Appbar.test.tsx.snap | 37 ++- src/components/__tests__/Searchbar.test.tsx | 31 ++- .../__snapshots__/Searchbar.test.tsx.snap | 222 ++++++++++++++++-- 4 files changed, 269 insertions(+), 24 deletions(-) diff --git a/src/components/Searchbar/Searchbar.tsx b/src/components/Searchbar/Searchbar.tsx index 3a8b276727..662be204a6 100644 --- a/src/components/Searchbar/Searchbar.tsx +++ b/src/components/Searchbar/Searchbar.tsx @@ -298,6 +298,7 @@ const Searchbar = ({ const handleClearPress = (e: any) => { root.current?.clear(); + root.current?.focus(); rest.onChangeText?.(''); onClearIconPress?.(e); }; @@ -484,7 +485,7 @@ const Searchbar = ({ ? customTrailingIconColor || trailingIconColor : 'rgba(255, 255, 255, 0)' } - onPress={value ? handleClearPress : undefined} + onPress={handleClearPress} icon={ clearIcon || (({ size, color }) => ( diff --git a/src/components/__tests__/Appbar/__snapshots__/Appbar.test.tsx.snap b/src/components/__tests__/Appbar/__snapshots__/Appbar.test.tsx.snap index c8e88992a7..0430f2978b 100644 --- a/src/components/__tests__/Appbar/__snapshots__/Appbar.test.tsx.snap +++ b/src/components/__tests__/Appbar/__snapshots__/Appbar.test.tsx.snap @@ -335,16 +335,47 @@ exports[`Appbar does not pass any additional props to Searchbar 1`] = ` } > { await rerender(); - expect(screen.getByRole('button', { name: 'clear' })).toBeEnabled(); + const clearButton = screen.getByRole('button', { name: 'clear' }); + expect(clearButton).toBeEnabled(); await rerender(); expect(screen.queryByRole('button', { name: 'clear' })).toBeNull(); + const hiddenClearButton = screen.getByLabelText('clear', { + includeHiddenElements: true, + }); + expect(hiddenClearButton).toBe(clearButton); + expect(hiddenClearButton).toHaveProp('focusable', false); +}); + +it('returns focus to the search input after clearing', async () => { + const focusSpy = jest.spyOn(NativeTextInput.prototype, 'focus'); + const onChangeText = jest.fn(); + try { + await render(); + await userEvent.press(screen.getByRole('button', { name: 'clear' })); + + expect(onChangeText).toHaveBeenCalledWith(''); + expect(focusSpy).toHaveBeenCalledTimes(1); + } finally { + focusSpy.mockRestore(); + } }); it('defines onClearIconPress action and checks if it is called when close button is pressed', async () => { diff --git a/src/components/__tests__/__snapshots__/Searchbar.test.tsx.snap b/src/components/__tests__/__snapshots__/Searchbar.test.tsx.snap index b4fa3f24e1..10c0946218 100644 --- a/src/components/__tests__/__snapshots__/Searchbar.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/Searchbar.test.tsx.snap @@ -726,16 +726,47 @@ exports[`fills a custom vertical layout {"flex":1} 1`] = ` } > Date: Sat, 5 Dec 2026 12:36:12 +0530 Subject: [PATCH 3/3] fix(searchbar): skip the empty clear button in web tab order --- src/components/Searchbar/Searchbar.tsx | 1 + .../__tests__/Appbar/__snapshots__/Appbar.test.tsx.snap | 1 + src/components/__tests__/Searchbar.test.tsx | 1 + .../__tests__/__snapshots__/Searchbar.test.tsx.snap | 6 ++++++ 4 files changed, 9 insertions(+) diff --git a/src/components/Searchbar/Searchbar.tsx b/src/components/Searchbar/Searchbar.tsx index 662be204a6..3998f01af4 100644 --- a/src/components/Searchbar/Searchbar.tsx +++ b/src/components/Searchbar/Searchbar.tsx @@ -480,6 +480,7 @@ const Searchbar = ({ aria-hidden={value ? undefined : true} aria-label={clearAccessibilityLabel} focusable={value ? undefined : false} + tabIndex={value ? undefined : -1} iconColor={ value ? customTrailingIconColor || trailingIconColor diff --git a/src/components/__tests__/Appbar/__snapshots__/Appbar.test.tsx.snap b/src/components/__tests__/Appbar/__snapshots__/Appbar.test.tsx.snap index 0430f2978b..8bf5bfb236 100644 --- a/src/components/__tests__/Appbar/__snapshots__/Appbar.test.tsx.snap +++ b/src/components/__tests__/Appbar/__snapshots__/Appbar.test.tsx.snap @@ -397,6 +397,7 @@ exports[`Appbar does not pass any additional props to Searchbar 1`] = ` ], ] } + tabIndex={-1} > { }); expect(hiddenClearButton).toBe(clearButton); expect(hiddenClearButton).toHaveProp('focusable', false); + expect(hiddenClearButton).toHaveProp('tabIndex', -1); }); it('returns focus to the search input after clearing', async () => { diff --git a/src/components/__tests__/__snapshots__/Searchbar.test.tsx.snap b/src/components/__tests__/__snapshots__/Searchbar.test.tsx.snap index 10c0946218..9c49cabe32 100644 --- a/src/components/__tests__/__snapshots__/Searchbar.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/Searchbar.test.tsx.snap @@ -788,6 +788,7 @@ exports[`fills a custom vertical layout {"flex":1} 1`] = ` ], ] } + tabIndex={-1} >