@@ -12,18 +12,23 @@ interface RenderProps {
1212 dragging : boolean ;
1313}
1414
15- export interface HandleProps {
15+ export interface HandleProps
16+ extends Omit < React . HTMLAttributes < HTMLDivElement > , 'onFocus' | 'onMouseEnter' > {
1617 prefixCls : string ;
1718 style ?: React . CSSProperties ;
1819 value : number ;
1920 valueIndex : number ;
2021 dragging : boolean ;
2122 onStartMove : OnStartMove ;
2223 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 ;
2630 onChangeComplete ?: ( ) => void ;
31+ mock ?: boolean ;
2732}
2833
2934const Handle = React . forwardRef < HTMLDivElement , HandleProps > ( ( props , ref ) => {
@@ -37,6 +42,8 @@ const Handle = React.forwardRef<HTMLDivElement, HandleProps>((props, ref) => {
3742 dragging,
3843 onOffsetChange,
3944 onChangeComplete,
45+ onFocus,
46+ onMouseEnter,
4047 ...restProps
4148 } = props ;
4249 const {
@@ -63,6 +70,14 @@ const Handle = React.forwardRef<HTMLDivElement, HandleProps>((props, ref) => {
6370 }
6471 } ;
6572
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+
6681 // =========================== Keyboard ===========================
6782 const onKeyDown : React . KeyboardEventHandler < HTMLDivElement > = ( e ) => {
6883 if ( ! disabled && keyboard ) {
@@ -131,13 +146,36 @@ const Handle = React.forwardRef<HTMLDivElement, HandleProps>((props, ref) => {
131146 const positionStyle = getDirectionStyle ( direction , value , min , max ) ;
132147
133148 // ============================ 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+
134172 let handleNode = (
135173 < div
136174 ref = { ref }
137175 className = { cls (
138176 handlePrefixCls ,
139177 {
140- [ `${ handlePrefixCls } -${ valueIndex + 1 } ` ] : range ,
178+ [ `${ handlePrefixCls } -${ valueIndex + 1 } ` ] : valueIndex !== null && range ,
141179 [ `${ handlePrefixCls } -dragging` ] : dragging ,
142180 } ,
143181 classNames . handle ,
@@ -147,20 +185,7 @@ const Handle = React.forwardRef<HTMLDivElement, HandleProps>((props, ref) => {
147185 ...style ,
148186 ...styles . handle ,
149187 } }
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 }
164189 { ...restProps }
165190 />
166191 ) ;
0 commit comments