feat(ColorPicker): add onClear#42634
Conversation
|
补个 |
|
单测挂了,本地调试一下。 |
|
@RedJue 这个单测不知道怎么不行,你看看 |
|
还有个问题,一直点击清除,会一直触发 onChange 和 onClear,0 和 100 会反复切换,这是故意为之还是 bug?已经是 clear 状态再点清除不是应该什么都不发生吗 |
是 |
这个可以跟 清空后不隐藏面板 的问题一起修复,然后提 pr 到 master |
| const { container } = render(<ColorPicker allowClear onClear={onClear} />); | ||
| fireEvent.click(container.querySelector('.ant-color-picker-trigger')!); | ||
| await waitFakeTimer(); | ||
| expect(container.querySelector('.ant-popover-hidden')).toBeFalsy(); |
There was a problem hiding this comment.
加上了之后,最后那行还是 0%,得不到 100%
There was a problem hiding this comment.
我知道不一样,删掉那几行是可以了,但是这几行看上去感觉没问题。
There was a problem hiding this comment.
有问题,现在是点击清空不关闭弹窗,删掉那部分逻辑是按之前点击清空关闭弹窗来走的,按现在逻辑再点击就关闭了,自然触发就有问题。
There was a problem hiding this comment.
这几行意思是点击一下方块,获取值是 0,应该没问题吧,跟是否关闭弹窗有关系么。删了删了,等另一个 pr 合并再更新这里的。
猜测可能单测里行为和现在的预期不一样,尝试删掉这几行 https://github.com/ant-design/ant-design/pull/42634/files#diff-aa06460351e8630f305cf6509e8137984e0f167ab2560da22874033189234fb4L99-L103 试试 |
5bb31ad to
a6617c9
Compare
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## feature #42634 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 641 641
Lines 10891 10889 -2
Branches 2958 2957 -1
=========================================
- Hits 10891 10889 -2
☔ View full report in Codecov by Sentry. |
| ## zh-CN | ||
|
|
||
| 清除已选择的颜色。 | ||
| 清除已选择的颜色。可以使用受控 open 和 onClear 控制清除时关闭弹窗。 |
There was a problem hiding this comment.
demo 分两个吧,一个最基础的用法,一个配合 onClear 实现弹窗关闭。
There was a problem hiding this comment.
其实我觉得就只要最基础的用法就好了,配合 onClear 关闭没有必要。

[中文版模板 / Chinese template]
🤔 This is a ...
🔗 Related issue link
#42406
💡 Background and solution
应该让用户自己控制清除时是否关闭,用 open 受控配合 onClear 实现,或者加一个类似 closePopupWhenClear 属性。
📝 Changelog
☑️ Self-Check before Merge
🚀 Summary
🤖 Generated by Copilot at e45c232
Added a new
onClearprop to theColorPickercomponent to customize the behavior when clearing the color. Refactored the color picker panel props and the popup closing and color clearing logic. Updated the documentation and the test case accordingly.🔍 Walkthrough
🤖 Generated by Copilot at e45c232
onClearprop toColorPickerPropsinterface andColorPickercomponent to allow custom callback function when clearing the color (link, link, link, link, link, link, link)handleClearfunction inColorPickercomponent to setcolorClearedstate and callonClearprop function without passing boolean parameter (link)useEffecthook and import fromColorPickercomponent as popup closing logic is moved tohandleClearfunction (link, link)onClearprop inColorPickerPanelPropsinterface andColorPickerPanelcomponent to a function without parameters to matchColorPickerPropsandhandleClearfunction (link, link)onFormatChangeprop fromColorPickerPropstoColorPickerPanelPropsas it is more relevant for customizing color format (link, link, link, link)onChangeandonOpenChangeprops fromColorPickerPropstoColorPickerPanelPropsas they are more relevant for customizing color picker panel behavior (link, link)components/color-picker/__tests__/index.test.tsxas it is handled byhandleClearfunction (link)