> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# ais-search-box

> Lets users perform a search using text input.

export const SearchQuery = () => <Tooltip tip="The text users enter into a search box. In the Search API, this corresponds to the query parameter. A search query is often used with filters, facets, and other parameters, but these aren't part of the query text itself.">
    search query
  </Tooltip>;

```vue Signature theme={"system"}
<ais-search-box
  // Optional parameters
  placeholder="string"
  submit-title="string"
  reset-title="string"
  :autofocus="boolean"
  :ignore-composition-events="boolean"
  :show-loading-indicator="boolean"
  :class-names="object"
/>
```

## Import

<Tabs>
  <Tab title="Component">
    To ensure optimal bundle sizes,
    see [Optimize build size](/doc/guides/building-search-ui/going-further/improve-performance/vue#optimize-build-size).

    ```js Vue icon=code theme={"system"}
    import { AisSearchBox } from "vue-instantsearch";
    // Use "vue-instantsearch/vue3/es" for Vue 3

    export default {
      components: {
        AisSearchBox,
      },
      // ...
    };
    ```
  </Tab>

  <Tab title="Plugin">
    This imports all widgets, even the ones you don't use.
    For more information, see [Get started with Vue InstantSearch](/doc/guides/building-search-ui/getting-started/vue).

    ```js JavaScript icon="code" theme={"system"}
    import Vue from "vue";
    import InstantSearch from "vue-instantsearch";
    // Use "vue-instantsearch/vue3/es" for Vue 3

    Vue.use(InstantSearch);
    ```
  </Tab>
</Tabs>

<Card title="See this widget in action" icon="monitor-play" href="https://instantsearchjs.netlify.app/stories/vue/?selectedKind=ais-searchbox" horizontal>
  Preview this widget and its behavior.
</Card>

## About this widget

The `ais-search-box` widget is used to let users set a text-based <SearchQuery />.

This usually is the main entry point to start the search in an InstantSearch context.
It's usually placed at the top of a search experience, so that users can start searching right away.

## Examples

```vue Vue icon=code theme={"system"}
<ais-search-box />
```

## Props

<ParamField body="placeholder" type="string" default="Search here…">
  The input placeholder.

  ```vue Vue icon=code theme={"system"}
  <ais-search-box placeholder="Search for products..." />
  ```
</ParamField>

<ParamField body="submit-title" type="string" default="search">
  The submit button text.

  ```vue Vue icon=code theme={"system"}
  <ais-search-box submit-title="Submit the query" />
  ```
</ParamField>

<ParamField body="reset-title" type="string" default="clear">
  The clear button text.

  ```vue Vue icon=code theme={"system"}
  <ais-search-box reset-title="Remove the query" />
  ```
</ParamField>

<ParamField body="autofocus" type="boolean" default={false}>
  Whether to automatically focus on the input when rendered.

  ```vue Vue icon=code theme={"system"}
  <ais-search-box autofocus />
  ```
</ParamField>

<ParamField body="ignore-composition-events" type="boolean" default={false} post={["since: v4.13.6"]}>
  Whether to update the search state in the middle of a composition session.
  This is useful when users need to search using non-latin characters.

  ```vue Vue icon=code theme={"system"}
  <ais-search-box ignore-composition-events />
  ```
</ParamField>

<ParamField body="show-loading-indicator" type="boolean" default={false}>
  Whether to show the loading indicator (replaces the submit button if the search is stalled).

  ```vue Vue icon=code theme={"system"}
  <ais-search-box show-loading-indicator />
  ```
</ParamField>

<ParamField body="class-names" type="object" default="{}">
  The [CSS classes you can override](/doc/guides/building-search-ui/widgets/customize-an-existing-widget/vue#style-your-widgets):

  * `ais-SearchBox`. The root element of the widget.
  * `ais-SearchBox-form`. The form element.
  * `ais-SearchBox-input`. The input element.
  * `ais-SearchBox-submit`. The submit button element.
  * `ais-SearchBox-submitIcon`. Magnifier icon used with The search input.
  * `ais-SearchBox-reset`. The reset button element.
  * `ais-SearchBox-resetIcon`. The reset button icon.
  * `ais-SearchBox-loadingIndicator`. The loading indicator element.
  * `ais-SearchBox-loadingIcon`. The loading indicator icon.

  ```vue Vue icon=code theme={"system"}
  <ais-search-box
    :class-names="{
      'ais-SearchBox': 'MySearchBox',
      'ais-SearchBox-form': 'MySearchBoxForm',
      // ...
    }"
  />
  ```
</ParamField>

## Customize the UI

<ParamField body="default">
  The slot to override the complete DOM output of the widget.

  Note that when you implement this slot,
  none of the other slots will change the output, as the default slot surrounds them.

  **Scope**

  * `currentRefinement: string`: the current query used for the search.
  * `isSearchStalled: boolean`: whether InstantSearch has detected that searches are stalled.
  * `refine: (string) => void`: the function to change the query.

  ```vue Vue icon=code theme={"system"}
  <ais-search-box>
    <template v-slot="{ currentRefinement, isSearchStalled, refine }">
      <input
        type="search"
        :value="currentRefinement"
        @input="refine($event.currentTarget.value)"
      >
      <span :hidden="!isSearchStalled">Loading...</span>
    </template>
  </ais-search-box>
  ```
</ParamField>

<ParamField body="submit-icon">
  The slot to override the DOM output of the submit icon.

  **Scope**

  No props are provided.

  ```vue Vue icon=code theme={"system"}
  <ais-search-box>
    <template v-slot:submit-icon>🔎</template>
  </ais-search-box>
  ```
</ParamField>

<ParamField body="reset-icon">
  The slot to override the DOM output of the reset icon.

  **Scope**

  No props are provided.

  ```vue Vue icon=code theme={"system"}
  <ais-search-box>
    <template v-slot:reset-icon>🚫</template>
  </ais-search-box>
  ```
</ParamField>

<ParamField body="loading-indicator">
  The slot to override the DOM output of the loading indicator.

  **Scope**

  No props are provided.

  ```vue Vue icon=code theme={"system"}
  <ais-search-box>
    <template v-slot:loading-indicator>⏳</template>
  </ais-search-box>
  ```
</ParamField>

## HTML output

```html HTML icon=code-xml theme={"system"}
<div class="ais-SearchBox">
  <form class="ais-SearchBox-form" novalidate>
    <input
      class="ais-SearchBox-input"
      autocomplete="off"
      autocorrect="off"
      autocapitalize="off"
      placeholder="Search for products"
      spellcheck="false"
      maxlength="512"
      type="search"
      value=""
    />
    <button
      class="ais-SearchBox-submit"
      type="submit"
      title="Submit the search query."
    >
      <svg
        class="ais-SearchBox-submitIcon"
        xmlns="http://www.w3.org/2000/svg"
        width="10"
        height="10"
        viewBox="0 0 40 40"
      >
        ...
      </svg>
    </button>
    <button
      class="ais-SearchBox-reset"
      type="reset"
      title="Clear the search query."
      hidden
    >
      <svg
        class="ais-SearchBox-resetIcon"
        xmlns="http://www.w3.org/2000/svg"
        viewBox="0 0 20 20"
        width="10"
        height="10"
      >
        ...
      </svg>
    </button>
    <span class="ais-SearchBox-loadingIndicator" hidden>
      <svg
        width="16"
        height="16"
        viewBox="0 0 38 38"
        xmlns="http://www.w3.org/2000/svg"
        stroke="#444"
        class="ais-SearchBox-loadingIcon"
      >
        ...
      </svg>
    </span>
  </form>
</div>
```
