SwipeUI

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-search
Variant
Preset
Material
Scheme
Feel
Real free component with a browser animation bridge. Native motion, haptics and materials need a device.

When 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.tsx and 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 install so versions match your SDK.

Usage

app/(tabs)/index.tsx
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

PropTypeDefaultDescription
label?string—

Visible label, or inherit an enclosing Field.

helper?string—

Instructions under the field; an error or success message replaces it.

error?string—

Validation message: a destructive ring, an alert glyph, one shake and an error haptic.

success?string—

Confirmation under the field, such as "Username available", in the success colour.

status?FieldStatus'idle'

validating shows a spinner and reports busy; valid draws a check on. An error implies invalid.

required?booleanfalse

Required; "Required" is spoken, and requiredIndicator marks the label. The app owns validation.

requiredIndicator?FieldRequiredIndicator'asterisk'

How a required label is marked: a muted asterisk, the word, or nothing.

optionalIndicator?booleanfalse

Show a muted "Optional" after the label.

disabled?booleanfalse

Disable editing and accessory actions.

disabledStyle?FieldDisabledStyle'muted'

muted lightens the fill and text without opacity; dim lowers the field to 50%.

appearance?FieldAppearance'filled'

The surface: filled (a soft fill), outline (a hairline), underline or ghost (no fill until focused).

size?FieldSize'md'

Height: sm 36pt, md 44pt, lg 52pt.

shape?FieldShape'preset'

preset follows your preset's control radius; pill is a capsule.

labelPlacement?FieldLabelPlacement'above'

above, inset (small, inside at the top), floating (rests centred like a hint and rises on focus or once there's a value) or hidden (spoken only).

focusRing?FieldFocusRing'halo'

The focus indicator: a primary ring with a soft halo, the ring alone, or none.

messageMorph?FieldMessageMorph'fade'

How a changed message arrives: rises in, letter by letter, or at once.

reserveMessageSpace?booleanfalse

Keep one line of room under the field so forms don't move as messages appear.

value?string—

Controlled text.

defaultValue?string''

Initial uncontrolled text.

onValueChange?((value: string) => void)—

Reports changed text, including clearing and undo.

onChangeText?((value: string) => void)—

Native-compatible text callback, in addition to onValueChange.

displayValue?ReactNode—

Decorative rendering for an unfocused value; the native text remains the accessible/editable source.

prefix?ReactNode—

Decorative prefix or an accessible accessory, drawn first.

suffix?ReactNode—

Accessible trailing accessory, drawn last.

leadingIcon?ButtonIcon—

A leading icon: a node, or a function given the state colour and size. It turns primary while focused.

trailingIcon?ButtonIcon—

A trailing icon: a node, or a function given the state colour and size.

clearable?booleanfalse

1.x switch: true means clearButton="always".

clearButton?TextFieldClearButton'never' (or 'always' with `clearable`)

When a "Clear text" button shows.

undoClear?booleantrue

After clearing, the button becomes "Undo clear" for a moment. Phones have no ⌘Z.

undoClearWindow?number4000

How long undo stays, in milliseconds.

counter?TextFieldCounterfalse

A rolling character counter under the field, using maxLength; amber near the limit, red at it.

tintCaret?booleantrue

Caret and selection in the primary colour.

iconTint?"focus" | "none"'focus'

The leading icon turns primary while focused (focus) or stays muted (none).

shakeOnError?booleantrue

Shake once for each new error. Reduce Motion keeps it still.

messages?Partial<FieldMessages>FIELD_MESSAGES (English)

Built-in strings, for translation.

nextRef?React.RefObject<_TextInputInstance | null>—

Ref focused when Return is pressed; otherwise a single-line field dismisses.

haptics?boolean | FieldHapticstrue (clear, error and limit)

All feedback, or each part: { clear, error, valid, limit, focus }.

motion?MotionOverridethe app feel

Ring, label and message motion.

className?string—

Classes on the outer field.

controlClassName?string—

Classes on the field surface.

inputClassName?string—

Classes on the editable text.

style?StyleProp<ViewStyle>—

Outer field style.

inputStyle?____TextStyleProp_Internal—

Native editable text style.

onCancel?(() => void)—

Called after the in-field clear action clears the query.

onSearch?((value: string) => void)—

Called when the keyboard Search action is accepted; network work stays in the application.

expanded?boolean—

Controlled expanded state.

defaultExpanded?booleanfalse

Initial expanded state.

onExpandedChange?((expanded: boolean) => void)—

Reports expansion/collapse requests.

expandTo?"end" | "start"'end'

The way the field opens: end keeps the circle at the start and stretches toward the end (right in left-to-right layouts); start keeps it at the end and stretches back.

actions?ExpandingSearchActions'close'

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?"end" | "start"'end'

The side of the field the buttons sit on.

clearOnClose?booleantrue

Clears the query when the cross is pressed.

closeOnSubmit?booleantrue

Closes the field after the tick runs the search, keeping the query.

closeOnEmptyBlur?booleantrue

Closes when the field loses focus with nothing typed.

closeLabel?string'Close search'

Spoken name of the cross.

submitLabel?string'Search'

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: end keeps the circle at the start and grows toward the end, start grows back from the end.
  • actions shows a cross (close), a tick (submit), both or none beside 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 morph and press motion roles, so it follows your app's feel. Pass motion to 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 onSupported
Expo SDK 57Yes
Expo SDK 58Yes
React Native CLI (with Expo modules)Yes
Expo GoYes
iOSYes
AndroidYes

This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.

Related items