Expanding search
A search circle that stretches into a field toward either side, with a cross, a tick or both beside it.
npx @swipeui/cli add expanding-searchWhen to use it
- Toolbars and headers where search should stay a small icon until needed.
- Screens where search is occasional, such as settings or a media library.
- Compact layouts where a full search field would crowd other actions.
When not to use it
- Search-first screens. Keep Search field always visible.
- Search in a collapsing header. Use Search header.
- When the icon would be the only way to find important content.
Installation
Run this from your app's root. If SwipeUI isn't set up yet, run npx @swipeui/cli init first; it sets up Uniwind, the theme tokens and the cn helper.
npx @swipeui/cli add expanding-search- Adds
components/swipeui/ui/expanding-search.tsxand 14 shared helpers. - Installs react-native-reanimated, react-native-worklets, uniwind, clsx, tailwind-merge, expo-haptics, class-variance-authority, react-native-svg. In Expo apps it uses
npx expo installso versions match your SDK.
Usage
import { ExpandingSearch } from '@/components/swipeui/ui/expanding-search';
<ExpandingSearch label="Search" expandTo="start" actions="both" onSearch={search} />;Examples
Use the variant and appearance controls in the live specimen to compare the documented states. The application owns validation, operation results and persistence.
API reference
ExpandingSearchProps
| Prop | Type | Default | Description |
|---|---|---|---|
label? | | — | Visible label, or inherit an enclosing Field. |
helper? | | — | Instructions under the field; an error or success message replaces it. |
error? | | — | Validation message: a destructive ring, an alert glyph, one shake and an error haptic. |
success? | | — | Confirmation under the field, such as "Username available", in the success colour. |
status? | | |
|
required? | | | Required; "Required" is spoken, and |
requiredIndicator? | | | How a required label is marked: a muted asterisk, the word, or nothing. |
optionalIndicator? | | | Show a muted "Optional" after the label. |
disabled? | | | Disable editing and accessory actions. |
disabledStyle? | | |
|
appearance? | | | The surface: |
size? | | | Height: |
shape? | | |
|
labelPlacement? | | |
|
focusRing? | | | The focus indicator: a primary ring with a soft halo, the ring alone, or none. |
messageMorph? | | | How a changed message arrives: rises in, letter by letter, or at once. |
reserveMessageSpace? | | | Keep one line of room under the field so forms don't move as messages appear. |
value? | | — | Controlled text. |
defaultValue? | | | Initial uncontrolled text. |
onValueChange? | | — | Reports changed text, including clearing and undo. |
onChangeText? | | — | Native-compatible text callback, in addition to onValueChange. |
displayValue? | | — | Decorative rendering for an unfocused value; the native text remains the accessible/editable source. |
prefix? | | — | Decorative prefix or an accessible accessory, drawn first. |
suffix? | | — | Accessible trailing accessory, drawn last. |
leadingIcon? | | — | A leading icon: a node, or a function given the state colour and size. It turns primary while focused. |
trailingIcon? | | — | A trailing icon: a node, or a function given the state colour and size. |
clearable? | | | 1.x switch: |
clearButton? | | | When a "Clear text" button shows. |
undoClear? | | | After clearing, the button becomes "Undo clear" for a moment. Phones have no ⌘Z. |
undoClearWindow? | | | How long undo stays, in milliseconds. |
counter? | | | A rolling character counter under the field, using |
tintCaret? | | | Caret and selection in the primary colour. |
iconTint? | | | The leading icon turns primary while focused ( |
shakeOnError? | | | Shake once for each new error. Reduce Motion keeps it still. |
messages? | | | Built-in strings, for translation. |
nextRef? | | — | Ref focused when Return is pressed; otherwise a single-line field dismisses. |
haptics? | | | All feedback, or each part: |
motion? | | | Ring, label and message motion. |
className? | | — | Classes on the outer field. |
controlClassName? | | — | Classes on the field surface. |
inputClassName? | | — | Classes on the editable text. |
style? | | — | Outer field style. |
inputStyle? | | — | Native editable text style. |
onCancel? | | — | Called after the in-field clear action clears the query. |
onSearch? | | — | Called when the keyboard Search action is accepted; network work stays in the application. |
expanded? | | — | Controlled expanded state. |
defaultExpanded? | | | Initial expanded state. |
onExpandedChange? | | — | Reports expansion/collapse requests. |
expandTo? | | | The way the field opens: |
actions? | | | The round buttons that appear beside the open field: a cross that closes, a tick that searches, both, or none (the keyboard's Search key and a blur still work). |
actionsSide? | | | The side of the field the buttons sit on. |
clearOnClose? | | | Clears the query when the cross is pressed. |
closeOnSubmit? | | | Closes the field after the tick runs the search, keeping the query. |
closeOnEmptyBlur? | | | Closes when the field loses focus with nothing typed. |
closeLabel? | | | Spoken name of the cross. |
submitLabel? | | | Spoken name of the tick. |
Native view/input props not listed here pass through where the exported TypeScript type allows them.
Composition and behavior
- A search circle that stretches into a live field, the way a header search opens. expandTo picks the direction:
endkeeps the circle at the start and grows toward the end,startgrows back from the end. - actions shows a cross (
close), a tick (submit),bothornonebeside the open field; actionsSide puts them before or after it. - The cross clears the query (unless clearOnClose is off) and closes. The tick runs onSearch with the query and closes, keeping it (unless closeOnSubmit is off). The keyboard's Search key also runs onSearch.
- Control with expanded and onExpandedChange. The capsule and circles take the theme's material, glass with the Glass material.
Behavior and gestures
- Tap the search icon and it expands into a focused search field with the keyboard up.
- Cancel clears the field, closes the keyboard and collapses back to the icon.
- Search, clear and onSearch work like Search field.
Accessibility
- The icon is a button named "Open search" that reports collapsed state.
- Focus moves into the field when it expands.
- Disabled state turns off the icon.
Motion
- Uses the
morphandpressmotion roles, so it follows your app's feel. Passmotionto tune this one instance. - The icon morphs into the field with the morph role.
- Reduce Motion swaps them instantly.
Performance
- The field mounts only when expanded.
Notes for AI
- Use expanded with onExpandedChange, or defaultExpanded.
Compatibility
| Runs on | Supported |
|---|---|
| Expo SDK 57 | Yes |
| Expo SDK 58 | Yes |
| React Native CLI (with Expo modules) | Yes |
| Expo Go | Yes |
| iOS | Yes |
| Android | Yes |
This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.