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

Conversation

JauSingSing
Copy link

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

  • 修复 use-lockscreen 在错误的时机移除 body 的 class name
  • 问题复现链接
  • 增加了测试用例

Copy link

👋 @JauSingSing, seems like this is your first time contribution to element-plus.

  • Please make sure that you have read our guidelines and code of conduct before making a contribution.
  • You can comment with /label Components:[component_name] to add a label for which component you are working on.
  • You may join our Discord for staying tuned.

@pull-request-triage pull-request-triage bot added 1st contribution Their very first contribution Needs Review labels Apr 3, 2024
Copy link

github-actions bot commented Apr 3, 2024

Copy link

github-actions bot commented Apr 3, 2024

Hello @JauSingSing, thank you for contributing to element-plus, please see our guideline to see how to make contribution

Copy link

github-actions bot commented Apr 3, 2024

🧪 Playground Preview: https://element-plus.run/?pr=16389
Please comment the example via this playground if needed.

@JauSingSing JauSingSing reopened this Apr 7, 2024
@JauSingSing
Copy link
Author

@btea Hi, I messed up the commit before :( , it looks more normal now. Please review it in your free time, thx.

Copy link
Collaborator

@btea btea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@colinchen-lb
Copy link

colinchen-lb commented May 23, 2024

这个代码还是有点问题,当第一个弹框关闭的同时第二个弹框出现,第一个弹框 withoutHiddenClass 是 true,会 remove 掉 class,这是错的,请看下面用例 @btea @JauSingSing

   it('should not remove class name when another trigger sync true', async () => {
      await sleep(250)
      const trigger = mount({
        setup: () => () => <Comp />,
      })

      await nextTick()
      expect(hasClass(document.body, kls)).toBe(true)
      
      trigger.unmount()
      // Trigger is close and anotherTrigger is open

      const anotherTrigger = mount({
        setup: () => () => <Comp />,
      })
      await nextTick()
      await sleep(250)
      expect(hasClass(document.body, kls)).toBe(true)
    })

@colinchen-lb
Copy link

colinchen-lb commented May 23, 2024

@JauSingSing @btea
我建议,直接隐藏样式类名上加一个随机数

image

然后新增一个判断函数

export const hasClassPrefix = (el: Element, cls: string): boolean => {
  if (!el || !cls) return false
  if (cls.includes(' ')) throw new Error('className should not contain space.')
  for (const className of el.classList) {
    if (className.startsWith(cls)) {
      return true
    }
  }
  return false
}
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants