@@ -4,7 +4,7 @@ import React from 'react';
44import PropTypes from 'prop-types' ;
55import clsx from 'clsx' ;
66import { useTheme , withStyles , fade , lighten } from '@material-ui/core/styles' ;
7- import { useForkRef , ownerWindow } from '@material-ui/core/utils' ;
7+ import { useForkRef , ownerWindow , useIsFocusVisible } from '@material-ui/core/utils' ;
88import { chainPropTypes } from '@material-ui/utils' ;
99import ValueLabel from './ValueLabel' ;
1010
@@ -163,9 +163,9 @@ export const styles = theme => ({
163163 marginRight : 20 ,
164164 } ,
165165 } ,
166- /* Styles applied to the root element if `orientation="vertical"`. */
166+ /* Pseudo-class applied to the root element if `orientation="vertical"`. */
167167 vertical : { } ,
168- /* Styles applied to the root element if `disabled={true}`. */
168+ /* Pseudo-class applied to the root element if `disabled={true}`. */
169169 disabled : { } ,
170170 /* Styles applied to the rail element. */
171171 rail : {
@@ -174,7 +174,7 @@ export const styles = theme => ({
174174 height : 2 ,
175175 borderRadius : 1 ,
176176 backgroundColor : 'currentColor' ,
177- opacity : 0.24 ,
177+ opacity : 0.38 ,
178178 '$vertical &' : {
179179 height : '100%' ,
180180 width : 2 ,
@@ -207,8 +207,11 @@ export const styles = theme => ({
207207 transition : theme . transitions . create ( [ 'box-shadow' ] , {
208208 duration : theme . transitions . duration . shortest ,
209209 } ) ,
210- '&:focus ,&:hover' : {
210+ '&$focusVisible ,&:hover' : {
211211 boxShadow : `0px 0px 0px 8px ${ fade ( theme . palette . primary . main , 0.16 ) } ` ,
212+ '@media (hover: none)' : {
213+ boxShadow : 'none' ,
214+ } ,
212215 } ,
213216 '&$active' : {
214217 boxShadow : `0px 0px 0px 14px ${ fade ( theme . palette . primary . main , 0.16 ) } ` ,
@@ -219,7 +222,7 @@ export const styles = theme => ({
219222 height : 8 ,
220223 marginLeft : - 4 ,
221224 marginTop : - 3 ,
222- '&:focus,&: hover' : {
225+ '&:hover' : {
223226 boxShadow : 'none' ,
224227 } ,
225228 } ,
@@ -232,8 +235,10 @@ export const styles = theme => ({
232235 marginBottom : - 4 ,
233236 } ,
234237 } ,
235- /* Styles applied to the thumb element if it's active. */
238+ /* Pseudo-class applied to the thumb element if it's active. */
236239 active : { } ,
240+ /* Pseudo-class applied to the thumb element if keyboard focused. */
241+ focusVisible : { } ,
237242 /* Styles applied to the thumb label element. */
238243 valueLabel : { } ,
239244 /* Styles applied to the mark element. */
@@ -320,11 +325,21 @@ const Slider = React.forwardRef(function Slider(props, ref) {
320325 source : valueDerived , // Keep track of the input value to leverage immutable state comparison.
321326 } ;
322327
328+ const { isFocusVisible, onBlurVisible, ref : focusVisibleRef } = useIsFocusVisible ( ) ;
329+ const [ focusVisible , setFocusVisible ] = React . useState ( - 1 ) ;
330+
323331 const handleFocus = useEventCallback ( event => {
324332 const index = Number ( event . currentTarget . getAttribute ( 'data-index' ) ) ;
333+ if ( isFocusVisible ( event ) ) {
334+ setFocusVisible ( index ) ;
335+ }
325336 setOpen ( index ) ;
326337 } ) ;
327338 const handleBlur = useEventCallback ( ( ) => {
339+ if ( focusVisible !== - 1 ) {
340+ setFocusVisible ( - 1 ) ;
341+ onBlurVisible ( ) ;
342+ }
328343 setOpen ( - 1 ) ;
329344 } ) ;
330345 const handleMouseOver = useEventCallback ( event => {
@@ -412,7 +427,8 @@ const Slider = React.forwardRef(function Slider(props, ref) {
412427 } ) ;
413428
414429 const sliderRef = React . useRef ( ) ;
415- const handleRef = useForkRef ( sliderRef , ref ) ;
430+ const handleFocusRef = useForkRef ( focusVisibleRef , sliderRef ) ;
431+ const handleRef = useForkRef ( ref , handleFocusRef ) ;
416432 const previousIndex = React . useRef ( ) ;
417433 let axis = orientation ;
418434 if ( theme . direction === 'rtl' && orientation === 'horizontal' ) {
@@ -663,6 +679,7 @@ const Slider = React.forwardRef(function Slider(props, ref) {
663679 < ThumbComponent
664680 className = { clsx ( classes . thumb , {
665681 [ classes . active ] : active === index ,
682+ [ classes . focusVisible ] : focusVisible === index ,
666683 } ) }
667684 tabIndex = { disabled ? null : 0 }
668685 role = "slider"
@@ -690,11 +707,11 @@ const Slider = React.forwardRef(function Slider(props, ref) {
690707
691708Slider . propTypes = {
692709 /**
693- * An alternative to `aria-labelledby` .
710+ * The label of the slider .
694711 */
695712 'aria-label' : PropTypes . string ,
696713 /**
697- * Refers to the element containing the name of the slider.
714+ * The id of the element containing a label for the slider.
698715 */
699716 'aria-labelledby' : PropTypes . string ,
700717 /**
0 commit comments