Skip to content

Commit 9241c45

Browse files
committed
[docs] Revert to (improved) focusable container
1 parent 194b3e9 commit 9241c45

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

docs/src/modules/components/Demo.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ const styles = (theme) => ({
6262
[theme.breakpoints.up('sm')]: {
6363
borderRadius: theme.shape.borderRadius,
6464
},
65+
'&:focus': {
66+
outline: `2px sollid ${theme.palette.text.primary}`,
67+
},
6568
},
6669
/* Isolate the demo with an outline. */
6770
demoBgOutlined: {
@@ -125,14 +128,6 @@ const styles = (theme) => ({
125128
marginTop: -64, // height of toolbar
126129
position: 'absolute',
127130
},
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-
},
136131
});
137132

138133
function getDemoName(location) {
@@ -346,12 +341,20 @@ function Demo(props) {
346341

347342
const initialFocusRef = React.useRef(null);
348343
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();
350350
}
351351

352352
return (
353353
<div className={classes.root}>
354+
{/* We're actually preventing interaction here */}
355+
{/* eslint-disable-next-line jsx-a11y/no-static-element-interactions */}
354356
<div
357+
aria-label={t('initialFocusLabel')}
355358
className={clsx(classes.demo, {
356359
[classes.demoHiddenToolbar]: demoOptions.hideToolbar,
357360
[classes.demoBgOutlined]: demoOptions.bg === 'outlined',
@@ -360,13 +363,10 @@ function Demo(props) {
360363
})}
361364
onMouseEnter={handleDemoHover}
362365
onMouseLeave={handleDemoHover}
366+
onMouseDown={handleDemoMouseDown}
367+
ref={initialFocusRef}
368+
tabIndex={-1}
363369
>
364-
<IconButton
365-
aria-label={t('initialFocusLabel')}
366-
className={classes.initialFocus}
367-
action={initialFocusRef}
368-
tabIndex={-1}
369-
/>
370370
<DemoSandboxed
371371
key={demoKey}
372372
style={demoSandboxedStyle}

0 commit comments

Comments
 (0)