@@ -12,18 +12,23 @@ interface RenderProps {
12
12
dragging : boolean ;
13
13
}
14
14
15
- export interface HandleProps {
15
+ export interface HandleProps
16
+ extends Omit < React . HTMLAttributes < HTMLDivElement > , 'onFocus' | 'onMouseEnter' > {
16
17
prefixCls : string ;
17
18
style ?: React . CSSProperties ;
18
19
value : number ;
19
20
valueIndex : number ;
20
21
dragging : boolean ;
21
22
onStartMove : OnStartMove ;
22
23
onOffsetChange : ( value : number | 'min' | 'max' , valueIndex : number ) => void ;
23
- onFocus ?: ( e : React . FocusEvent < HTMLDivElement > ) => void ;
24
- onBlur ?: ( e : React . FocusEvent < HTMLDivElement > ) => void ;
25
- render ?: ( origin : React . ReactElement < HandleProps > , props : RenderProps ) => React . ReactElement ;
24
+ onFocus : ( e : React . FocusEvent < HTMLDivElement > , index : number ) => void ;
25
+ onMouseEnter : ( e : React . MouseEvent < HTMLDivElement > , index : number ) => void ;
26
+ render ?: (
27
+ origin : React . ReactElement < React . HTMLAttributes < HTMLDivElement > > ,
28
+ props : RenderProps ,
29
+ ) => React . ReactElement ;
26
30
onChangeComplete ?: ( ) => void ;
31
+ mock ?: boolean ;
27
32
}
28
33
29
34
const Handle = React . forwardRef < HTMLDivElement , HandleProps > ( ( props , ref ) => {
@@ -37,6 +42,8 @@ const Handle = React.forwardRef<HTMLDivElement, HandleProps>((props, ref) => {
37
42
dragging,
38
43
onOffsetChange,
39
44
onChangeComplete,
45
+ onFocus,
46
+ onMouseEnter,
40
47
...restProps
41
48
} = props ;
42
49
const {
@@ -63,6 +70,14 @@ const Handle = React.forwardRef<HTMLDivElement, HandleProps>((props, ref) => {
63
70
}
64
71
} ;
65
72
73
+ const onInternalFocus = ( e : React . FocusEvent < HTMLDivElement > ) => {
74
+ onFocus ?.( e , valueIndex ) ;
75
+ } ;
76
+
77
+ const onInternalMouseEnter = ( e : React . MouseEvent < HTMLDivElement > ) => {
78
+ onMouseEnter ( e , valueIndex ) ;
79
+ } ;
80
+
66
81
// =========================== Keyboard ===========================
67
82
const onKeyDown : React . KeyboardEventHandler < HTMLDivElement > = ( e ) => {
68
83
if ( ! disabled && keyboard ) {
@@ -131,13 +146,36 @@ const Handle = React.forwardRef<HTMLDivElement, HandleProps>((props, ref) => {
131
146
const positionStyle = getDirectionStyle ( direction , value , min , max ) ;
132
147
133
148
// ============================ Render ============================
149
+ let divProps : React . HtmlHTMLAttributes < HTMLDivElement > = { } ;
150
+
151
+ if ( valueIndex !== null ) {
152
+ divProps = {
153
+ tabIndex : disabled ? null : getIndex ( tabIndex , valueIndex ) ,
154
+ role : 'slider' ,
155
+ 'aria-valuemin' : min ,
156
+ 'aria-valuemax' : max ,
157
+ 'aria-valuenow' : value ,
158
+ 'aria-disabled' : disabled ,
159
+ 'aria-label' : getIndex ( ariaLabelForHandle , valueIndex ) ,
160
+ 'aria-labelledby' : getIndex ( ariaLabelledByForHandle , valueIndex ) ,
161
+ 'aria-valuetext' : getIndex ( ariaValueTextFormatterForHandle , valueIndex ) ?.( value ) ,
162
+ 'aria-orientation' : direction === 'ltr' || direction === 'rtl' ? 'horizontal' : 'vertical' ,
163
+ onMouseDown : onInternalStartMove ,
164
+ onTouchStart : onInternalStartMove ,
165
+ onFocus : onInternalFocus ,
166
+ onMouseEnter : onInternalMouseEnter ,
167
+ onKeyDown,
168
+ onKeyUp : handleKeyUp ,
169
+ } ;
170
+ }
171
+
134
172
let handleNode = (
135
173
< div
136
174
ref = { ref }
137
175
className = { cls (
138
176
handlePrefixCls ,
139
177
{
140
- [ `${ handlePrefixCls } -${ valueIndex + 1 } ` ] : range ,
178
+ [ `${ handlePrefixCls } -${ valueIndex + 1 } ` ] : valueIndex !== null && range ,
141
179
[ `${ handlePrefixCls } -dragging` ] : dragging ,
142
180
} ,
143
181
classNames . handle ,
@@ -147,20 +185,7 @@ const Handle = React.forwardRef<HTMLDivElement, HandleProps>((props, ref) => {
147
185
...style ,
148
186
...styles . handle ,
149
187
} }
150
- onMouseDown = { onInternalStartMove }
151
- onTouchStart = { onInternalStartMove }
152
- onKeyDown = { onKeyDown }
153
- onKeyUp = { handleKeyUp }
154
- tabIndex = { disabled ? null : getIndex ( tabIndex , valueIndex ) }
155
- role = "slider"
156
- aria-valuemin = { min }
157
- aria-valuemax = { max }
158
- aria-valuenow = { value }
159
- aria-disabled = { disabled }
160
- aria-label = { getIndex ( ariaLabelForHandle , valueIndex ) }
161
- aria-labelledby = { getIndex ( ariaLabelledByForHandle , valueIndex ) }
162
- aria-valuetext = { getIndex ( ariaValueTextFormatterForHandle , valueIndex ) ?.( value ) }
163
- aria-orientation = { direction === 'ltr' || direction === 'rtl' ? 'horizontal' : 'vertical' }
188
+ { ...divProps }
164
189
{ ...restProps }
165
190
/>
166
191
) ;
0 commit comments