Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PB-1188: Search preview layer stays on the map #1219

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions src/modules/menu/components/search/SearchResultListEntry.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup>
/** Component showing one search result entry (and dispatching its selection to the store) */

import { computed, ref, toRefs } from 'vue'
import { computed, onUnmounted, ref, toRefs } from 'vue'
import { useStore } from 'vuex'

import { SearchResultTypes } from '@/api/search.api'
Expand Down Expand Up @@ -35,7 +35,7 @@ const resultType = computed(() => entry.value.resultType)
const showLayerDescription = ref(false)

const item = ref(null)

const isSetPreview = ref(false)
const store = useStore()
const compact = computed(() => store.getters.isDesktopMode)
const searchQuery = computed(() => store.state.search.query)
Expand Down Expand Up @@ -76,6 +76,24 @@ function goToLast() {
item.value.parentElement.lastElementChild?.focus()
}

function clearPreview() {
if (isSetPreview.value) {
isSetPreview.value = false
emits('clearPreview', entry.value)
}
}

function setPreview() {
if (!isSetPreview.value) {
isSetPreview.value = true
emits('setPreview', entry.value)
}
}

onUnmounted(() => {
clearPreview()
})

defineExpose({
goToFirst,
goToLast,
Expand All @@ -93,10 +111,10 @@ defineExpose({
@keydown.home.prevent="goToFirst"
@keydown.end.prevent="goToLast"
@keyup.enter="selectItem"
@mouseenter="emits('setPreview', entry)"
@mouseleave="emits('clearPreview', entry)"
@focusin="emits('setPreview', entry)"
@focusout="emits('clearPreview', entry)"
@mouseenter="setPreview"
@mouseleave="clearPreview"
@focusin="setPreview"
@focusout="clearPreview"
>
<TextSearchMarker
class="search-category-entry-main px-2 flex-grow-1"
Expand Down
6 changes: 6 additions & 0 deletions tests/cypress/tests-e2e/search/search-results.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,13 @@ describe('Test the search bar result handling', () => {
expect(visibleIds).not.to.contain(expectedLayerId)
})

// Location - Leave via unmount
cy.get('@locationSearchResults').first().trigger('mouseenter')
cy.get('[data-cy="searchbar-clear"]').click()
cy.readStoreValue('state.map.previewedPinnedLocation').should('be.null')

cy.log('Clicking on the first entry to test handling of zoom/extent/position')
cy.get(searchbarSelector).paste('test')
cy.get(searchbarSelector).should('have.value', 'test')
cy.get('@locationSearchResults').first().realClick()
// search bar should take element's title as value if it's a location
Expand Down
Loading