1
- import findDOMNode from 'rc-util/lib/Dom/findDOMNode ' ;
1
+ import classNames from 'classnames ' ;
2
2
import useMergedState from 'rc-util/lib/hooks/useMergedState' ;
3
3
import KeyCode from 'rc-util/lib/KeyCode' ;
4
4
import pickAttrs from 'rc-util/lib/pickAttrs' ;
5
5
import React from 'react' ;
6
- import classNames from 'classnames' ;
7
-
8
6
import type { StarProps } from './Star' ;
9
7
import Star from './Star' ;
10
8
import useRefs from './useRefs' ;
@@ -41,8 +39,6 @@ function Rate(props: RateProps, ref: React.Ref<RateRef>) {
41
39
// Base
42
40
prefixCls = 'rc-rate' ,
43
41
className,
44
- style,
45
- id,
46
42
47
43
// Value
48
44
defaultValue,
@@ -67,7 +63,6 @@ function Rate(props: RateProps, ref: React.Ref<RateRef>) {
67
63
onFocus,
68
64
onBlur,
69
65
onKeyDown,
70
- onMouseEnter,
71
66
onMouseLeave,
72
67
73
68
...restProps
@@ -102,7 +97,7 @@ function Rate(props: RateProps, ref: React.Ref<RateRef>) {
102
97
const reverse = direction === 'rtl' ;
103
98
let starValue = index + 1 ;
104
99
if ( allowHalf ) {
105
- const starEle = findDOMNode < HTMLElement > ( getStarRef ( index ) ) ;
100
+ const starEle = getStarRef ( index ) ;
106
101
const leftDis = getOffsetLeft ( starEle ) ;
107
102
const width = starEle . clientWidth ;
108
103
if ( reverse && x - leftDis > width / 2 ) {
@@ -219,8 +214,9 @@ function Rate(props: RateProps, ref: React.Ref<RateRef>) {
219
214
220
215
// =========================== Render ===========================
221
216
// >>> Star
222
- const starNodes = new Array ( count ) . fill ( 0 ) . map ( ( _ , index ) => {
223
- return (
217
+ const starNodes = new Array ( count )
218
+ . fill ( 0 )
219
+ . map ( ( item , index ) => (
224
220
< Star
225
221
ref = { setStarRef ( index ) }
226
222
index = { index }
@@ -231,32 +227,30 @@ function Rate(props: RateProps, ref: React.Ref<RateRef>) {
231
227
value = { hoverValue === null ? value : hoverValue }
232
228
onClick = { onClick }
233
229
onHover = { onHover }
234
- key = { index }
230
+ key = { item || index }
235
231
character = { character }
236
232
characterRender = { characterRender }
237
233
focused = { focused }
238
234
/>
239
- ) ;
235
+ ) ) ;
236
+
237
+ const classString = classNames ( prefixCls , className , {
238
+ [ `${ prefixCls } -disabled` ] : disabled ,
239
+ [ `${ prefixCls } -rtl` ] : direction === 'rtl' ,
240
240
} ) ;
241
241
242
242
// >>> Node
243
243
return (
244
244
< ul
245
- className = { classNames ( prefixCls , className , {
246
- [ `${ prefixCls } -disabled` ] : disabled ,
247
- [ `${ prefixCls } -rtl` ] : direction === 'rtl' ,
248
- } ) }
249
- style = { style }
250
- id = { id }
251
- onMouseEnter = { onMouseEnter }
245
+ className = { classString }
252
246
onMouseLeave = { onMouseLeaveCallback }
253
247
tabIndex = { disabled ? - 1 : tabIndex }
254
248
onFocus = { disabled ? null : onInternalFocus }
255
249
onBlur = { disabled ? null : onInternalBlur }
256
250
onKeyDown = { disabled ? null : onInternalKeyDown }
257
251
ref = { rateRef }
258
252
role = "radiogroup"
259
- { ...pickAttrs ( restProps , { aria : true , data : true } ) }
253
+ { ...pickAttrs ( restProps , { aria : true , data : true , attr : true } ) }
260
254
>
261
255
{ starNodes }
262
256
</ ul >
0 commit comments