Skip to content

fix(color-picker): incorrect default value for recentColors #5428

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

Merged
merged 5 commits into from
May 12, 2025

Conversation

RylanBot
Copy link
Collaborator

@RylanBot RylanBot commented May 9, 2025

🤔 这个 PR 的性质是?

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

🔗 相关 Issue

💡 需求背景和解决方案

📝 更新日志

  • 本条 PR 不需要纳入 Changelog

tdesign-vue-next

  • fix(color-picker): 无法正常显示和添加最近使用颜色

@tdesign-vue-next/chat

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

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

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

@tdesign-bot
Copy link
Collaborator

tdesign-bot commented May 9, 2025

📝 更新日志

tdesign-vue-next

  • fix(ColorPicker): 修复添加最近使用颜色功能异常的问题

@tdesign-bot
Copy link
Collaborator

tdesign-bot commented May 9, 2025

TDesign Component Site Preview Open

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

Copy link

pkg-pr-new bot commented May 9, 2025

tdesign-vue-next-demo

npm i https://pkg.pr.new/tdesign-vue-next@5428

commit: 2290fe4

@liweijie0812
Copy link
Collaborator

liweijie0812 commented May 9, 2025

api 平台的改下

@RylanBot
Copy link
Collaborator Author

RylanBot commented May 9, 2025

api 平台的改下

api 没问题… vue / react 那边也没问题,输出到 vue-next 这边就莫名是 undefined 🤔

@liweijie0812
Copy link
Collaborator

api 平台的改下

api 没问题… vue / react 那边也没问题,输出到 vue-next 这边就莫名是 undefined 🤔

找到了

image image

@liweijie0812
Copy link
Collaborator

const [recentlyUsedColors, setRecentlyUsedColors] = useDefaultValue(
recentColors,
props.defaultRecentColors,
props.onRecentColorsChange,
'recentColors',
);

export default function useDefaultValue<T, P extends any[]>(
value: Ref<T>,
defaultValue: T,
onChange: ChangeHandler<T, P>,
propsName: string,
): [Ref<T>, ChangeHandler<T, P>] {
const { emit, vnode } = getCurrentInstance();
const internalValue: Ref<T> = ref();
const vProps = vnode.props || {};
const isVMP =
Object.prototype.hasOwnProperty.call(vProps, propsName) ||
Object.prototype.hasOwnProperty.call(vProps, kebabCase(propsName));
if (isVMP) {
return [
value,
(newValue, ...args) => {
emit(`update:${propsName}`, newValue);
onChange?.(newValue, ...args);
},
];
}
internalValue.value = defaultValue;
return [
internalValue,
(newValue, ...args) => {
internalValue.value = newValue;
onChange?.(newValue, ...args);
},
];
}

@uyarn
Copy link
Collaborator

uyarn commented May 10, 2025

recentColors 支持受控和非受控 需要先用useDefaultValue 进行受控处理再传递给内部组件,确保正常支持受控和非受控
color-picker.ts修改为如下

 const [innerRecentColors, setInnerRecentColor] = useDefaultValue(
      recentColors,
      props.defaultRecentColors,
      props.onRecentColorsChange,
      'recentColors',
    );
...
<ColorPanel
          {...newProps}
          recentColors={innerRecentColors.value}
          onRecentColorsChange={setInnerRecentColor}
          disabled={props.disabled}
          value={innerValue.value}
          togglePopup={setVisible}
          onChange={(value: string, context: TdColorContext) => setInnerValue(value, context)}
 />

@RylanBot RylanBot force-pushed the fix/color/recent branch from 777d704 to 2290fe4 Compare May 10, 2025 14:41
@uyarn uyarn merged commit 940ad46 into develop May 12, 2025
1 check passed
@uyarn uyarn deleted the fix/color/recent branch May 12, 2025 10:55
@tdesign-bot tdesign-bot mentioned this pull request May 14, 2025
16 tasks
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.

4 participants