Skip to content

Commit f0429f1

Browse files
committed
fix(BlockchainSearchInput): click on example should focus the search input on landing page
1 parent 146bf12 commit f0429f1

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

frontend/.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"BcTablePager",
1818
"BcToggle",
1919
"BcTooltip",
20+
"BlockchainSearchInput",
2021
"DashboardChartSummary",
2122
"DashboardChartSummaryFilter",
2223
"DashboardChartSummaryTooltip",

frontend/layers/products/app/components/BlockchainSearchInput.vue

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ const history = useLocalStorage<string[]>('bc-search-history-product-landing', [
7171
const localHistory = ref<InternalPostSearchResponseWithChainId['data']>(history.value.map(item => JSON.parse(item)))
7272
const hasHistory = computed(() => !!localHistory.value.length)
7373
const hasResults = computed(() => results !== undefined)
74+
const hasInput = computed(() => searchParams.value.input.length > 0)
7475
7576
const isHistoryVisible = ref<boolean>(!hasResults.value && hasHistory.value)
7677
const resultsOrHistory = computed(() => {
77-
if ((!hasResults.value && hasHistory.value) || isHistoryVisible.value) {
78+
if ((!hasInput.value && hasHistory.value) || isHistoryVisible.value) {
7879
return localHistory.value
7980
}
8081
return results
@@ -83,7 +84,7 @@ const toggleHistory = () => {
8384
isHistoryVisible.value = !isHistoryVisible.value
8485
localHistory.value = history.value.map(item => JSON.parse(item))
8586
}
86-
const handleClick = (searchResult: InternalPostSearchResponseWithChainId['data'][number]) => {
87+
const handleSelect = (searchResult: InternalPostSearchResponseWithChainId['data'][number]) => {
8788
const currentEntry = JSON.stringify(searchResult)
8889
if (history.value.length >= 10) {
8990
history.value.pop()
@@ -96,10 +97,18 @@ watch(hasResults, () => {
9697
if (hasResults.value) return
9798
isHistoryVisible.value = true
9899
})
100+
const searchInput = useTemplateRef<ComponentPublicInstance | null>('searchInput')
101+
const handleClickExample = (type: 'address' | 'token' | 'transaction' | 'validator') => {
102+
emit('click:example', type)
103+
isHistoryVisible.value = false
104+
const input = searchInput.value?.$el.querySelector('input')
105+
input?.focus()
106+
}
99107
</script>
100108

101109
<template>
102110
<BaseSearchInput
111+
ref="searchInput"
103112
v-model="searchParams.input"
104113
:is-loading="isHistoryVisible ? false : isLoading"
105114
:has-error="isHistoryVisible ? false : hasError"
@@ -133,7 +142,7 @@ watch(hasResults, () => {
133142
<BaseChip
134143
:is-selected="false"
135144
icon="stack-2"
136-
@click="emit('click:example', 'validator')"
145+
@click="handleClickExample('validator')"
137146
>
138147
{{ $t('products.landing_page.search.examples.validator') }}
139148
</BaseChip>
@@ -200,7 +209,7 @@ watch(hasResults, () => {
200209
<template #result-item="{ result }">
201210
<BlockchainSearchResultItem
202211
:result
203-
@click="handleClick(result)"
212+
@click="handleSelect(result)"
204213
/>
205214
</template>
206215

0 commit comments

Comments
 (0)