Skip to content

refactor: searchbar component - #5020

Open
MrMuzyk wants to merge 13 commits into
callstack:mainfrom
MrMuzyk:refactor/searchbar
Open

MrMuzyk wants to merge 13 commits into
callstack:mainfrom
MrMuzyk:refactor/searchbar

Conversation

@MrMuzyk

@MrMuzyk MrMuzyk commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Modernizes Searchbar to the MD3 Expressive spec using the shared theme tokens, like TextInput/Switch/Checkbox/FAB.

Changes

  • Fixes MD3 colors: input onSurface, placeholder onSurfaceVariant, leading icon onSurface.
  • Adds a focus transition: contained bar margins go 24 → 12dp (Reanimated CSS transition, off with reduce motion).
  • Adds Searchbar.Results, a results surface aligned with the focused bar.
  • Moves the component to src/components/Searchbar/ with tokens.ts and utils.ts.

Breaking change

Mode values are renamed to MD3 terminology

   // Before (v5)                                                                                                                                                          
   <Searchbar mode="bar" ... />   // default                                                                                                                               
   <Searchbar mode="view" ... />                                                                                                                                           
                                                                                                                                                                           
   // After (v6)                                                                                                                                                           
   <Searchbar mode="contained" ... />  // default                                                                                                                          
   <Searchbar mode="divided" ... />    // deprecated in M3 Expressive      

Contained mode (the default) now has 24dp side margins, where the old bar mode was full-width. Pass style={{ marginHorizontal: 0 }} to keep it full-width.

Related issue

#4978

Test plan

  • yarn typecheck, yarn lint, yarn test
  • Checked on web and Android: focus margins, colors, divided mode, results
searchbar.mp4

@MrMuzyk
MrMuzyk marked this pull request as ready for review July 9, 2026 11:27

@MikitasK MikitasK left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

great job 👍
just a few things comments from my side:

Comment thread src/components/Searchbar/Searchbar.tsx Resolved
Comment thread src/components/Searchbar/Searchbar.tsx Resolved

@MikitasK MikitasK left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  • updated implementation to preserve consumer layout styles on outer wrapper while keeping focus-margin animation on a separate Reanimated view
  • expanded HORIZONTAL_MARGIN_KEYS to include marginInline, marginInlineStart, marginInlineEnd
  • added regression tests & updated snapshots

Comment thread src/components/Searchbar/tokens.ts Resolved
Comment thread src/components/Searchbar/Searchbar.tsx Resolved
Comment thread src/components/Searchbar/Searchbar.tsx Resolved
@JKobrynski

Copy link
Copy Markdown
Collaborator

@MikitasK can you resolve the comments that were addressed?

@MikitasK

Copy link
Copy Markdown
Contributor

@MikitasK can you resolve the comments that were addressed?

hey, actually, I can't do that due to lack of access
maybe we can ask @MrMuzyk or try resolve it ourself

Comment thread src/components/Searchbar/Searchbar.tsx Resolved
@JKobrynski

Copy link
Copy Markdown
Collaborator

@MikitasK just one comment this time ☝️

Comment thread src/components/Searchbar/Searchbar.tsx Resolved
@JKobrynski

JKobrynski commented Sep 9, 2026 •

Copy link
Copy Markdown
Collaborator

This branch has a copy of built docs committed to id with 900+ files, please remove it 🙏 And also please resolve the conflicts, there've been some changes on main that will also influence this branch, like dropping default test IDs

@satya164
satya164 requested a balanced review from Copilot September 15, 2026 20:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@MikitasK
MikitasK force-pushed the refactor/searchbar branch 2 times, most recently from 671768a to 0c82a80 Compare September 21, 2026 17:12

@JKobrynski JKobrynski 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.

Could you rebuild migration.md, Searchbar.test.tsx and SearchbarExample.tsx from main's copies and re-apply only the Searchbar changes? Right now they undo #5095, #5099 and #5117, and Git won't flag it.

Comment thread docs/6.x/docs/guides/migration.md Resolved
Comment thread src/components/Searchbar/Searchbar.tsx Resolved
Comment thread src/components/Searchbar/Searchbar.tsx Resolved
Comment thread src/components/Searchbar/Searchbar.tsx Resolved
@satya164

Copy link
Copy Markdown
Contributor

Review by Claude

iOS

Searchbar.Results is wider than the bar above it

Steps: open the Searchbar example, scroll to "With results", type a, dismiss the keyboard.

What happens: the results surface spans the full screen width and its corners touch the screen edges. The contained bar above it has 24dp side margins, so the two do not line up.

What should happen: the results container lines up with the bar, as in the MD3 docked search view. (via Claude, verify if it makes sense)

iOS: results wider than the bar

Android

Searchbar.Results is wider than the bar above it

Steps: open the Searchbar example, scroll to "With results", type a.

What happens: the bar is focused with 12dp side margins, and the results surface below it has none.

What should happen: the results container lines up with the bar. (via Claude, verify if it makes sense)

Android: results wider than the bar

Web

Searchbar.Results is wider than the bar above it

Steps: open /searchbar, scroll to "With results", type a.

What happens: same as on native. The results surface is full width and the bar has 12dp side margins while focused.

What should happen: the results container lines up with the bar. (via Claude, verify if it makes sense)

Web: results wider than the bar

A click on the outer part of the clear button does not clear the text

Steps: focus the first bar under "Contained mode", type some text, then press the clear button within about 12px of its outer edge and release after about 100ms.

What happens: on mouse down the button takes focus and the input blurs. The bar animates back from 12dp to 24dp margins, so the clear button moves 12px inward while the button is held. The release lands outside the button and the text stays. Pressing Tab from the input to the clear button also collapses the bar while focus is still inside it.

What should happen: the bar stays expanded while focus is inside it, and the clear button clears the text wherever it is clicked. (via Claude, verify if it makes sense)

@satya164 satya164 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review by Claude

See the inline comments. (via Claude, verify if it makes sense)

Comment thread src/components/Searchbar/Searchbar.tsx Resolved
Comment thread src/components/Searchbar/Searchbar.tsx Resolved
Comment thread src/components/Searchbar/Searchbar.tsx Resolved
Comment thread src/components/Searchbar/Searchbar.tsx Resolved
@MikitasK

MikitasK commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Review by Claude

iOS

Searchbar.Results is wider than the bar above it

Steps: open the Searchbar example, scroll to "With results", type a, dismiss the keyboard.

What happens: the results surface spans the full screen width and its corners touch the screen edges. The contained bar above it has 24dp side margins, so the two do not line up.

What should happen: the results container lines up with the bar, as in the MD3 docked search view. (via Claude, verify if it makes sense)

iOS: results wider than the bar

Android

Searchbar.Results is wider than the bar above it

Steps: open the Searchbar example, scroll to "With results", type a.

What happens: the bar is focused with 12dp side margins, and the results surface below it has none.

What should happen: the results container lines up with the bar. (via Claude, verify if it makes sense)

Android: results wider than the bar

Web

Searchbar.Results is wider than the bar above it

Steps: open /searchbar, scroll to "With results", type a.

What happens: same as on native. The results surface is full width and the bar has 12dp side margins while focused.

What should happen: the results container lines up with the bar. (via Claude, verify if it makes sense)

Web: results wider than the bar

A click on the outer part of the clear button does not clear the text

Steps: focus the first bar under "Contained mode", type some text, then press the clear button within about 12px of its outer edge and release after about 100ms.

What happens: on mouse down the button takes focus and the input blurs. The bar animates back from 12dp to 24dp margins, so the clear button moves 12px inward while the button is held. The release lands outside the button and the text stays. Pressing Tab from the input to the clear button also collapses the bar while focus is still inside it.

What should happen: the bar stays expanded while focus is inside it, and the clear button clears the text wherever it is clicked. (via Claude, verify if it makes sense)

good catch 👍 both reproduced & fixed 👌

image

@Doberjohn Doberjohn added this to the 6.0.0 milestone Oct 30, 2026
@github-actions

Copy link
Copy Markdown

Found potential problems with the pull request:

  • The description is too long. Please keep it under 1000 characters.

@Doberjohn

Copy link
Copy Markdown
Collaborator

/review

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Apex Sentinel: 2 new findings on af55889. The verdict and the full list are in the summary comment.

Comment thread src/components/Searchbar/Searchbar.tsx Resolved

@kachmashk kachmashk 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 the effort! Left some comments and questions.
Also two things (as you can see on a screenshot, it comes from the MD3 docs):

  1. I tried using the input with a results for the divided SearchBar mode and it looks like it's missing,
  2. The other missing thing is the Results label at the top.
image

Comment thread src/components/Searchbar/tokens.ts Resolved
Comment thread src/components/Searchbar/utils.ts Resolved
Copilot AI balanced review requested due to automatic review settings November 25, 2026 15:48
Copilot stopped reviewing on behalf of MrMuzyk due to an error November 25, 2026 15:50
@MrMuzyk

MrMuzyk commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review! All comments are addressed. Searchbar.Results now takes a mode prop, so mode="divided" renders full width under the divider. The example shows a Results label as a List.Subheader, which I kept as content rather than a prop since the spec fills the container with list components. Happy to add a label prop if you'd prefer. "Deprecated" is now "not recommended", and the color changes are documented in migration.md.

@MrMuzyk
MrMuzyk requested a review from kachmashk November 25, 2026 16:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@kachmashk kachmashk 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 addressing the feedback!

Copilot AI balanced review requested due to automatic review settings November 26, 2026 12:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Searchbar lacks reduced-motion and internal focus-retention test coverage, and the results component’s documentation name does not match the public Searchbar.Results API.

3 open issues

Review effort: Balanced

Comment on lines +347 to +350
React.useEffect(() => {
if (!focusHeldInside || Platform.OS !== 'web') {
return;
}
style,
]}
// `Surface` applies its own duration after `style`, hence the prop.
transitionDuration={reduceMotion ? 0 : theme.motion.duration.medium2}
},
});

export default SearchbarResults;
@Doberjohn

Copy link
Copy Markdown
Collaborator

/review

@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 776f040

Since the review of af55889: 1 new · 0 still open · 2 no longer raised

1 finding(s): 1 minor.

🟡 Minor (1)

Where Finding
src/components/Searchbar/Searchbar.tsx:468 🆕 Clear icon ignores the iconColor prop it used to follow; undocumented change
Not in the reviewers' scope (2 files)
  • src/components/__tests__/Appbar/__snapshots__/Appbar.test.tsx.snap: generated or a lockfile, so its lines were left out
  • src/components/__tests__/__snapshots__/Searchbar.test.tsx.snap: generated or a lockfile, so its lines were left out

1 finding below minor hidden (user_settings.min_severity).

Reviewed with this repository's own Sentinel configuration (63a3d5acf854).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Apex Sentinel: 1 new finding on 776f040. The verdict and the full list are in the summary comment.

Comment on lines 468 to +471
<IconButton
borderless
aria-label={clearAccessibilityLabel}
iconColor={value ? iconColor : 'rgba(255, 255, 255, 0)'}
iconColor={value ? trailingIconColor : 'rgba(255, 255, 255, 0)'}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🆕 🟡 Minor · Clear icon ignores the iconColor prop it used to follow; undocumented change

<Searchbar iconColor="purple" value="value" /> no longer tints the clear icon—it stays onSurfaceVariant while the magnify icon turns purple. The migration guide's "keep the 5.x colors" snippet tells callers to pass iconColor, but never mentions the clear icon, so a caller following it loses the 5.x tint with no note.

Suggested change

State in the migration guide's Searchbar section that iconColor now affects only the leading icon, and that the clear icon follows the trailing-icon color (set trailingIconColor to keep a 5.x tint on it).

Details

Also raised here

Also raised at this location by persona senior-developer: iconColor no longer tints the clear icon; migration note tells users it does — In 5.x the clear (X) button used customIconColor || colors.onSurfaceVariant, so an app that passed iconColor got a matching clear icon. It now uses trailingIconColor (colors.onSurfaceVariant) and ignores iconColor entirely (src/components/Searchbar/Searchbar.tsx:471), so that app's clear icon changes color on upgrade. The new Searchbar section of docs/6.x/docs/guides/migration.md (lines 995-1047) only mentions input, placeholder and leading-icon colors and tells readers to "keep the 5.x colors" by passing inputStyle, placeholderTextColor and iconColor — following that advice does not restore the 5.x clear icon, and the migration doc for this component never states that iconColor stopped affecting it. Add that line to the section (the clear icon follows trailingIconColor now).

Also raised at this location by persona maintainability: Clear icon no longer respects iconColor — undocumented breaking change — A consumer passing iconColor="purple" previously got a purple clear icon (because iconColor = customIconColor || theme.colors.onSurfaceVariant fed both leading and clear icons). The new code always uses trailingIconColor (= onSurfaceVariant) for the clear icon regardless of customIconColor. This is an intentional separation per the test, but the migration guide section on Searchbar colors only mentions input/placeholder/leading icon changes — the clear icon color change is undocumented, so callers upgrading from v5 will see an unexpected visual difference with no migration note.

persona: react-native-paper, senior-developer, maintainability, javascript

Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.

Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if it is wrong — I will re-check the cited code.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants