-
Notifications
You must be signed in to change notification settings - Fork 576
fix: components props transmit bugs #6052
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
base: develop
Are you sure you want to change the base?
Conversation
TDesign Component Site Preview Open
|
commit: |
629d911 to
0ff87ad
Compare
0ff87ad to
89474fb
Compare
91c7f72 to
4e435cd
Compare
There was a problem hiding this 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
useEventForwardhook 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.
|
这样确实解决了问题,但是又增加了贡献的心智负担,写事件的时候要记得用这个hooks了 |
是的,不过这个问题大多数出现在输入类的组件🫠 |
There was a problem hiding this 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.
|
带在 1.18.0 的版本 |

🤔 这个 PR 的性质是?
🔗 相关 Issue
💡 需求背景和解决方案
修复部分组件的方法透传问题

根据在 #4802 得出的结论,问题的原因:
部分组件有这种处理方法:

虽然这样的解决方案不会将两个方法合并成数组
但后者会覆盖前者,即组件内部的回调方法就失效了,只会调用用户传入的方法。
🙋🌰 举个例子
selectInput基于Input,如果selectInput的onChange是非常必要的,但是又透传了inputProps,那么用户定义的onChange就会覆盖掉selectInput必要的onChange,可能会导致selectInput出现异常问题一个解决方案:
因为不止一个组件有这类问题,所以新建了一个hooks
useEventForward,用于处理这种特殊的情况。useEventForward会处理每一个event,并合并同名的方法,按照先调用组件的回调 再调用用户传入的回调的顺序调用一种情况
selectInput在透传tagInputProps的同时,提供了onTagChangeAPI,就是tagInput的onChange。这种情况下,onTagChange会比透传的(tagInputProps的onChange)先调用,更多层组件套用也是同理:用户通过透传props传入的事件会被最后调用,因为useEventForward的调用顺序是先调用组件的回调 再调用用户传入的回调📝 更新日志
tdesign-vue-next
@tdesign-vue-next/chat
@tdesign-vue-next/auto-import-resolver
☑️ 请求合并前的自查清单