Search Box

Represents a Material UI styled search box for user input and search actions.

Overview

The SearchBox view provides a customizable search bar with Material UI styling. A search button appears when text is entered, allowing users to trigger a search action.

To use the SearchBox, initialize it with a binding to the search text and a closure for the search action. Optionally, provide a custom placeholder text.

Initializers

Creates a search box with a default placeholder text.

SearchBox(searchText: Binding<String>, _ action: @escaping () -> Void)

Creates a search box with a custom placeholder text.

SearchBox(
   _ placeholder: String,
   searchText: Binding<String>,
   _ action: @escaping () -> Void
)

Parameters

Parameter

Description

placeholder

The placeholder text to display when the search bar is empty.

searchText

A binding to the text that the user enters into the search bar.

action

A closure to execute when the user triggers the search action.

Example

Displays a search box with default placeholder text.

SearchBox(searchText: $query) {
    Void()
}

Displays a search box with custom placeholder.

SearchBox("Search here", searchText: $query) {
    Void()
}

Last updated