Skip to content

fix(searchbar): hide the clear button when empty - #5208

Open
vivekjm wants to merge 5 commits into
callstack:mainfrom
vivekjm:fix/searchbar-hidden-clear-button
Open

vivekjm wants to merge 5 commits into
callstack:mainfrom
vivekjm:fix/searchbar-hidden-clear-button

Conversation

@vivekjm

@vivekjm vivekjm commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

An empty Searchbar's transparent Clear button still accepts keyboard focus and appears in the accessibility tree. Hide it from assistive technology and disable focus and activation until the field has text. Keep it mounted so the ripple can finish when the field is cleared.

Related issue

Related to #4757.

Screenshots / Videos

The layout stays the same.

Test plan

  • The new empty → populated → empty regression failed on main and passed with the fix. All 57 Jest suites, lint, and type checking passed.
  • In Chrome, Tab skipped Clear when empty and reached it after typing. Enter cleared the query and removed Clear from the accessibility tree.
  • Native screen reader checks are pending.

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Found potential problems with the pull request:

  • Screenshot or video evidence is missing. Make sure to include one if it affects the UI.

@Doberjohn

Doberjohn commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Before the review, could you add the native screen reader check your test plan mentions? A short clip each with TalkBack on Android and VoiceOver on iOS would be enough, showing:

  1. With the field empty, swiping through the Searchbar never lands on the clear button.
  2. After typing, the clear button is reachable, is announced with its label, and clears the field when activated.
  3. After clearing, it's gone from the swipe order again.

"Related to #4757" is the right link: the empty space where the button sits stays, so that issue remains open.

A heads-up: #5020 rewrites Searchbar and moves the file to src/components/Searchbar/Searchbar.tsx. This PR can land first once it's reviewed, and #5020 will carry the change over.

While you're here: #5014 still needs main merged in, the snapshots regenerated and its test adapted to the test ID changes from #5088 and #5099. Is that still on your list?

@vivekjm

vivekjm commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for spelling out the swipe sequence and for the heads-up on #5020. The Chrome check covers the empty, populated, and cleared states. I haven't verified the native swipe order yet. VoiceOver needs a physical iOS device, and I don't have one connected here.

I also refreshed #5014 against current main (0c9b7af) in 7fbc22c. Its regression uses the button role, and all 57 Jest suites passed on the updated branch with the snapshots in place.

@vivekjm

vivekjm commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

I found a way to test this with VoiceOver on the iOS 27 simulator. On the current PR commit (3fb596cc), forward navigation skipped Clear when the field was empty, announced “clear, button” after I entered text, and skipped it again after activation cleared the field. I have a silent recording of the sequence and the spoken label was verified from the VoiceOver test output. The Android TalkBack sequence is still pending.

@Doberjohn Doberjohn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for porting this onto the rewritten Searchbar. Hiding the empty Clear button from assistive technology and from the tab order is the right fix, and the new test covers it well. Two things before it can merge:

  1. onPress={value ? handleClearPress : undefined} undoes the reason the button stays mounted. Without a press handler, TouchableRipple renders a plain View instead of a Pressable (its !isControl branch, on web and on native). So when a press on Clear empties the field, the Pressable the ripple is drawn in gets replaced, and the ripple is cut off mid-animation on web and on Android. Could you keep onPress={handleClearPress} as on main? The wrapper's pointerEvents="none" already stops touches while the field is empty (the existing "does not respond to touch" test covers that), and focusable={false} with aria-hidden keep it out of the tab order and the accessibility tree. The comment above the View then stays true.

  2. When a keyboard user clears the field with Enter, the button they are on becomes hidden while it still has focus. Moving focus back to the input in handleClearPress (root.current?.focus()) would fix that, and the input is where focus belongs after clearing.

Then the screen reader checks: the VoiceOver run was on 3fb596c, before the port, and TalkBack is still open. Could you rerun both on the latest commit once these are in?

@Doberjohn Doberjohn added this to the 6.1.0 milestone Dec 4, 2026
@vivekjm

vivekjm commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, @Doberjohn. The Clear button now keeps its press handler and stays mounted as a Pressable, so clearing the query preserves the ripple host. Clearing also returns focus to the input. I set the empty button's tab index explicitly because React Native Web defaults Pressable to a tab stop while the handler is attached.

I verified on 65e460e that Chrome skips the empty button, tabs to it with text present, and returns focus to the cleared input after Enter. The button kept the same DOM node. VoiceOver on an iOS 27 iPhone 18 Pro simulator skipped Clear when empty, announced “clear Button” with text present, and cleared the field on activation. After clearing, VoiceOver skipped the button again. All 1,799 Jest tests passed.

TalkBack is still pending. No Android device was connected for this run.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants