@@ -62,6 +62,9 @@ const styles = (theme) => ({
62
62
[ theme . breakpoints . up ( 'sm' ) ] : {
63
63
borderRadius : theme . shape . borderRadius ,
64
64
} ,
65
+ '&:focus' : {
66
+ outline : `2px sollid ${ theme . palette . text . primary } ` ,
67
+ } ,
65
68
} ,
66
69
/* Isolate the demo with an outline. */
67
70
demoBgOutlined : {
@@ -125,14 +128,6 @@ const styles = (theme) => ({
125
128
marginTop : - 64 , // height of toolbar
126
129
position : 'absolute' ,
127
130
} ,
128
- initialFocus : {
129
- position : 'absolute' ,
130
- top : 0 ,
131
- left : 0 ,
132
- width : theme . spacing ( 4 ) ,
133
- height : theme . spacing ( 4 ) ,
134
- pointerEvents : 'none' ,
135
- } ,
136
131
} ) ;
137
132
138
133
function getDemoName ( location ) {
@@ -346,12 +341,20 @@ function Demo(props) {
346
341
347
342
const initialFocusRef = React . useRef ( null ) ;
348
343
function handleResetFocusClick ( ) {
349
- initialFocusRef . current . focusVisible ( ) ;
344
+ initialFocusRef . current . focus ( ) ;
345
+ }
346
+ function handleDemoMouseDown ( event ) {
347
+ // Otherwise clicking any non-focusable element in the demo focuses the demo container
348
+ // which is surprising and not how the code would behave outside of this page
349
+ event . preventDefault ( ) ;
350
350
}
351
351
352
352
return (
353
353
< div className = { classes . root } >
354
+ { /* We're actually preventing interaction here */ }
355
+ { /* eslint-disable-next-line jsx-a11y/no-static-element-interactions */ }
354
356
< div
357
+ aria-label = { t ( 'initialFocusLabel' ) }
355
358
className = { clsx ( classes . demo , {
356
359
[ classes . demoHiddenToolbar ] : demoOptions . hideToolbar ,
357
360
[ classes . demoBgOutlined ] : demoOptions . bg === 'outlined' ,
@@ -360,13 +363,10 @@ function Demo(props) {
360
363
} ) }
361
364
onMouseEnter = { handleDemoHover }
362
365
onMouseLeave = { handleDemoHover }
366
+ onMouseDown = { handleDemoMouseDown }
367
+ ref = { initialFocusRef }
368
+ tabIndex = { - 1 }
363
369
>
364
- < IconButton
365
- aria-label = { t ( 'initialFocusLabel' ) }
366
- className = { classes . initialFocus }
367
- action = { initialFocusRef }
368
- tabIndex = { - 1 }
369
- />
370
370
< DemoSandboxed
371
371
key = { demoKey }
372
372
style = { demoSandboxedStyle }
0 commit comments