---
url: https://talkjs.com/docs/UI_Components/Theme/Theme_components/ChatSearchBox/
title: "<ChatSearchBox> | Theme components | TalkJS Docs"
---

For AI agents: Find a documentation index at https://talkjs.com/llms.txt (full content at https://talkjs.com/llms-full.txt). Get a markdown version of any page by appending .md to its URL path.

# <ChatSearchBox>

Search messages within a conversation.

> Note: The in-conversation message search functionality is only available on the TalkJS Growth plan and above.

The `<ChatSearchBox>` component displays a text input which lets the user enter a search query.

## interface ChatSearchBoxProps

```typescript
interface ChatSearchBoxProps {
  common: CommonChatboxProps;
  searchQuery: string;
}
```

### Properties

**common**: [CommonChatboxProps](https://talkjs.com/docs/UI_Components/Theme/Shared_types/#CommonChatboxProps)

A collection of objects which are passed to all Chatbox theme components.

**searchQuery**: string

The current query used by in-conversation message search.

## Example

In the default theme, the `<ChatSearchBox>` component is implemented as follows:

**JSX**

```jsx
import { Icon, SearchInput } from "@talkjs/react-components";
/** @import { ChatSearchBoxProps } from "@talkjs/react-components"; */

/** @param {ChatSearchBoxProps} props */
export function ChatSearchBox(props) {
  const { t, chatbox, chatSearchState } = props.common;
  const { searchQuery } = props;

  let statusText;
  if (chatSearchState === "searching") {
    statusText = t.SEARCH_SEARCHING;
  } else if (chatSearchState === "noResults") {
    statusText = t.SEARCH_NO_RESULTS;
  } else if (chatSearchState === "noMoreResults") {
    statusText = t.SEARCH_NO_MORE_RESULTS;
  }

  const onClear = () => {
    chatbox.setSearchQuery("");
  };

  return (
    <div className="t-theme-chat-search-wrap">
      <div className="t-theme-chat-search-box">
        <button
          className="t-button t-back-button"
          aria-label={t.ARIA_LEAVE_SEARCH_MODE}
          onClick={() => chatbox.toggleSearchBox()}
        >
          <Icon type="chevronLeft" size={20} />
        </button>

        <div className="t-search-field">
          <SearchInput
            id="t-search-input"
            autoFocus={true}
            placeholder={t.SEARCH_PLACEHOLDER_TEXT}
            className="t-search-input"
          />

          {searchQuery.length > 0 && (
            <button
              type="button"
              className="t-clear"
              aria-label={t.ARIA_LEAVE_SEARCH_MODE}
              onClick={onClear}
            >
              <Icon type="close" size={20} />
            </button>
          )}
        </div>

        <button
          className="t-button t-previous-button"
          aria-label={t.ARIA_SEARCH_UP}
          disabled={chatSearchState === "searching"}
          onClick={() => chatbox.jumpToPreviousHighlight()}
        >
          <Icon type="chevronUp" size={20} />
        </button>

        <button
          className="t-button t-next-button"
          aria-label={t.ARIA_SEARCH_DOWN}
          disabled={chatSearchState === "searching"}
          onClick={() => chatbox.jumpToNextHighlight()}
        >
          <Icon type="chevronDown" size={20} />
        </button>
      </div>

      {statusText && (
        <div
          className="t-theme-chat-search-status"
          role="status"
          aria-live="polite"
        >
          <span className="t-text">{statusText}</span>
        </div>
      )}
    </div>
  );
}
```

**TSX**

```tsx
import { Icon, SearchInput } from "@talkjs/react-components";
import type { ChatSearchBoxProps } from "@talkjs/react-components";

export function ChatSearchBox(props: ChatSearchBoxProps) {
  const { t, chatbox, chatSearchState } = props.common;
  const { searchQuery } = props;

  let statusText: string | undefined;
  if (chatSearchState === "searching") {
    statusText = t.SEARCH_SEARCHING;
  } else if (chatSearchState === "noResults") {
    statusText = t.SEARCH_NO_RESULTS;
  } else if (chatSearchState === "noMoreResults") {
    statusText = t.SEARCH_NO_MORE_RESULTS;
  }

  const onClear = () => {
    chatbox.setSearchQuery("");
  };

  return (
    <div className="t-theme-chat-search-wrap">
      <div className="t-theme-chat-search-box">
        <button
          className="t-button t-back-button"
          aria-label={t.ARIA_LEAVE_SEARCH_MODE}
          onClick={() => chatbox.toggleSearchBox()}
        >
          <Icon type="chevronLeft" size={20} />
        </button>

        <div className="t-search-field">
          <SearchInput
            id="t-search-input"
            autoFocus={true}
            placeholder={t.SEARCH_PLACEHOLDER_TEXT}
            className="t-search-input"
          />

          {searchQuery.length > 0 && (
            <button
              type="button"
              className="t-clear"
              aria-label={t.ARIA_LEAVE_SEARCH_MODE}
              onClick={onClear}
            >
              <Icon type="close" size={20} />
            </button>
          )}
        </div>

        <button
          className="t-button t-previous-button"
          aria-label={t.ARIA_SEARCH_UP}
          disabled={chatSearchState === "searching"}
          onClick={() => chatbox.jumpToPreviousHighlight()}
        >
          <Icon type="chevronUp" size={20} />
        </button>

        <button
          className="t-button t-next-button"
          aria-label={t.ARIA_SEARCH_DOWN}
          disabled={chatSearchState === "searching"}
          onClick={() => chatbox.jumpToNextHighlight()}
        >
          <Icon type="chevronDown" size={20} />
        </button>
      </div>

      {statusText && (
        <div
          className="t-theme-chat-search-status"
          role="status"
          aria-live="polite"
        >
          <span className="t-text">{statusText}</span>
        </div>
      )}
    </div>
  );
}
```

**JavaScript**

```js
import { html, Icon, SearchInput } from "@talkjs/web-components";
/** @import { ChatSearchBoxProps } from "@talkjs/web-components"; */

/** @param {ChatSearchBoxProps} props */
export function ChatSearchBox(props) {
  const { t, chatbox, chatSearchState } = props.common;
  const { searchQuery } = props;

  let statusText;
  if (chatSearchState === "searching") {
    statusText = t.SEARCH_SEARCHING;
  } else if (chatSearchState === "noResults") {
    statusText = t.SEARCH_NO_RESULTS;
  } else if (chatSearchState === "noMoreResults") {
    statusText = t.SEARCH_NO_MORE_RESULTS;
  }

  const onClear = () => {
    chatbox.setSearchQuery("");
  };

  return html`
    <div className="t-theme-chat-search-wrap">
      <div className="t-theme-chat-search-box">
        <button
          className="t-button t-back-button"
          aria-label=${t.ARIA_LEAVE_SEARCH_MODE}
          onClick=${() => chatbox.toggleSearchBox()}
        >
          <${Icon} type="chevronLeft" size=${20} />
        </button>

        <div className="t-search-field">
          <${SearchInput}
            id="t-search-input"
            autoFocus=${true}
            placeholder=${t.SEARCH_PLACEHOLDER_TEXT}
            className="t-search-input"
          />

          ${searchQuery.length > 0 &&
          html`
            <button
              type="button"
              className="t-clear"
              aria-label=${t.ARIA_LEAVE_SEARCH_MODE}
              onClick=${onClear}
            >
              <${Icon} type="close" size=${20} />
            </button>
          `}
        </div>

        <button
          className="t-button t-previous-button"
          aria-label=${t.ARIA_SEARCH_UP}
          disabled=${chatSearchState === "searching"}
          onClick=${() => chatbox.jumpToPreviousHighlight()}
        >
          <${Icon} type="chevronUp" size=${20} />
        </button>

        <button
          className="t-button t-next-button"
          aria-label=${t.ARIA_SEARCH_DOWN}
          disabled=${chatSearchState === "searching"}
          onClick=${() => chatbox.jumpToNextHighlight()}
        >
          <${Icon} type="chevronDown" size=${20} />
        </button>
      </div>

      ${statusText &&
      html`
        <div
          className="t-theme-chat-search-status"
          role="status"
          aria-live="polite"
        >
          <span className="t-text">${statusText}</span>
        </div>
      `}
    </div>
  `;
}
```

**TypeScript**

```ts
import { html, Icon, SearchInput } from "@talkjs/web-components";
import type { ChatSearchBoxProps } from "@talkjs/web-components";

export function ChatSearchBox(props: ChatSearchBoxProps) {
  const { t, chatbox, chatSearchState } = props.common;
  const { searchQuery } = props;

  let statusText: string | undefined;
  if (chatSearchState === "searching") {
    statusText = t.SEARCH_SEARCHING;
  } else if (chatSearchState === "noResults") {
    statusText = t.SEARCH_NO_RESULTS;
  } else if (chatSearchState === "noMoreResults") {
    statusText = t.SEARCH_NO_MORE_RESULTS;
  }

  const onClear = () => {
    chatbox.setSearchQuery("");
  };

  return html`
    <div className="t-theme-chat-search-wrap">
      <div className="t-theme-chat-search-box">
        <button
          className="t-button t-back-button"
          aria-label=${t.ARIA_LEAVE_SEARCH_MODE}
          onClick=${() => chatbox.toggleSearchBox()}
        >
          <${Icon} type="chevronLeft" size=${20} />
        </button>

        <div className="t-search-field">
          <${SearchInput}
            id="t-search-input"
            autoFocus=${true}
            placeholder=${t.SEARCH_PLACEHOLDER_TEXT}
            className="t-search-input"
          />

          ${searchQuery.length > 0 &&
          html`
            <button
              type="button"
              className="t-clear"
              aria-label=${t.ARIA_LEAVE_SEARCH_MODE}
              onClick=${onClear}
            >
              <${Icon} type="close" size=${20} />
            </button>
          `}
        </div>

        <button
          className="t-button t-previous-button"
          aria-label=${t.ARIA_SEARCH_UP}
          disabled=${chatSearchState === "searching"}
          onClick=${() => chatbox.jumpToPreviousHighlight()}
        >
          <${Icon} type="chevronUp" size=${20} />
        </button>

        <button
          className="t-button t-next-button"
          aria-label=${t.ARIA_SEARCH_DOWN}
          disabled=${chatSearchState === "searching"}
          onClick=${() => chatbox.jumpToNextHighlight()}
        >
          <${Icon} type="chevronDown" size=${20} />
        </button>
      </div>

      ${statusText &&
      html`
        <div
          className="t-theme-chat-search-status"
          role="status"
          aria-live="polite"
        >
          <span className="t-text">${statusText}</span>
        </div>
      `}
    </div>
  `;
}
```

[view on GitHub](https://github.com/talkjs/themes/blob/master/default/react-jsx/ChatSearchBox.jsx)
