Skip to content

Commit bb12f85

Browse files
authored
Merge branch 'main' into contrasty-switches
2 parents cf4e0c8 + 19d1849 commit bb12f85

5 files changed

Lines changed: 57 additions & 2 deletions

File tree

app/components/OgImage/Package.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ try {
112112
style="font-family: 'Geist Sans', sans-serif"
113113
>
114114
<span
115-
class="px-3 py-1 mr-2 rounded-lg border font-bold opacity-90"
115+
class="px-3 py-1 me-2 rounded-lg border font-bold opacity-90"
116116
:style="{
117117
color: primaryColor,
118118
backgroundColor: primaryColor + '10',

app/pages/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ defineOgImageComponent('Default', {
101101
class="absolute group inset-ie-2.5 px-2.5 sm:ps-4 sm:pe-4 py-2 font-mono text-sm text-bg bg-fg/90 rounded-md transition-[background-color,transform] duration-200 hover:bg-fg! group-focus-within:bg-fg/80 active:scale-95 focus-visible:outline-accent/70"
102102
>
103103
<span
104-
class="inline-block i-carbon:search align-middle w-4 h-4 sm:mr-2"
104+
class="inline-block i-carbon:search align-middle w-4 h-4 sm:me-2"
105105
aria-hidden="true"
106106
></span>
107107
<span class="sr-only sm:not-sr-only">

app/pages/search.vue

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,59 @@ function focusElement(el: HTMLElement) {
541541
el.scrollIntoView({ block: 'nearest', behavior: 'smooth' })
542542
}
543543
544+
// Navigate to package page
545+
async function navigateToPackage(packageName: string) {
546+
await navigateTo({
547+
name: 'package',
548+
params: { package: packageName.split('/') },
549+
})
550+
}
551+
552+
// Track the input value when user pressed Enter (for navigating when results arrive)
553+
const pendingEnterQuery = shallowRef<string | null>(null)
554+
555+
// Watch for results to navigate when Enter was pressed before results arrived
556+
watch(displayResults, results => {
557+
if (!pendingEnterQuery.value) return
558+
559+
// Check if input is still focused (user hasn't started navigating or clicked elsewhere)
560+
if (document.activeElement?.tagName !== 'INPUT') {
561+
pendingEnterQuery.value = null
562+
return
563+
}
564+
565+
// Navigate if first result matches the query that was entered
566+
const firstResult = results[0]
567+
// eslint-disable-next-line no-console
568+
console.log('[search] watcher fired', {
569+
pending: pendingEnterQuery.value,
570+
firstResult: firstResult?.package.name,
571+
})
572+
if (firstResult?.package.name === pendingEnterQuery.value) {
573+
pendingEnterQuery.value = null
574+
navigateToPackage(firstResult.package.name)
575+
}
576+
})
577+
544578
function handleResultsKeydown(e: KeyboardEvent) {
579+
// If the active element is an input, navigate to exact match or wait for results
580+
if (e.key === 'Enter' && document.activeElement?.tagName === 'INPUT') {
581+
// Get value directly from input (not from route query, which may be debounced)
582+
const inputValue = (document.activeElement as HTMLInputElement).value.trim()
583+
if (!inputValue) return
584+
585+
// Check if first result matches the input value exactly
586+
const firstResult = displayResults.value[0]
587+
if (firstResult?.package.name === inputValue) {
588+
pendingEnterQuery.value = null
589+
return navigateToPackage(firstResult.package.name)
590+
}
591+
592+
// No match yet - store input value, watcher will handle navigation when results arrive
593+
pendingEnterQuery.value = inputValue
594+
return
595+
}
596+
545597
if (totalSelectableCount.value <= 0) return
546598
547599
const elements = getFocusableElements()

codecov.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
coverage:
22
status:
3+
changes:
4+
informational: true
35
project:
46
default:
57
informational: true

uno.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export default defineConfig({
3535
].filter(Boolean),
3636
transformers: [transformerDirectives(), transformerVariantGroup()],
3737
theme: {
38+
spacing: { DEFAULT: '4px' },
3839
font: {
3940
mono: "'Geist Mono', monospace",
4041
sans: "'Geist', system-ui, -apple-system, sans-serif",

0 commit comments

Comments
 (0)