> ## 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-toggle-refinement

> Lets users toggle a specific filter.

<div className="not-prose algolia-flavor-switcher">
  <div className="afs-dropdown">
    <div className="afs-trigger" role="button" tabIndex="0" aria-haspopup="listbox">
      <span className="afs-current">Vue</span>

      <svg className="afs-chevron lucide lucide-chevron-down" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
        <path d="m6 9 6 6 6-6" />
      </svg>
    </div>

    <ul className="afs-menu" role="listbox">
      <li role="option" aria-selected="false"><a className="afs-option" href="/doc/api-reference/widgets/toggle-refinement/js"><span className="afs-option-name">JavaScript</span><span className="afs-option-lib">InstantSearch.js</span></a></li>
      <li role="option" aria-selected="false"><a className="afs-option" href="/doc/api-reference/widgets/toggle-refinement/react"><span className="afs-option-name">React</span><span className="afs-option-lib">React InstantSearch</span></a></li>
      <li role="option" aria-selected="true"><a className="afs-option is-current" href="/doc/api-reference/widgets/toggle-refinement/vue"><span className="afs-option-name">Vue</span><span className="afs-option-lib">Vue InstantSearch</span></a></li>
      <li role="option" aria-selected="false"><a className="afs-option" href="/doc/api-reference/widgets/toggle-refinement/ios"><span className="afs-option-name">iOS</span><span className="afs-option-lib">InstantSearch iOS</span></a></li>
      <li role="option" aria-selected="false"><a className="afs-option" href="/doc/api-reference/widgets/toggle-refinement/android"><span className="afs-option-name">Android</span><span className="afs-option-lib">InstantSearch Android</span></a></li>
      <li role="option" aria-selected="false"><a className="afs-option" href="/doc/api-reference/widgets/toggle-refinement/flutter"><span className="afs-option-name">Flutter</span><span className="afs-option-lib">Algolia for Flutter</span></a></li>
    </ul>
  </div>
</div>

```vue Signature theme={"system"}
<ais-toggle-refinement
  attribute="string"
  label="string"
  // Optional parameters
  :on="string | number | boolean"
  :off="string | number | 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 { AisToggleRefinement } from "vue-instantsearch";
    // Use "vue-instantsearch/vue3/es" for Vue 3

    export default {
      components: {
        AisToggleRefinement
      },
      // ...
    };
    ```
  </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-toggle-refinement" horizontal>
  Preview this widget and its behavior.
</Card>

## About this widget

The `ais-toggle-refinement` widget provides an on/off filtering feature based on an attribute value.

## Examples

```vue Vue icon=code theme={"system"}
<ais-toggle-refinement attribute="free_shipping" label="Free Shipping" />
```

## Props

<ParamField body="attribute" type="string" required>
  The name of the attribute on which to apply the refinement.

  To avoid unexpected behavior, you can't use the same `attribute` prop in a different type of widget.

  ```vue Vue icon=code theme={"system"}
  <ais-toggle-refinement
    [...]
    attribute="free_shipping"
  />
  ```
</ParamField>

<ParamField body="label" type="string" required>
  The label to display for the checkbox.

  ```vue Vue icon=code theme={"system"}
  <ais-toggle-refinement
    [...]
    label="Free Shipping"
  />
  ```
</ParamField>

<ParamField body="on" type="string | number | boolean" default={true}>
  The value of the refinement to apply on the attribute when checked.

  ```vue Vue icon=code theme={"system"}
  <ais-toggle-refinement
    [...]
    :on="true"
  />
  ```
</ParamField>

<ParamField body="off" type="string | number | boolean">
  The value of the refinement to apply on the attribute when unchecked.

  ```vue Vue icon=code theme={"system"}
  <ais-toggle-refinement
    [...]
    :off="false"
  />
  ```
</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-ToggleRefinement`. The root of the widget.
  * `ais-ToggleRefinement--noRefinement`. The root of the widget without refinement.
  * `ais-ToggleRefinement-label`. The label of the toggle.
  * `ais-ToggleRefinement-checkbox`. The checkbox element of the toggle.
  * `ais-ToggleRefinement-labelText`. The label text of the toggle.
  * `ais-ToggleRefinement-count`. The count of the toggle.

  ```vue Vue icon=code theme={"system"}
  <ais-toggle-refinement
    [...]
    :class-names="{
      'ais-ToggleRefinement': 'MyCustomToggleRefinement',
      'ais-ToggleRefinement-label': 'MyCustomToggleRefinementLabel',
      // ...
    }"
  />
  ```
</ParamField>

## Customize the UI

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

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

  **Scope**

  * `value: object`. The current refinement. It contains `name`, `count` and `isRefined`.
  * `canRefine: boolean`. Whether the refinement can be applied.
  * `refine: (value: string) => void`. The function to call with the provided value to update the refinement.
  * `createURL: (value: string) => void`. The function to generate a link from the provided value.
  * `sendEvent: (eventType: 'click', facetValue: string) => void`. The function to send `click` events.

    * The `view` event is automatically sent when the facets are rendered.
    * The `click` event is automatically sent when `refine` is called.

    To learn more, see the [`insights`](/doc/api-reference/widgets/insights/vue) middleware.

  ```vue Vue icon=code theme={"system"}
  <ais-toggle-refinement attribute="free_shipping" label="Free Shipping">
    <template v-slot="{ value, refine, createURL, sendEvent }">
      <a
        :href="createURL(value)"
        :style="{ fontWeight: value.isRefined ? 'bold' : '' }"
        @click.prevent="refine(value)"
      >
        {{ value.name }}
        ({{ value.count }})
      </a>
    </template>
  </ais-toggle-refinement>
  ```
</ParamField>

## HTML output

```html HTML icon=code-xml theme={"system"}
<div class="ais-ToggleRefinement">
  <label class="ais-ToggleRefinement-label">
    <input class="ais-ToggleRefinement-checkbox" type="checkbox" />
    <span class="ais-ToggleRefinement-labelText">Free Shipping</span>
    <span class="ais-ToggleRefinement-count">18,013</span>
  </label>
</div>
```
