From fda97e27dd2d790869d71ec34ff0af79e347434c Mon Sep 17 00:00:00 2001 From: Xc <124118265@qq.com> Date: Sat, 3 Sep 2022 22:57:37 +0800 Subject: [PATCH] fix(hooks): [useLockscreen] close shake (#9610) * fix(hooks): [useLockscreen] close shake * fix(hooks): [useLockscreen] remove unused * fix(hooks): [useLockscreen] unit test --- packages/hooks/__tests__/use-lockscreen.test.tsx | 9 +++++++-- packages/hooks/use-lockscreen/index.ts | 11 ++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/hooks/__tests__/use-lockscreen.test.tsx b/packages/hooks/__tests__/use-lockscreen.test.tsx index 813f075ad1..c041051f36 100644 --- a/packages/hooks/__tests__/use-lockscreen.test.tsx +++ b/packages/hooks/__tests__/use-lockscreen.test.tsx @@ -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) }) }) diff --git a/packages/hooks/use-lockscreen/index.ts b/packages/hooks/use-lockscreen/index.ts index 484dbc91b3..41999acafd 100644 --- a/packages/hooks/use-lockscreen/index.ts +++ b/packages/hooks/use-lockscreen/index.ts @@ -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) => { 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) {