Skip to content

Commit

Permalink
fix(search): avoid body scroll when using local search (#2236)
Browse files Browse the repository at this point in the history
Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com>
  • Loading branch information
ChuHoMan and brc-dd authored Apr 16, 2023
1 parent ca8db8a commit 144a7d8
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/client/theme-default/components/VPLocalSearchBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
onKeyStroke,
useEventListener,
useLocalStorage,
useScrollLock,
useSessionStorage
} from '@vueuse/core'
import Mark from 'mark.js'
Expand All @@ -16,6 +17,7 @@ import {
createApp,
markRaw,
nextTick,
onBeforeUnmount,
onMounted,
ref,
shallowRef,
Expand All @@ -36,8 +38,9 @@ const emit = defineEmits<{
(e: 'close'): void
}>()
const el = shallowRef<HTMLDivElement>()
const resultsEl = shallowRef<HTMLDivElement>()
const el = shallowRef<HTMLElement>()
const resultsEl = shallowRef<HTMLElement>()
const body = shallowRef<HTMLElement>()
/* Search */
Expand Down Expand Up @@ -312,6 +315,20 @@ useEventListener('popstate', (event) => {
emit('close')
})
/** Lock body */
const isLocked = useScrollLock(body)
onMounted(() => {
body.value = document.body
nextTick(() => {
isLocked.value = true
})
})
onBeforeUnmount(() => {
isLocked.value = false
})
function formMarkRegex(terms: Set<string>) {
return new RegExp(
[...terms]
Expand Down

0 comments on commit 144a7d8

Please sign in to comment.