From 4ddb96fe508578893ee5a44621b5bac098bd4710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20S=C3=A1nchez?= Date: Sat, 10 Jun 2023 11:12:27 +0200 Subject: [PATCH] feat(theme): add semantic markup to local search dialog (#2325) --- .../components/VPLocalSearchBox.vue | 176 +++++++++++------- 1 file changed, 104 insertions(+), 72 deletions(-) diff --git a/src/client/theme-default/components/VPLocalSearchBox.vue b/src/client/theme-default/components/VPLocalSearchBox.vue index 139d4197..b89415c9 100644 --- a/src/client/theme-default/components/VPLocalSearchBox.vue +++ b/src/client/theme-default/components/VPLocalSearchBox.vue @@ -241,10 +241,12 @@ async function fetchExcerpt(id: string) { /* Search input focus */ const searchInput = ref() - -function focusSearchInput() { +const disableReset = computed(() => { + return filterText.value?.length <= 0 +}) +function focusSearchInput(select = true) { searchInput.value?.focus() - searchInput.value?.select() + select && searchInput.value?.select() } onMounted(() => { @@ -259,11 +261,11 @@ function onSearchBarClick(event: PointerEvent) { /* Search keyboard selection */ -const selectedIndex = ref(0) +const selectedIndex = ref(-1) const disableMouseOver = ref(false) -watch(results, () => { - selectedIndex.value = 0 +watch(results, (r) => { + selectedIndex.value = r.length ? 0 : -1 scrollToSelectedResult() }) @@ -360,6 +362,11 @@ onBeforeUnmount(() => { isLocked.value = false }) +function resetSearch() { + filterText.value = '' + nextTick().then(() => focusSearchInput(false)) +} + function formMarkRegex(terms: Set) { return new RegExp( [...terms] @@ -377,34 +384,44 @@ function formMarkRegex(terms: Set) {