Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 28, 2025

🤔 这个 PR 的性质是?

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

🔗 相关 Issue

https://github.com/Tencent/tdesign-vue-next/issues/6228

💡 需求背景和解决方案

When using creatable mode with an async onCreate callback (e.g., setTimeout to validate with backend), the component crashes because getSelectedOptions() is called before the option exists in optionsList.

<t-select
  v-model="value"
  creatable
  filterable
  :options="options"
  @create="(val) => {
    // Async validation causes error
    setTimeout(() => {
      options.push({ label: val, value: val });
    }, 100);
  }"
/>

Fix: When createAble is true, construct the option object directly from props instead of calling getSelectedOptions():

const createdOption = { value: props.value, label: labelText.value };

This ensures onChange receives valid option data regardless of async callback timing.

Test case: Added test case under describe('@event', ...) section with proper naming describe('onCreate #6228', ...), following the repository test format standards used by other event tests like onClear and onChange.

📝 更新日志

  • 本条 PR 不需要纳入 Changelog

tdesign-vue-next

  • fix(select): 修复 creatable 模式下使用异步 onCreate 回调时报错的问题

@tdesign-vue-next/chat

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

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

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

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

This section details on the original issue you should resolve

<issue_title>[select] 新增选项时报错</issue_title>
<issue_description>### tdesign-vue-next 版本

最新版本

重现链接

https://stackblitz.com/edit/cph2gsoe?file=src%2Fdemo.vue

重现步骤

新增选项的时候 如果不加定时器是可以的 加上定时器 是因为需要询问后端 这个是否可添加 但是这样就会造成添加错误 导致控制台报错

期望结果

No response

实际结果

No response

框架版本

No response

浏览器版本

No response

系统版本

No response

Node版本

20.10.0

补充说明

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits November 28, 2025 12:56
Co-authored-by: liweijie0812 <10710889+liweijie0812@users.noreply.github.com>
Co-authored-by: liweijie0812 <10710889+liweijie0812@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix error when adding options with timer fix(select): handle async option creation in creatable mode Nov 28, 2025
Copilot AI requested a review from liweijie0812 November 28, 2025 13:01
Copilot finished work on behalf of liweijie0812 November 28, 2025 13:01
@liweijie0812
Copy link
Collaborator

@copilot 测试案例格式根据仓库规范来,可以参考form的

Co-authored-by: liweijie0812 <10710889+liweijie0812@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 28, 2025

@copilot 测试案例格式根据仓库规范来,可以参考form的

Updated the test case format to follow repository standards in commit f059dda. The test is now nested under describe('@event', ...) with proper naming describe('onCreate #6228', ...), matching the pattern used by other event tests like onClear and onChange.

Copilot finished work on behalf of liweijie0812 November 28, 2025 13:10
@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 28, 2025

tdesign-vue-next-demo

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

commit: f059dda

@tdesign-bot
Copy link
Collaborator

tdesign-bot commented Nov 29, 2025

TDesign Component Site Preview Open

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

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.

[select] 新增选项时报错

3 participants