Skip to content

Commit

Permalink
✨ feat(appfilter.vue): add categories filter
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinsOnuoha committed Oct 27, 2023
1 parent 2e1b5b8 commit 21f8b20
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/components/AppFilter/AppFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ const { categories } = useDBStore()
const dropdown = ref(false)
const categorySearch = ref(null)
const filterValue = ref('')
const categoriesList = ref(categories)
const selectedValue: Ref<Category | null> = ref(null)
const toggleDropdown = () => {
dropdown.value = !dropdown.value
Expand All @@ -23,6 +24,15 @@ const selectCategory = (category: Category) => {
selectedValue.value = category
closeDropdown()
}
const filterCategories = () => {
if (filterValue.value) {
categoriesList.value = categoriesList.value.filter((category) =>
category.name.toLowerCase().includes(filterValue.value.toLowerCase())
)
return
}
categoriesList.value = categories
}
</script>

<template>
Expand All @@ -36,7 +46,9 @@ const selectCategory = (category: Category) => {
name="category-dropdown"
placeholder="Filter by Categories"
aria-haspopup="true"
@input="filterCategories"
@focusin="openDropdown"
v-model="filterValue"
/>
<button
@click="toggleDropdown"
Expand All @@ -58,7 +70,7 @@ const selectCategory = (category: Category) => {
aria-labelledby="category-dropdown-btn"
>
<li
v-for="(category, index) in categories"
v-for="(category, index) in categoriesList"
:key="index"
@click="selectCategory(category)"
role="option"
Expand Down
2 changes: 1 addition & 1 deletion src/components/AppFilter/_AppFilter.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}

&__dropdown {
@apply absolute top-10 z-10 bg-white border p-3 left-0 max-h-80 shadow-2xl rounded-lg overflow-y-scroll;
@apply absolute top-10 z-10 bg-white border p-3 left-0 max-h-80 shadow-2xl rounded-lg overflow-y-scroll w-full;
li {
@apply p-2 transition-all flex;
&:hover {
Expand Down

0 comments on commit 21f8b20

Please sign in to comment.