Skip to content

Commit

Permalink
feat: disable expanding search results when no results
Browse files Browse the repository at this point in the history
  • Loading branch information
themightychris committed Nov 11, 2024
1 parent 9f74070 commit 59e194d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/components/SearchResults.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ const sortedResults = computed(() => {
return [...props.results.matches].sort((a, b) => a.name.localeCompare(b.name))
})
const hasResults = computed(() => props.results.matches.length > 0)
// Compute the results title based on the type of search
const resultsTitle = computed(() => {
if (props.results.matches.length === 0) {
if (!hasResults.value) {
return 'No Results'
}
Expand Down Expand Up @@ -49,16 +51,19 @@ watch(() => props.results.matches.length, (newCount) => {
}, { immediate: true })
const toggleExpand = () => {
isExpanded.value = !isExpanded.value
emit('update:expanded', isExpanded.value)
// Only allow toggling if there are results
if (hasResults.value) {
isExpanded.value = !isExpanded.value
emit('update:expanded', isExpanded.value)
}
}
</script>

<template>
<div class="search-results" :class="{ expanded: isExpanded }">
<div class="results-header" @click="toggleExpand">
<span class="result-count">{{ resultsTitle }}</span>
<button class="expand-button">
<button v-if="hasResults" class="expand-button">
{{ isExpanded ? '▼' : '▲' }}
</button>
</div>
Expand Down

0 comments on commit 59e194d

Please sign in to comment.