Skip to content

Conversation

Wesley-0808
Copy link
Collaborator

@Wesley-0808 Wesley-0808 commented Oct 9, 2025

🤔 这个 PR 的性质是?

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

🔗 相关 Issue

💡 需求背景和解决方案

修复部分组件的方法透传问题
根据在 #4802 得出的结论,问题的原因:
image

部分组件有这种处理方法:
image
虽然这样的解决方案不会将两个方法合并成数组
但后者会覆盖前者,即组件内部的回调方法就失效了,只会调用用户传入的方法。

🙋🌰 举个例子

  • selectInput 基于 Input,如果 selectInputonChange 是非常必要的,但是又透传了 inputProps ,那么用户定义的 onChange 就会覆盖掉 selectInput 必要的 onChange ,可能会导致 selectInput 出现异常问题

一个解决方案:

因为不止一个组件有这类问题,所以新建了一个hooks useEventForward,用于处理这种特殊的情况。
useEventForward会处理每一个event,并合并同名的方法,按照先调用组件的回调 再调用用户传入的回调的顺序调用

一种情况

  • selectInput 在透传 tagInputProps 的同时,提供了 onTagChange API,就是 tagInputonChange。这种情况下,onTagChange 会比透传的(tagInputPropsonChange)先调用,更多层组件套用也是同理:用户通过透传props传入的事件会被最后调用,因为useEventForward的调用顺序是先调用组件的回调 再调用用户传入的回调

📝 更新日志

  • 本条 PR 不需要纳入 Changelog

tdesign-vue-next

  • fix(TagInput): 优化透传组件 props 事件的处理方式,修复透传的回调函数无法触发的问题
  • fix(Cascader): 优化透传组件 props 事件的处理方式,修复透传的回调函数无法触发的问题
  • fix(SelectInput): 优化透传组件 props 事件的处理方式,修复透传的回调函数无法触发的问题
  • fix(Upload): 优化透传组件 props 事件的处理方式,修复透传的回调函数无法触发的问题
  • fix(TreeSelect): 优化透传组件 props 事件的处理方式,修复透传的回调函数无法触发的问题
  • fix(Table): 优化透传组件 props 事件的处理方式,修复透传的回调函数无法触发的问题
  • fix(ColorPicker): 优化透传组件 props 事件的处理方式,修复透传的回调函数无法触发的问题
  • fix(DatePicker): 优化透传组件 props 事件的处理方式,修复透传的回调函数无法触发的问题
  • fix(InputNumber): 优化透传组件 props 事件的处理方式,修复透传的回调函数无法触发的问题
  • fix(RangeInput): 优化透传组件 props 事件的处理方式,修复透传的回调函数无法触发的问题
  • fix(TimePicker): 优化透传组件 props 事件的处理方式,修复透传的回调函数无法触发的问题
  • fix(Select): 优化透传组件 props 事件的处理方式,修复透传的回调函数无法触发的问题
  • fix(AutoComplete): 优化透传组件 props 事件的处理方式,修复透传的回调函数无法触发的问题
  • fix(Transfer): 优化透传组件 props 事件的处理方式,修复透传的回调函数无法触发的问题

@tdesign-vue-next/chat

@tdesign-vue-next/auto-import-resolver

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

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

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

@tdesign-bot
Copy link
Collaborator

tdesign-bot commented Oct 9, 2025

TDesign Component Site Preview Open

Component Preview
tdesign-vue-next 完成
@tdesign-vue-next/chat 完成

@Wesley-0808 Wesley-0808 requested a review from RSS1102 October 9, 2025 15:40
@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 9, 2025

tdesign-vue-next-demo

npm i https://pkg.pr.new/Tencent/tdesign-vue-next/@tdesign-vue-next/auto-import-resolver@6052
npm i https://pkg.pr.new/Tencent/tdesign-vue-next@6052
npm i https://pkg.pr.new/Tencent/tdesign-vue-next/@tdesign-vue-next/chat@6052

commit: cf93a09

@Wesley-0808 Wesley-0808 force-pushed the wesley/fix/props-transmit branch from 629d911 to 0ff87ad Compare October 10, 2025 11:10
@Wesley-0808 Wesley-0808 force-pushed the wesley/fix/props-transmit branch from 0ff87ad to 89474fb Compare October 10, 2025 11:21
@Wesley-0808 Wesley-0808 force-pushed the wesley/fix/props-transmit branch from 91c7f72 to 4e435cd Compare October 10, 2025 12:52
@Wesley-0808 Wesley-0808 removed the WIP label Oct 10, 2025
@liweijie0812 liweijie0812 requested a review from Copilot October 13, 2025 01:33
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 fixes a critical bug in props transmission across multiple TDesign Vue components where component event handlers were being overridden by user-provided event handlers instead of being properly merged.

  • Introduces a new useEventForward hook to handle merging of component and user event handlers
  • Fixes props transmission issues in 11 components (TagInput, Cascader, SelectInput, Upload, TreeSelect, Table, ColorPicker, DatePicker, InputNumber, RangeInput, TimePicker)
  • Ensures component internal handlers execute first, followed by user-provided handlers, preventing component functionality from being broken

Reviewed Changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/shared/hooks/useEventForward/index.ts New hook implementation for merging event handlers with error handling
packages/shared/hooks/useEventForward/index.md Documentation placeholder for the new hook
packages/shared/hooks/index.ts Export the new useEventForward hook
packages/components/upload/components/multiple-flow-list.tsx Apply useEventForward to upload/cancel button props
packages/components/tree-select/tree-select.tsx Fix event forwarding for tree and selectInput props
packages/components/time-picker/time-range-picker.tsx Apply useEventForward to rangeInput and popup props
packages/components/time-picker/time-picker.tsx Fix selectInput props event forwarding
packages/components/tag-input/tag-input.tsx Apply useEventForward to input props
packages/components/tag-input/hooks/useTagList.tsx Fix tag props event forwarding
packages/components/table/base-table.tsx Apply useEventForward to affix props
packages/components/select-input/hooks/useSingle.tsx Fix input props event forwarding
packages/components/select-input/hooks/useMultiple.tsx Apply useEventForward to tagInput props
packages/components/range-input/range-input.tsx Fix event forwarding for both input instances
packages/components/input-number/input-number.tsx Apply useEventForward to input props
packages/components/date-picker/DatePicker.tsx Fix selectInput props event forwarding
packages/components/color-picker/components/trigger/index.tsx Apply useEventForward to input props
packages/components/cascader/cascader.tsx Fix selectInput props event forwarding and remove omit usage
packages/components/upload/_example/test.vue Test example for upload component
packages/components/tag-input/_example/testinput.vue Test example for tag-input component
packages/components/select-input/_example/testinput.vue Test example for select-input component

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

@uyarn
Copy link
Collaborator

uyarn commented Oct 13, 2025

这样确实解决了问题,但是又增加了贡献的心智负担,写事件的时候要记得用这个hooks了

@Wesley-0808
Copy link
Collaborator Author

这样确实解决了问题,但是又增加了贡献的心智负担,写事件的时候要记得用这个hooks了

是的,不过这个问题大多数出现在输入类的组件🫠

@Wesley-0808 Wesley-0808 requested a review from Copilot October 14, 2025 06:27
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

Copilot reviewed 23 out of 23 changed files in this pull request and generated 5 comments.

Comments suppressed due to low confidence (1)

packages/shared/hooks/useEventForward/index.ts:1

  • [nitpick] Consider using a more structured logging approach or making the error handling configurable. Direct console.warn calls may not be appropriate for all environments (production, testing, etc.).
import { computed, ComputedRef } from 'vue';

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

@uyarn
Copy link
Collaborator

uyarn commented Oct 23, 2025

带在 1.18.0 的版本

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.

3 participants