Skip to content

Commit

Permalink
fix: improve keyboard operability especially on search page and editor (
Browse files Browse the repository at this point in the history
#2730)

Co-authored-by: patak <583075+patak-dev@users.noreply.github.com>
  • Loading branch information
shuuji3 and patak-dev authored Apr 1, 2024
1 parent 587c063 commit eee671c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions components/publish/PublishWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ onDeactivated(() => {
flex max-w-full
:class="shouldExpanded ? 'min-h-30 md:max-h-[calc(100vh-200px)] sm:max-h-[calc(100vh-400px)] max-h-35 of-y-auto overscroll-contain' : ''"
@keydown="stopQuestionMarkPropagation"
@keydown.esc.prevent="editor?.commands.blur()"
/>
</div>

Expand Down
1 change: 1 addition & 0 deletions components/search/SearchWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function activate() {
placeholder-text-secondary
@keydown.down.prevent="shift(1)"
@keydown.up.prevent="shift(-1)"
@keydown.esc.prevent="input?.blur()"
@keypress.enter="activate"
>
<button v-if="query.length" btn-action-icon text-secondary @click="query = ''; input?.focus()">
Expand Down
13 changes: 10 additions & 3 deletions pages/[[server]]/search.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
<script setup lang="ts">
const keys = useMagicKeys()
const { t } = useI18n()
useHydratedHead({
title: () => t('nav.search'),
})
const search = ref<{ input?: HTMLInputElement }>()
watchEffect(() => {
if (search.value?.input)
search.value?.input?.focus()
})
onActivated(() =>
search.value?.input?.focus(),
)
onActivated(() => search.value?.input?.focus())
onDeactivated(() => search.value?.input?.blur())
watch(keys['/'], (v) => {
// focus on input when '/' is up to avoid '/' being typed
if (!v)
search.value?.input?.focus()
})
</script>

<template>
Expand Down

0 comments on commit eee671c

Please sign in to comment.