fix(hooks): [useLockscreen] close shake (#9610)

* fix(hooks): [useLockscreen] close shake

* fix(hooks): [useLockscreen] remove unused

* fix(hooks): [useLockscreen] unit test
This commit is contained in:
Xc 2022-09-03 22:57:37 +08:00 committed by GitHub
parent adc468cb50
commit fda97e27dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 7 deletions

View File

@ -29,7 +29,10 @@ describe('useLockscreen', () => {
wrapper.unmount()
await nextTick()
expect(hasClass(document.body, kls)).toBe(false)
setTimeout(() => {
expect(hasClass(document.body, kls)).toBe(false)
}, 250)
})
it('should cleanup when unmounted', async () => {
@ -45,6 +48,8 @@ describe('useLockscreen', () => {
shouldRender.value = false
await nextTick()
expect(hasClass(document.body, kls)).toBe(false)
setTimeout(() => {
expect(hasClass(document.body, kls)).toBe(false)
}, 250)
})
})

View File

@ -1,5 +1,4 @@
import { isRef, onScopeDispose, watch } from 'vue'
import { computed } from '@vue/reactivity'
import { isClient } from '@vueuse/core'
import {
@ -40,10 +39,12 @@ export const useLockscreen = (trigger: Ref<boolean>) => {
let bodyWidth = '0'
const cleanup = () => {
removeClass(document.body, hiddenCls.value)
if (withoutHiddenClass) {
document.body.style.width = bodyWidth
}
setTimeout(() => {
removeClass(document.body, hiddenCls.value)
if (withoutHiddenClass) {
document.body.style.width = bodyWidth
}
}, 200)
}
watch(trigger, (val) => {
if (!val) {