mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-12-17 14:19:05 +08:00
Improve quick search interactions [SCI-10706]
This commit is contained in:
parent
112360ce9f
commit
a7990ea2b7
2 changed files with 30 additions and 12 deletions
|
|
@ -5,6 +5,7 @@
|
||||||
<div class="flex items-center gap-2 flex-wrap mb-6">
|
<div class="flex items-center gap-2 flex-wrap mb-6">
|
||||||
<template v-for="group in searchGroups" :key="group.value">
|
<template v-for="group in searchGroups" :key="group.value">
|
||||||
<button class="btn btn-secondary btn-xs"
|
<button class="btn btn-secondary btn-xs"
|
||||||
|
ref="groupButtons"
|
||||||
:class="{'active': activeGroup === group.value}"
|
:class="{'active': activeGroup === group.value}"
|
||||||
@click="setActiveGroup(group.value)">
|
@click="setActiveGroup(group.value)">
|
||||||
{{ group.label }}
|
{{ group.label }}
|
||||||
|
|
|
||||||
|
|
@ -2,25 +2,27 @@
|
||||||
<GeneralDropdown ref="container" :canOpen="canOpen" :fieldOnlyOpen="true" @close="filtersOpened = false; flyoutOpened = false" @open="flyoutOpened = true">
|
<GeneralDropdown ref="container" :canOpen="canOpen" :fieldOnlyOpen="true" @close="filtersOpened = false; flyoutOpened = false" @open="flyoutOpened = true">
|
||||||
<template v-slot:field>
|
<template v-slot:field>
|
||||||
<div class="sci--navigation--top-menu-search left-icon sci-input-container-v2" :class="{'disabled' : !currentTeam}" :title="i18n.t('nav.search')">
|
<div class="sci--navigation--top-menu-search left-icon sci-input-container-v2" :class="{'disabled' : !currentTeam}" :title="i18n.t('nav.search')">
|
||||||
<input ref="searchField" type="text" class="!pr-20" v-model="searchQuery" @keydown="focusHistoryItem"
|
<input ref="searchField" type="text" class="!pr-20" v-model="searchQuery"
|
||||||
:class="{'active': flyoutOpened}"
|
@keydown="focusHistoryItem"
|
||||||
|
@keydown.down="focusQuickSearchResults"
|
||||||
@keydown.escape="closeFlyout"
|
@keydown.escape="closeFlyout"
|
||||||
@focus="openHistory" :placeholder="i18n.t('nav.search')" @keydown.enter="saveQuery"/>
|
@focus="openHistory" :placeholder="i18n.t('nav.search')" @keydown.enter="saveQuery"/>
|
||||||
<i class="sn-icon sn-icon-search"></i>
|
<i class="sn-icon sn-icon-search"></i>
|
||||||
<div v-if="this.searchQuery.length > 1" class="flex items-center gap-1 absolute right-2 top-1.5">
|
<div v-if="this.searchQuery.length > 1" class="flex items-center gap-1 absolute right-2 top-1.5">
|
||||||
<div class="btn btn-light icon-btn btn-xs" @click="this.searchQuery = ''; $refs.searchField.focus()">
|
<button class="btn btn-light icon-btn btn-xs" @click="this.searchQuery = ''; $refs.searchField.focus()">
|
||||||
<i class="sn-icon sn-icon-close m-0" :title="i18n.t('nav.clear')"></i>
|
<i class="sn-icon sn-icon-close m-0" :title="i18n.t('nav.clear')"></i>
|
||||||
</div>
|
</button>
|
||||||
<div class="btn btn-light icon-btn btn-xs" :title="i18n.t('search.quick_search.search_options')"
|
<button class="btn btn-light icon-btn btn-xs" :title="i18n.t('search.quick_search.search_options')"
|
||||||
:class="{'active': filtersOpened}" @click="filtersOpened = !filtersOpened">
|
:class="{'active': filtersOpened}" @click="filtersOpened = !filtersOpened">
|
||||||
<i class="sn-icon sn-icon-search-options m-0"></i>
|
<i class="sn-icon sn-icon-search-options m-0"></i>
|
||||||
</div>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<template v-slot:flyout >
|
<template v-slot:flyout >
|
||||||
<SearchFilters
|
<SearchFilters
|
||||||
class="px-3.5"
|
class="px-3.5"
|
||||||
|
ref="filters"
|
||||||
v-if="filtersOpened"
|
v-if="filtersOpened"
|
||||||
:teamsUrl="teamsUrl"
|
:teamsUrl="teamsUrl"
|
||||||
:usersUrl="usersUrl"
|
:usersUrl="usersUrl"
|
||||||
|
|
@ -43,6 +45,7 @@
|
||||||
<div v-else class="w-[600px]">
|
<div v-else class="w-[600px]">
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<button class="btn btn-secondary btn-xs"
|
<button class="btn btn-secondary btn-xs"
|
||||||
|
ref="experimentGroup"
|
||||||
:class="{'active': quickFilter === 'experiments'}"
|
:class="{'active': quickFilter === 'experiments'}"
|
||||||
@click="setQuickFilter('experiments')">
|
@click="setQuickFilter('experiments')">
|
||||||
{{ i18n.t('search.quick_search.experiments') }}
|
{{ i18n.t('search.quick_search.experiments') }}
|
||||||
|
|
@ -61,7 +64,7 @@
|
||||||
<hr class="my-2">
|
<hr class="my-2">
|
||||||
<a v-if="!loading" v-for="(result, i) in results" :key="i"
|
<a v-if="!loading" v-for="(result, i) in results" :key="i"
|
||||||
:href="getUrl(result.attributes)"
|
:href="getUrl(result.attributes)"
|
||||||
class="px-3 py-2 hover:bg-sn-super-light-grey cursor-pointer
|
class="px-3 py-2 hover:bg-sn-super-light-grey cursor-pointer focus:no-underline
|
||||||
text-sn-black hover:no-underline active:no-underline hover:text-black block"
|
text-sn-black hover:no-underline active:no-underline hover:text-black block"
|
||||||
>
|
>
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
|
|
@ -104,9 +107,9 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<hr class="my-2">
|
<hr class="my-2">
|
||||||
<div class="btn btn-light" @click="searchValue">
|
<button class="btn btn-light" @click="searchValue">
|
||||||
{{ i18n.t('search.quick_search.all_results', {query: searchQuery}) }}
|
{{ i18n.t('search.quick_search.all_results', {query: searchQuery}) }}
|
||||||
</div>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</GeneralDropdown>
|
</GeneralDropdown>
|
||||||
|
|
@ -167,6 +170,9 @@ export default {
|
||||||
if (this.searchQuery.length > 1) {
|
if (this.searchQuery.length > 1) {
|
||||||
this.fetchQuickSearchResults();
|
this.fetchQuickSearchResults();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
filtersOpened() {
|
||||||
|
if (this.filtersOpened) this.$nextTick(() => { this.focusFilters() });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
|
|
@ -311,21 +317,32 @@ export default {
|
||||||
focusHistoryItem(event) {
|
focusHistoryItem(event) {
|
||||||
if (this.focusedHistoryItem === null && (event.key === 'ArrowDown' || event.key === 'ArrowUp')) {
|
if (this.focusedHistoryItem === null && (event.key === 'ArrowDown' || event.key === 'ArrowUp')) {
|
||||||
this.focusedHistoryItem = 0;
|
this.focusedHistoryItem = 0;
|
||||||
this.$refs.historyItems[this.focusedHistoryItem].focus();
|
this.$refs.historyItems[this.focusedHistoryItem]?.focus();
|
||||||
} else if (event.key === 'ArrowDown') {
|
} else if (event.key === 'ArrowDown') {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
this.focusedHistoryItem += 1;
|
this.focusedHistoryItem += 1;
|
||||||
if (this.focusedHistoryItem >= this.$refs.historyItems.length) {
|
if (this.focusedHistoryItem >= this.$refs.historyItems.length) {
|
||||||
this.focusedHistoryItem = 0;
|
this.focusedHistoryItem = 0;
|
||||||
}
|
}
|
||||||
this.$refs.historyItems[this.focusedHistoryItem].focus();
|
this.$refs.historyItems[this.focusedHistoryItem]?.focus();
|
||||||
} else if (event.key === 'ArrowUp') {
|
} else if (event.key === 'ArrowUp') {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
this.focusedHistoryItem -= 1;
|
this.focusedHistoryItem -= 1;
|
||||||
if (this.focusedHistoryItem < 0) {
|
if (this.focusedHistoryItem < 0) {
|
||||||
this.focusedHistoryItem = this.$refs.historyItems.length - 1;
|
this.focusedHistoryItem = this.$refs.historyItems.length - 1;
|
||||||
}
|
}
|
||||||
this.$refs.historyItems[this.focusedHistoryItem].focus();
|
this.$refs.historyItems[this.focusedHistoryItem]?.focus();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
focusQuickSearchResults(e) {
|
||||||
|
this.$refs.experimentGroup?.focus();
|
||||||
|
e.preventDefault();
|
||||||
|
},
|
||||||
|
focusFilters() {
|
||||||
|
const { filters } = this.$refs;
|
||||||
|
|
||||||
|
if (filters) {
|
||||||
|
filters.$refs.groupButtons[0].focus();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
closeFlyout() {
|
closeFlyout() {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue