Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(hooks): [use-lockscreen] removing class name at wrong time #16389

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions packages/hooks/__tests__/use-lockscreen.test.tsx
Expand Up @@ -3,6 +3,7 @@ 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'

Expand Down Expand Up @@ -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: () => () => <Comp />,
})
const anotherTrigger = mount({
setup: () => () => <Comp />,
})
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)
})
})
4 changes: 2 additions & 2 deletions packages/hooks/use-lockscreen/index.ts
Expand Up @@ -57,7 +57,7 @@ export const useLockscreen = (
}
watch(trigger, (val) => {
if (!val) {
cleanup()
withoutHiddenClass && cleanup()
return
}

Expand All @@ -78,5 +78,5 @@ export const useLockscreen = (
}
addClass(document.body, hiddenCls.value)
})
onScopeDispose(() => cleanup())
onScopeDispose(() => withoutHiddenClass && cleanup())
}