<!--
{
  "availability" : [
    "macOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSSearchToolbarItem",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSSearchToolbarItem"
  },
  "title" : "NSSearchToolbarItem"
}
-->

# NSSearchToolbarItem

A toolbar item that contains a search field optimized for performing text-based searches.

```
class NSSearchToolbarItem
```

## Overview

[`NSSearchToolbarItem`](/documentation/AppKit/NSSearchToolbarItem) automatically resizes to accommodate typing when the focus switches to the toolbar item. When the toolbar is low on space, the system may collapse the search item into a button representation, which then expands to a full search field when the user clicks on it.

## Topics

### Configuring a search item

[`preferredWidthForSearchField`](/documentation/AppKit/NSSearchToolbarItem/preferredWidthForSearchField)

The preferred width for the toolbar item when it has keyboard focus.

[`resignsFirstResponderWithCancel`](/documentation/AppKit/NSSearchToolbarItem/resignsFirstResponderWithCancel)

A Boolean value that enables the cancel button in the search field to resign the first responder in addition to clearing the contents.

[`searchField`](/documentation/AppKit/NSSearchToolbarItem/searchField)

The search field inside the toolbar item.

### Controlling search interactions

[`beginSearchInteraction()`](/documentation/AppKit/NSSearchToolbarItem/beginSearchInteraction())

Starts a search interaction and moves the keyboard focus to the search field.

[`endSearchInteraction()`](/documentation/AppKit/NSSearchToolbarItem/endSearchInteraction())

Ends a search interaction by giving up the first responder and adjusting the size of the search field to the available width for the toolbar item if necessary.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)