diff --git a/packages/hooks/__tests__/use-lockscreen.test.tsx b/packages/hooks/__tests__/use-lockscreen.test.tsx
index 1909c5ea272f07..00987d3cc94e5b 100644
--- a/packages/hooks/__tests__/use-lockscreen.test.tsx
+++ b/packages/hooks/__tests__/use-lockscreen.test.tsx
@@ -2,6 +2,7 @@ import { computed, defineComponent, nextTick, onMounted, ref } from 'vue'
import { mount } from '@vue/test-utils'
import { describe, expect, it } from 'vitest'
import { hasClass } from '@element-plus/utils'
+import sleep from '@element-plus/test-utils/sleep'
import { useLockscreen } from '../use-lockscreen'
import { useNamespace } from '../use-namespace'
@@ -78,4 +79,30 @@ describe('useLockscreen', () => {
wrapper.unmount()
})
+
+ it('should not remove class name when another trigger is true', async () => {
+ // await the previous test remove class name
+ await sleep(250)
+ const trigger = mount({
+ setup: () => () => ,
+ })
+ const anotherTrigger = mount({
+ setup: () => () => ,
+ })
+ await nextTick()
+
+ expect(hasClass(document.body, kls)).toBe(true)
+
+ anotherTrigger.unmount()
+ await nextTick()
+ await sleep(250)
+
+ expect(hasClass(document.body, kls)).toBe(true)
+
+ trigger.unmount()
+ await nextTick()
+
+ await sleep(250)
+ expect(hasClass(document.body, kls)).toBe(false)
+ })
})
diff --git a/packages/hooks/use-lockscreen/index.ts b/packages/hooks/use-lockscreen/index.ts
index 6389b1c585daeb..1650cf96d8715b 100644
--- a/packages/hooks/use-lockscreen/index.ts
+++ b/packages/hooks/use-lockscreen/index.ts
@@ -57,7 +57,7 @@ export const useLockscreen = (
}
watch(trigger, (val) => {
if (!val) {
- cleanup()
+ withoutHiddenClass && cleanup()
return
}
@@ -78,5 +78,5 @@ export const useLockscreen = (
}
addClass(document.body, hiddenCls.value)
})
- onScopeDispose(() => cleanup())
+ onScopeDispose(() => withoutHiddenClass && cleanup())
}