> For the complete documentation index, see [llms.txt](https://swift-packages.gitbook.io/materialuikit/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://swift-packages.gitbook.io/materialuikit/components/search-box.md).

# 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.

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

Creates a search box with a custom placeholder text.

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

### Parameters

<table data-header-hidden><thead><tr><th width="211"></th><th></th></tr></thead><tbody><tr><td><strong>Parameter</strong></td><td><strong>Description</strong></td></tr><tr><td><code>placeholder</code></td><td>The placeholder text to display when the search bar is empty.</td></tr><tr><td><code>searchText</code></td><td>A binding to the text that the user enters into the search bar.</td></tr><tr><td><code>action</code></td><td>A closure to execute when the user triggers the search action.</td></tr></tbody></table>

### Example

Displays a search box with default placeholder text.

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

<figure><picture><source srcset="/files/KlgvNliAJWRgekrZSoBQ" media="(prefers-color-scheme: dark)"><img src="https://2931569195-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHpwjDgYAa64eKF8AGmeE%2Fuploads%2FD38ZD5uCRQO6fiaFruck%2FSearbox%20Light.png?alt=media&amp;token=95877152-1b7e-4de0-9a24-92519273131e" alt=""></picture><figcaption></figcaption></figure>

Displays a search box with custom placeholder.

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

<figure><picture><source srcset="/files/ks6ppgdLgyUUUvSJz7KW" media="(prefers-color-scheme: dark)"><img src="https://2931569195-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHpwjDgYAa64eKF8AGmeE%2Fuploads%2F3NjAwlFlEOaUBzx7yxqE%2FCustom%20searchbox%20light.png?alt=media&amp;token=447abac5-3518-4001-a4fc-40a7ca46c55a" alt=""></picture><figcaption></figcaption></figure>
