ant-design/components/_util/getAllowClear.tsx
MadCcc 1cb644d476
fix: color picker controlled value (#47816)
* fix: fix control value not show in dom

* chore: update title

* add test case

* change test title

* fix: cleared color should change after controlled value changed

* chore: code clean

* test: change test

* comment

* fix: should respect empty string

* test: add test case

* chore: update demo

---------

Co-authored-by: tanghui <yoyo837@hotmail.com>
Co-authored-by: afc163 <afc163@gmail.com>
Co-authored-by: lijianan <574980606@qq.com>
2024-03-25 20:10:47 +08:00

21 lines
580 B
TypeScript

import React from 'react';
import CloseCircleFilled from '@ant-design/icons/CloseCircleFilled';
import type { BaseInputProps } from 'rc-input/lib/interface';
export type AllowClear = BaseInputProps['allowClear'];
const getAllowClear = (allowClear: AllowClear): AllowClear => {
let mergedAllowClear: AllowClear;
if (typeof allowClear === 'object' && allowClear?.clearIcon) {
mergedAllowClear = allowClear;
} else if (allowClear) {
mergedAllowClear = {
clearIcon: <CloseCircleFilled />,
};
}
return mergedAllowClear;
};
export default getAllowClear;