Skip to content

refactor: searchbar component#5020

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

refactor: searchbar component#5020
MrMuzyk wants to merge 5 commits into
callstack:mainfrom
MrMuzyk:refactor/searchbar

Conversation

@MrMuzyk

@MrMuzyk MrMuzyk commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Motivation

Modernizes the Searchbar to the latest MD3 (Expressive) search spec by adopting the shared theme tokens (shape, motion, colors), extracting component-specific tokens, and adding the missing results container - following the token/structure conventions of the already-modernized TextInput/Switch/Checkbox/FAB. Also fixes the long-standing swapped input/placeholder colors and adds the missing focus transition.

Changes

Colors (tokens.ts / utils.ts)

  • Fixed swapped roles: input text onSurfaceVariant → onSurface; placeholder onSurface → onSurfaceVariant (MD3 order).
  • Container background resolved from the container token (surfaceContainerHigh) via getSearchbarColors, instead of a hardcoded color.

Shape

  • contained → corner.extraLarge (28dp), divided → none (0), resolved through the shared resolveCornerRadius util (src/theme/utils/shape.ts).

Motion - focus transition (new)

  • The contained bar grows a little wider when focused: its side margins shrink from 24dp to 12dp, then expand back on blur. It's a spring animation (Reanimated) and respects the OS "reduce motion" setting.
  • Note: contained mode (now the default) has side margins, where the old bar mode was full-width. Set a horizontal margin in style to override it — that also turns the focus animation off.

Structure

  • Moved Searchbar.tsx into its own src/components/Searchbar/ directory with tokens.ts (sizes/shape/colors), utils.ts (getSearchbarColors, getSearchbarInputFont), and
    index.tsx (attaches Results as a static sub-component) - mirroring Switch/Checkbox/FAB.

New sub-component — Searchbar.Results (SearchbarResults.tsx)

  • A Surface container for the results/suggestions list (MD3 search anatomy element 6). It provides only the surface; result grouping is left to the consumer. SearchbarResultsProps is exported from the package root.

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      

Related issue

#4978

Test plan

  • yarn typescript
  • yarn lint
  • yarn test
  • Visual verification (yarn example web):
    • Contained bar grows wider on focus; reduced-motion disables the animation
    • Input vs placeholder colors correct (input onSurface, placeholder onSurfaceVariant)
    • Divided mode: square corners + bottom divider; showDivider={false} hides it
    • Trailering icon / right item / loading states render correctly
    • Searchbar.Results renders the results list below the bar
searchbar.mp4

@MrMuzyk MrMuzyk marked this pull request as ready for review July 9, 2026 11:27
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.

1 participant