Skip to content

Attribute Filter

The Attribute Filter component provides a user interface for filtering items based on various attributes. By default, it utilizes the chip component as the trigger element and the list component to display filter options, but it can be customized to use other components as needed.

Basic Usage

Status
0
vue
<template>
  <SprAttributeFilter
    id="attribute_filter1"
    :filter-label="'Status'"
    width="70px"
    popper-width="300px"
    placement="bottom-start"
    :filter-menu-list="filterList"
  />
</template>
<script lang="ts" setup>
import { ref } from 'vue';

const filterList = ref([
  { text: 'Approved', value: 'Approved' },
  { text: 'Completed', value: 'Completed' },
  { text: 'In Progress', value: 'In Progress' },
  { text: 'Pending', value: 'Pending' },
  { text: 'Rejected', value: 'Rejected' },
  { text: 'On Hold', value: 'On Hold' },
]);
</script>

Multi Select

Status
0
vue
<template>
  <SprAttributeFilter
    id="attribute_filter5"
    :filter-label="'Status'"
    width="70px"
    popper-width="300px"
    placement="bottom-start"
    :filter-menu-list="filterList"
  />
</template>
<script lang="ts" setup>
import { ref } from 'vue';

const filterList = ref([
  { text: 'Approved', value: 'Approved' },
  { text: 'Completed', value: 'Completed' },
  { text: 'In Progress', value: 'In Progress' },
  { text: 'Pending', value: 'Pending' },
  { text: 'Rejected', value: 'Rejected' },
  { text: 'On Hold', value: 'On Hold' },
]);
</script>

Attribute Filter Trigger

By default, Attribute Filter is triggered by the chip component. You can change the trigger component by providing a default slot.

vue
<template>
  <SprAttributeFilter
    id="attribute_filter2"
    :filter-label="'Status'"
    width="70px"
    popper-width="300px"
    placement="bottom-start"
    :filter-menu-list="filterList"
  >
    <SprButton tone="success"> Status </SprButton>
  </SprAttributeFilter>
</template>
<script lang="ts" setup>
import { ref } from 'vue';

const filterList = ref([
  { text: 'Approved', value: 'Approved' },
  { text: 'Completed', value: 'Completed' },
  { text: 'In Progress', value: 'In Progress' },
  { text: 'Pending', value: 'Pending' },
  { text: 'Rejected', value: 'Rejected' },
  { text: 'On Hold', value: 'On Hold' },
]);
</script>

To render a search input inside the Attribute Filter popper, set the searchable prop to true. You can also bind a model to the search input using the v-model:search directive.

INFO

For API searching, disable local searching by setting the disableLocalSearch prop to true.

Status w/ Local Search
0
Status w/o Local Search
0
vue
<template>
  <div class="spr-flex spr-items-center spr-gap-2">
    <SprAttributeFilter
      id="attribute_filter3"
      :filter-label="'Status w/ Local Search'"
      width="180px"
      v-model:search="searchString1"
      popper-width="300px"
      placement="bottom-start"
      :searchable="true"
      :filter-menu-list="filterList"
    />

    <SprAttributeFilter
      id="attribute_filter4"
      :filter-label="'Status w/o Local Search'"
      width="180px"
      popper-width="300px"
      placement="bottom-start"
      :searchable="true"
      :disable-local-search="true"
      :filter-menu-list="filterList"
      @update:search="handleSearch"
    />
  </div>
</template>
<script lang="ts" setup>
import { ref } from 'vue';

const searchString1 = ref('');
const searchString2 = ref('');

const filterList = ref([
  { text: 'Approved', value: 'Approved' },
  { text: 'Completed', value: 'Completed' },
  { text: 'In Progress', value: 'In Progress' },
  { text: 'Pending', value: 'Pending' },
  { text: 'Rejected', value: 'Rejected' },
  { text: 'On Hold', value: 'On Hold' },
]);

const handleSearch = (search: string) => {
  //do something with search term
};
</script>

API Reference

Props

NameDescriptionTypeDefault
id

Unique identifier for the component

string'attribute_filter'
filterLabel

Label displayed on the filter trigger

string'Filter'
headerLabel

Label displayed on the filter popper header

string'Add Filter'
disabledWhen true, disables the chip component and the filter dropdown from being openedbooleanfalse
multiselectEnables multiple selection of filter optionsbooleanfalse
filterMenuListList of filter options to display in the dropdown{text: string, value: string}[] | string[][]
searchableEnable to render a search input within the filter dropdownbooleanfalse
disableLocalSearchWhen true, disables the local search functionality within the filter dropdownbooleanfalse
showSelectedFilterCountWhen true, displays a badge in the chip component trigger indicating the number of selected filtersbooleantrue
selectedFilterCountSet the text to display in the badge indicating the number of selected filters. If not provided and the no list prop is false, it will default to the length of the selected filters.stringundefined
badgeVariantVariant style for the badge displayed on the chip component trigger'brand' | 'information' | 'danger' | 'disabled''danger'
noListWhen true, will not display the filter list. To be used if body slot is provided.booleanfalse
clearableWhen true, will render an X icon in the default chip trigger to clear selected filters or if no list, will trigger the onClearFilter event.booleanfalse
NameDescriptionTypeDefault
placementControls the position of the filter dropdown relative to the trigger'auto' | 'auto-start' | 'auto-end' | 'top' | 'top-start' | 'top-end' | 'right' | 'right-start' | 'right-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'left' | 'left-start' | 'left-end''bottom'
wrapper-positionCSS position value for the filter dropdownstring'relative'
widthWidth of the filter wrapper (including the trigger element)string'100%'
popper-widthWidth of the filter dropdown that appears when triggeredstring'100%'
popper-inner-widthWidth of the inner content area of the filter dropdownstring'unset'
popper-strategyPositioning strategy for the filter dropdown, especially important in modals'absolute' | 'fixed''absolute'
triggersArray of events that will trigger the filter dropdown to open'click' | 'hover' | 'focus' | 'touch'[][]
popper-triggersArray of events that will trigger the filter dropdown menu (popper element) to open'click' | 'hover' | 'focus' | 'touch'[][]
auto-hideWhen true, automatically hides the filter dropdown when clicking outside itbooleantrue

Events

NameDescriptionParameters
onSaveFilterEmitted when clicking the save button in the default footer(savedFilters: MenuListType[])
onOpenFilterEmitted when the filter dropdown is shown-
onCloseFilterEmitted when the filter dropdown is closed-
onSelectFilterEmitted when selecting a filter option from the dropdown(selectedFilters: MenuListType[])
infiniteScrollTriggerEmitted when the user scrolls to the bottom of the filter dropdown-
@update:searchEmitted when the search input value changes(searchString: string)
onClearFilterEmitted when the clear action is triggered to reset selected filters-

Slots

NameDescription
defaultSlot for the trigger of the filter dropdown. Defaults to the chip component
headerSlot for the header inside the filter dropdown
actionsSlot for additional actions inside the filter dropdown. Slotted between the header (search container if searchable) and the body
bodySlot for the main content. Defaults to the list component.
footerSlot for the footer inside the filter dropdown. Defaults to a cancel and save button