@@ -33,13 +33,14 @@ const RateIcon: React.FC<RateIconProps> = ({ icon, ...props }) => {
33
33
const Rate = React . forwardRef < HTMLDivElement , RateProps > ( ( originalProps , ref ) => {
34
34
const props = useDefaultProps < RateProps > ( originalProps , rateDefaultProps ) ;
35
35
36
- const { allowHalf, color, count, disabled, gap, showText, size, icon, className, style, onChange, texts } = props ;
36
+ const { allowHalf, color, count, disabled, gap, showText, size, icon, className, style, onChange, texts, clearable } =
37
+ props ;
37
38
const [ locale , t ] = useLocaleReceiver ( 'rate' ) ;
38
39
39
40
const displayTexts = texts . length ? texts : t ( locale . rateText ) ;
40
41
41
42
const { classPrefix } = useConfig ( ) ;
42
- const [ starValue = 0 , setStarValue ] = useControlled ( props , 'value' , onChange ) ;
43
+ const [ starValue , setStarValue ] = useControlled ( props , 'value' , onChange ) ;
43
44
44
45
const [ hoverValue , setHoverValue ] = useState < number | undefined > ( undefined ) ;
45
46
const displayValue = hoverValue || starValue ;
@@ -86,7 +87,14 @@ const Rate = React.forwardRef<HTMLDivElement, RateProps>((originalProps, ref) =>
86
87
if ( disabled ) {
87
88
return ;
88
89
}
89
- setStarValue ( getStarValue ( event , index ) ) ;
90
+
91
+ let value = getStarValue ( event , index ) ;
92
+ if ( clearable && value === starValue ) {
93
+ value = 0 ;
94
+ setHoverValue ( undefined ) ;
95
+ }
96
+
97
+ setStarValue ( value ) ;
90
98
} ;
91
99
92
100
const getStarCls = ( index : number ) => {
0 commit comments