fix(search): avoid body scroll when using local search (#2236)

Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com>
pull/2239/head
ChuHoMan 2 years ago committed by GitHub
parent ca8db8adca
commit 144a7d8e4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,6 +6,7 @@ import {
onKeyStroke, onKeyStroke,
useEventListener, useEventListener,
useLocalStorage, useLocalStorage,
useScrollLock,
useSessionStorage useSessionStorage
} from '@vueuse/core' } from '@vueuse/core'
import Mark from 'mark.js' import Mark from 'mark.js'
@ -16,6 +17,7 @@ import {
createApp, createApp,
markRaw, markRaw,
nextTick, nextTick,
onBeforeUnmount,
onMounted, onMounted,
ref, ref,
shallowRef, shallowRef,
@ -36,8 +38,9 @@ const emit = defineEmits<{
(e: 'close'): void (e: 'close'): void
}>() }>()
const el = shallowRef<HTMLDivElement>() const el = shallowRef<HTMLElement>()
const resultsEl = shallowRef<HTMLDivElement>() const resultsEl = shallowRef<HTMLElement>()
const body = shallowRef<HTMLElement>()
/* Search */ /* Search */
@ -312,6 +315,20 @@ useEventListener('popstate', (event) => {
emit('close') 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>) { function formMarkRegex(terms: Set<string>) {
return new RegExp( return new RegExp(
[...terms] [...terms]

Loading…
Cancel
Save