Skip to content

Commit 59e194d

Browse files
feat: disable expanding search results when no results
1 parent 9f74070 commit 59e194d

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/components/SearchResults.vue

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ const sortedResults = computed(() => {
1616
return [...props.results.matches].sort((a, b) => a.name.localeCompare(b.name))
1717
})
1818
19+
const hasResults = computed(() => props.results.matches.length > 0)
20+
1921
// Compute the results title based on the type of search
2022
const resultsTitle = computed(() => {
21-
if (props.results.matches.length === 0) {
23+
if (!hasResults.value) {
2224
return 'No Results'
2325
}
2426
@@ -49,16 +51,19 @@ watch(() => props.results.matches.length, (newCount) => {
4951
}, { immediate: true })
5052
5153
const toggleExpand = () => {
52-
isExpanded.value = !isExpanded.value
53-
emit('update:expanded', isExpanded.value)
54+
// Only allow toggling if there are results
55+
if (hasResults.value) {
56+
isExpanded.value = !isExpanded.value
57+
emit('update:expanded', isExpanded.value)
58+
}
5459
}
5560
</script>
5661

5762
<template>
5863
<div class="search-results" :class="{ expanded: isExpanded }">
5964
<div class="results-header" @click="toggleExpand">
6065
<span class="result-count">{{ resultsTitle }}</span>
61-
<button class="expand-button">
66+
<button v-if="hasResults" class="expand-button">
6267
{{ isExpanded ? '▼' : '▲' }}
6368
</button>
6469
</div>

0 commit comments

Comments
 (0)