# Search Field

A search input with magnifier icon and clear button.

> For the complete documentation index, see [llms.txt](/llms.txt). Markdown variants are available by appending `.md` to any URL or sending an `Accept: text/markdown` header. An agent skill is available at [/.well-known/agent-skills/site-skill.md](/.well-known/agent-skills/site-skill.md).



<ComponentPreview name="search-field/Basic" />

## Import [#import]

```rust
use maccn::MacSearchField;
```

## Usage [#usage]

```rust
let state = cx.new(|cx| InputState::new(window, cx).placeholder("Search"));

MacSearchField::new("search", &state);
```

## Clearing [#clearing]

<ComponentPreview name="search-field/Clearing" />

```rust
use gpui::div;
use maccn::{MacLabel, MacSearchField};
use maccn::LabelStyle;

div()
    .flex()
    .flex_col()
    .gap_2()
    .child(MacSearchField::new("search-clear", &state).w(px(220.)))
    .child(
        MacLabel::new("search-hint")
            .style(LabelStyle::Footnote)
            .secondary(true)
            .child("Type text to reveal the clear button; press Escape to clear."),
    )
```

## Sizes [#sizes]

<ComponentPreview name="search-field/Sizes" />

```rust
use gpui::div;
use maccn::{MacControlSize, MacSearchField};

div()
    .flex()
    .items_center()
    .gap_2()
    .child(
        MacSearchField::new("search-xl", &state)
            .size(MacControlSize::ExtraLarge)
            .w(px(240.)),
    )
    .child(
        MacSearchField::new("search-s", &state)
            .size(MacControlSize::Small)
            .w(px(180.)),
    )
```

## Disabled [#disabled]

<ComponentPreview name="search-field/Disabled" />

```rust
MacSearchField::new("search-d", &state)
    .disabled(true)
    .w(px(220.))
```

## API [#api]

### Props [#props]

| Prop       | Type             | Default   |
| ---------- | ---------------- | --------- |
| `size`     | `MacControlSize` | `Regular` |
| `disabled` | `bool`           | `false`   |

### InputState [#inputstate]

`MacSearchField::new(id, &state)` requires an `Entity<InputState>` created with `InputState::new(window, cx)`.
