Skip to content

chore: refactor hover #1998

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

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft

chore: refactor hover #1998

wants to merge 1 commit into from

Conversation

liweijie0812
Copy link
Collaborator

@liweijie0812 liweijie0812 commented Aug 22, 2025

🤔 这个 PR 的性质是?

  • 日常 bug 修复
  • 新特性提交
  • 文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • CI/CD 改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他

🔗 相关 Issue

💡 需求背景和解决方案

📝 更新日志

  • fix(组件名称): 处理问题或特性描述 ...

  • 本条 PR 不需要纳入 Changelog

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • Changelog 已提供或无须提供

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the v-hover directive implementation to improve its functionality, type safety, and maintainability. The refactor transforms a basic touch-only hover directive into a more robust solution with enhanced features.

  • Enhanced the directive to support both pointer and touch events with proper fallback handling
  • Added comprehensive configuration options and type definitions
  • Implemented proper lifecycle management with cleanup and reactive updates

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

// 保存上下文
// @ts-ignore - 自定义 symbol 属性
el[CTX_KEY] = ctx;

Copy link
Preview

Copilot AI Aug 22, 2025

Choose a reason for hiding this comment

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

Using @ts-ignore suppresses TypeScript checking. Consider extending the HTMLElement interface or using a WeakMap to store context data instead of attaching it directly to DOM elements.

Suggested change
hoverContextMap.set(el, ctx);

Copilot uses AI. Check for mistakes.

},
updated(el, binding) {
// @ts-ignore
const ctx: HoverContext | undefined = el[CTX_KEY];
Copy link
Preview

Copilot AI Aug 22, 2025

Choose a reason for hiding this comment

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

Using @ts-ignore suppresses TypeScript checking. Consider extending the HTMLElement interface or using a WeakMap to store context data instead of attaching it directly to DOM elements.

Copilot uses AI. Check for mistakes.

ctx.current = next;
},
unmounted(el) {
// @ts-ignore
Copy link
Preview

Copilot AI Aug 22, 2025

Choose a reason for hiding this comment

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

Using @ts-ignore suppresses TypeScript checking. Consider extending the HTMLElement interface or using a WeakMap to store context data instead of attaching it directly to DOM elements.

Copilot uses AI. Check for mistakes.

el.removeEventListener('touchcancel', ctx.cancelHandler);
el.removeEventListener('touchmove', ctx.cancelHandler);
}
// @ts-ignore
Copy link
Preview

Copilot AI Aug 22, 2025

Choose a reason for hiding this comment

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

Using @ts-ignore suppresses TypeScript checking. Consider extending the HTMLElement interface or using a WeakMap to store context data instead of attaching it directly to DOM elements.

Copilot uses AI. Check for mistakes.

// className 变化需要替换
if (prev.className !== next.className) {
if (prev.className) el.classList.remove(prev.className);
if (!next.disabledHover && next.className && el.matches(':active')) {
Copy link
Preview

Copilot AI Aug 22, 2025

Choose a reason for hiding this comment

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

Using :active pseudo-class may not work reliably for touch devices. The hover directive is designed for touch interactions, but :active behaves differently across touch and pointer devices.

Suggested change
if (!next.disabledHover && next.className && el.matches(':active')) {
if (!next.disabledHover && next.className) {

Copilot uses AI. Check for mistakes.

@liweijie0812 liweijie0812 marked this pull request as draft August 22, 2025 02:56
Copy link

pkg-pr-new bot commented Aug 22, 2025

Open in StackBlitz

npm i https://pkg.pr.new/tdesign-mobile-vue@1998

commit: 99579fd

Copy link
Contributor

完成

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

Successfully merging this pull request may close these issues.

1 participant