Skip to content

Commit 32efa44

Browse files
committed
fix(ui): apply accessibility and history state review suggestions
1 parent 307b733 commit 32efa44

1 file changed

Lines changed: 25 additions & 24 deletions

File tree

app/pages/search.vue

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const updateUrlPage = debounce((page: number) => {
2929
url.searchParams.delete('page')
3030
}
3131
// This updates the address bar "silently"
32-
window.history.replaceState({}, '', url)
32+
window.history.replaceState(window.history.state, '', url)
3333
}, 500)
3434
3535
const { model: searchQuery, provider: searchProvider } = useGlobalSearch()
@@ -393,20 +393,24 @@ const totalSelectableCount = computed(() => suggestionCount.value + resultCount.
393393
* Get all focusable result elements in DOM order (suggestions first, then packages)
394394
*/
395395
function getFocusableElements(): HTMLElement[] {
396-
const suggestions = Array.from(
397-
document.querySelectorAll<HTMLElement>('[data-suggestion-index]'),
398-
).sort((a, b) => {
399-
const aIdx = Number.parseInt(a.dataset.suggestionIndex ?? '0', 10)
400-
const bIdx = Number.parseInt(b.dataset.suggestionIndex ?? '0', 10)
401-
return aIdx - bIdx
402-
})
403-
const packages = Array.from(document.querySelectorAll<HTMLElement>('[data-result-index]')).sort(
404-
(a, b) => {
396+
const isVisible = (el: HTMLElement) => el.getClientRects().length > 0
397+
398+
const suggestions = Array.from(document.querySelectorAll<HTMLElement>('[data-suggestion-index]'))
399+
.filter(isVisible)
400+
.sort((a, b) => {
401+
const aIdx = Number.parseInt(a.dataset.suggestionIndex ?? '0', 10)
402+
const bIdx = Number.parseInt(b.dataset.suggestionIndex ?? '0', 10)
403+
return aIdx - bIdx
404+
})
405+
406+
const packages = Array.from(document.querySelectorAll<HTMLElement>('[data-result-index]'))
407+
.filter(isVisible)
408+
.sort((a, b) => {
405409
const aIdx = Number.parseInt(a.dataset.resultIndex ?? '0', 10)
406410
const bIdx = Number.parseInt(b.dataset.resultIndex ?? '0', 10)
407411
return aIdx - bIdx
408-
},
409-
)
412+
})
413+
410414
return [...suggestions, ...packages]
411415
}
412416
@@ -549,13 +553,13 @@ defineOgImageComponent('Default', {
549553
</div>
550554

551555
<section v-if="query" class="results-layout">
552-
<LoadingSpinner
553-
v-if="showSearching && displayResults.length === 0"
554-
:text="$t('search.searching')"
555-
/>
556+
<LoadingSpinner v-if="showSearching" :text="$t('search.searching')" />
556557

557558
<div v-show="results || displayResults.length > 0">
558-
<div v-if="validatedSuggestions.length > 0" class="mb-6 space-y-3">
559+
<div
560+
v-if="validatedSuggestions.length > 0 && displayResults.length > 0"
561+
class="mb-6 space-y-3"
562+
>
559563
<SearchSuggestionCard
560564
v-for="(suggestion, idx) in validatedSuggestions"
561565
:key="`${suggestion.type}-${suggestion.name}`"
@@ -570,7 +574,7 @@ defineOgImageComponent('Default', {
570574
</div>
571575

572576
<div
573-
v-if="showClaimPrompt && visibleResults && visibleResults.total > 0"
577+
v-if="showClaimPrompt && visibleResults && displayResults.length > 0"
574578
class="mb-6 p-4 bg-bg-subtle border border-border rounded-lg sm:flex hidden flex-row sm:items-center gap-3 sm:gap-4"
575579
>
576580
<div class="flex-1 min-w-0">
@@ -594,7 +598,7 @@ defineOgImageComponent('Default', {
594598
</p>
595599
</div>
596600

597-
<div v-else-if="visibleResults && visibleResults.total > 0" class="mb-6">
601+
<div v-else-if="visibleResults && displayResults.length > 0" class="mb-6">
598602
<PackageListToolbar
599603
:filters="filters"
600604
v-model:sort-option="sortOption"
@@ -744,11 +748,8 @@ defineOgImageComponent('Default', {
744748
</template>
745749

746750
<style scoped>
747-
.search-page {
748-
overflow-anchor: none;
749-
}
750-
751751
.results-layout {
752-
min-height: 100vh;
752+
min-height: 50vh;
753+
overflow-anchor: none;
753754
}
754755
</style>

0 commit comments

Comments
 (0)