SortDropdown
SortDropdown
The SortDropdown
component allows user to select the search results order. This component also
allows to change the selected sort programmatically.
Props
Name | Description | Type | Default |
---|---|---|---|
items | The list of possible sort values. If there are no values selected, the first item of this list will be selected. | Array |
|
animation | The transition to use for opening and closing the dropdown. | union |
|
Events
Event name | Properties | Description |
---|---|---|
change |
Slots
Name | Description | Bindings (name - type - description) |
---|---|---|
toggle | Used to render the contents of the dropdown toggle button. If not provided, it uses | isOpen boolean - True if the dropdown is opened, and false if it is closed.item Sort - The sort data to render. |
item | (required) Used to render each one of the items content, and as fallback | item Sort - Sort to renderisHighlighted boolean - True when the item has the focus.isSelected boolean - True when the item is selected. |
Sort Dropdown
The SortDropdown
component can be used to change the way the search results are ordered.
To do so, the list of valid sort values has to be provided using the items
prop. These are the
values that can be received then in the SearchAdapter
.
The component also optionally accepts the selected sort, which can be set using the value
prop.
This prop allows changing programmatically the selected sort, as it will be synced with the store
immediately. If this prop is not provided, the first item from the items
prop will be the one
selected by default.
This component also allows customizing both the toggle button and each one of the possible sort
values. This can be done with thetoggle
and item
slots.
Events
This component emits 2 different events:
SelectedSortProvided
(opens new window): To sync the selected sort with the store state value. This event is emitted as soon as the list of items is received, whenever this list changes if there is no provided value, and when the provided value changes.UserClickedASort
(opens new window): As its name suggest, the event is emitted after the user clicks one of the sort options. This does not mean that the sort has changed, only that the user has clicked it.
Examples
Only providing the list of items
<template>
<SortDropdown :items="sortValues">
<template #toggle="{ item, isOpen }">{{ item }} {{ isOpen ? '🔼' : '🔽' }}</template>
<template #item="{ item, isHighlighted, isSelected }">
<span v-if="isSelected">✅</span>
<span v-if="isHighlighted">🟢</span>
{{ item }}
</template>
</SortDropdown>
</template>
<script>
import { SortDropdown } from '@empathyco/x-components/search';
export default {
components: {
SortDropdown
},
data() {
return { sortValues: ['Relevance', 'Price asc', 'Price desc'] };
}
};
</script>
Providing also the selected value
<template>
<SortDropdown v-model="selectedSort" :items="sortValues">
<template #toggle="{ item, isOpen }">{{ item }} {{ isOpen ? '🔼' : '🔽' }}</template>
<template #item="{ item, isHighlighted, isSelected }">
<span v-if="isSelected">✅</span>
<span v-if="isHighlighted">🟢</span>
{{ item }}
</template>
</SortDropdown>
</template>
<script>
import { SortDropdown } from '@empathyco/x-components/search';
export default {
components: {
SortDropdown
},
data() {
return {
selectedSort: 'Price asc',
sortValues: ['Relevance', 'Price asc', 'Price desc']
};
}
};
</script>