diff --git a/components/cascader/index.tsx b/components/cascader/index.tsx index e401c639319c..23f48cfd6659 100644 --- a/components/cascader/index.tsx +++ b/components/cascader/index.tsx @@ -286,6 +286,7 @@ const Cascader = React.forwardRef>((props, ref) showSuffixIcon, multiple, prefixCls, + componentName: 'Cascader', }); // ===================== Placement ===================== @@ -298,6 +299,8 @@ const Cascader = React.forwardRef>((props, ref) const mergedBuiltinPlacements = useBuiltinPlacements(builtinPlacements, popupOverflow); + const mergedAllowClear = allowClear === true ? { clearIcon } : allowClear; + // ==================== Render ===================== const renderNode = ( >((props, ref) direction={mergedDirection} placement={memoPlacement} notFoundContent={mergedNotFoundContent} - allowClear={allowClear} + allowClear={mergedAllowClear} showSearch={mergedShowSearch} expandIcon={mergedExpandIcon} suffixIcon={suffixIcon} removeIcon={removeIcon} - clearIcon={clearIcon} loadingIcon={loadingIcon} checkable={checkable} dropdownClassName={mergedDropdownClassName} diff --git a/components/date-picker/generatePicker/generateRangePicker.tsx b/components/date-picker/generatePicker/generateRangePicker.tsx index e2b0c748e446..f929dc0c824b 100644 --- a/components/date-picker/generatePicker/generateRangePicker.tsx +++ b/components/date-picker/generatePicker/generateRangePicker.tsx @@ -49,6 +49,7 @@ export default function generateRangePicker(generateConfig: GenerateCo popupClassName, dropdownClassName, status: customStatus, + clearIcon, ...restProps } = props; @@ -116,12 +117,10 @@ export default function generateRangePicker(generateConfig: GenerateCo dropdownAlign={transPlacement2DropdownAlign(direction, placement)} placeholder={getRangePlaceholder(locale, picker, placeholder)} suffixIcon={suffixNode} - clearIcon={} prevIcon={} nextIcon={} superPrevIcon={} superNextIcon={} - allowClear transitionName={`${rootPrefixCls}-slide-up`} {...restProps} {...additionalOverrideProps} @@ -142,6 +141,7 @@ export default function generateRangePicker(generateConfig: GenerateCo components={Components} direction={direction} dropdownClassName={classNames(hashId, popupClassName || dropdownClassName)} + allowClear={{ clearIcon: clearIcon ?? }} />, ); }); diff --git a/components/date-picker/generatePicker/generateSinglePicker.tsx b/components/date-picker/generatePicker/generateSinglePicker.tsx index 25ae6b7aef7e..c6b8073b2abf 100644 --- a/components/date-picker/generatePicker/generateSinglePicker.tsx +++ b/components/date-picker/generatePicker/generateSinglePicker.tsx @@ -54,6 +54,7 @@ export default function generatePicker(generateConfig: GenerateConfig< dropdownClassName, disabled: customDisabled, status: customStatus, + clearIcon, ...restProps } = props; @@ -139,12 +140,10 @@ export default function generatePicker(generateConfig: GenerateConfig< placeholder={getPlaceholder(locale, mergedPicker, placeholder)} suffixIcon={suffixNode} dropdownAlign={transPlacement2DropdownAlign(direction, placement)} - clearIcon={} prevIcon={} nextIcon={} superPrevIcon={} superNextIcon={} - allowClear transitionName={`${rootPrefixCls}-slide-up`} {...additionalProps} {...restProps} @@ -178,6 +177,7 @@ export default function generatePicker(generateConfig: GenerateConfig< rootClassName, popupClassName || dropdownClassName, )} + allowClear={{ clearIcon: clearIcon ?? }} />, ); }, diff --git a/components/select/index.tsx b/components/select/index.tsx index 98bdc4770d55..ac07efdafa91 100755 --- a/components/select/index.tsx +++ b/components/select/index.tsx @@ -99,6 +99,7 @@ const InternalSelect = < popupMatchSelectWidth, direction: propDirection, style, + allowClear, ...props }: SelectProps, ref: React.Ref, @@ -170,8 +171,11 @@ const InternalSelect = < showSuffixIcon, prefixCls, showArrow: props.showArrow, + componentName: 'Select', }); + const mergedAllowClear = allowClear === true ? { clearIcon } : allowClear; + const selectProps = omit(props as typeof props & { itemIcon: React.ReactNode }, [ 'suffixIcon', 'itemIcon', @@ -259,7 +263,7 @@ const InternalSelect = < suffixIcon={suffixIcon} menuItemSelectedIcon={itemIcon} removeIcon={removeIcon} - clearIcon={clearIcon} + allowClear={mergedAllowClear} notFoundContent={mergedNotFound} className={mergedClassName} getPopupContainer={getPopupContainer || getContextPopupContainer} diff --git a/components/select/utils/iconUtil.tsx b/components/select/utils/iconUtil.tsx index a5718b8a2339..d93dafe095f6 100644 --- a/components/select/utils/iconUtil.tsx +++ b/components/select/utils/iconUtil.tsx @@ -6,6 +6,7 @@ import LoadingOutlined from '@ant-design/icons/LoadingOutlined'; import SearchOutlined from '@ant-design/icons/SearchOutlined'; import type { ReactNode } from 'react'; import * as React from 'react'; +import warning from '../../_util/warning'; type RenderNode = React.ReactNode | ((props: any) => React.ReactNode); @@ -21,6 +22,7 @@ export default function getIcons({ showSuffixIcon, feedbackIcon, showArrow, + componentName, }: { suffixIcon?: React.ReactNode; clearIcon?: RenderNode; @@ -33,7 +35,16 @@ export default function getIcons({ prefixCls: string; showSuffixIcon?: boolean; showArrow?: boolean; + componentName: string; }) { + if (process.env.NODE_ENV !== 'production') { + warning( + !clearIcon, + componentName, + '`clearIcon` is deprecated, please use `allowClear={{ clearIcon: React.ReactNode }}` instead.', + ); + } + // Clear Icon const mergedClearIcon = clearIcon ?? ; diff --git a/components/time-picker/__tests__/__snapshots__/index.test.tsx.snap b/components/time-picker/__tests__/__snapshots__/index.test.tsx.snap index c06bfe119098..45137dee427d 100644 --- a/components/time-picker/__tests__/__snapshots__/index.test.tsx.snap +++ b/components/time-picker/__tests__/__snapshots__/index.test.tsx.snap @@ -41,6 +41,31 @@ exports[`TimePicker not render clean icon when allowClear is false 1`] = ` + + + + + `; diff --git a/components/tree-select/index.tsx b/components/tree-select/index.tsx index 2c88ca9639bd..7391c9993e37 100644 --- a/components/tree-select/index.tsx +++ b/components/tree-select/index.tsx @@ -106,6 +106,7 @@ const InternalTreeSelect = < builtinPlacements, dropdownMatchSelectWidth, popupMatchSelectWidth, + allowClear, ...props }: TreeSelectProps, ref: React.Ref, @@ -188,8 +189,11 @@ const InternalTreeSelect = < hasFeedback, feedbackIcon, prefixCls, + componentName: 'TreeSelect', }); + const mergedAllowClear = allowClear === true ? { clearIcon } : allowClear; + // ===================== Empty ===================== let mergedNotFound: React.ReactNode; if (notFoundContent !== undefined) { @@ -268,7 +272,7 @@ const InternalTreeSelect = < multiple={isMultiple} placement={memoizedPlacement} removeIcon={removeIcon} - clearIcon={clearIcon} + allowClear={mergedAllowClear} switcherIcon={renderSwitcherIcon} showTreeIcon={treeIcon as any} notFoundContent={mergedNotFound}