@@ -128,6 +128,14 @@ const styles = (theme) => ({
128
128
marginTop : - 64 , // height of toolbar
129
129
position : 'absolute' ,
130
130
} ,
131
+ initialFocus : {
132
+ position : 'absolute' ,
133
+ top : 0 ,
134
+ left : 0 ,
135
+ width : theme . spacing ( 4 ) ,
136
+ height : theme . spacing ( 4 ) ,
137
+ pointerEvents : 'none' ,
138
+ } ,
131
139
} ) ;
132
140
133
141
function getDemoName ( location ) {
@@ -341,20 +349,12 @@ function Demo(props) {
341
349
342
350
const initialFocusRef = React . useRef ( null ) ;
343
351
function handleResetFocusClick ( ) {
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 ( ) ;
352
+ initialFocusRef . current . focusVisible ( ) ;
350
353
}
351
354
352
355
return (
353
356
< div className = { classes . root } >
354
- { /* We're actually preventing interaction here */ }
355
- { /* eslint-disable-next-line jsx-a11y/no-static-element-interactions */ }
356
357
< div
357
- aria-label = { t ( 'initialFocusLabel' ) }
358
358
className = { clsx ( classes . demo , {
359
359
[ classes . demoHiddenToolbar ] : demoOptions . hideToolbar ,
360
360
[ classes . demoBgOutlined ] : demoOptions . bg === 'outlined' ,
@@ -363,10 +363,13 @@ function Demo(props) {
363
363
} ) }
364
364
onMouseEnter = { handleDemoHover }
365
365
onMouseLeave = { handleDemoHover }
366
- onMouseDown = { handleDemoMouseDown }
367
- ref = { initialFocusRef }
368
- tabIndex = { - 1 }
369
366
>
367
+ < IconButton
368
+ aria-label = { t ( 'initialFocusLabel' ) }
369
+ className = { classes . initialFocus }
370
+ action = { initialFocusRef }
371
+ tabIndex = { - 1 }
372
+ />
370
373
< DemoSandboxed
371
374
key = { demoKey }
372
375
style = { demoSandboxedStyle }
0 commit comments