Skip to content

Commit e125318

Browse files
authored
[docs] Allow default actions of nested elements (#20777)
1 parent 0cf29dd commit e125318

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

docs/src/modules/components/Demo.js

+15-12
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ const styles = (theme) => ({
128128
marginTop: -64, // height of toolbar
129129
position: 'absolute',
130130
},
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+
},
131139
});
132140

133141
function getDemoName(location) {
@@ -341,20 +349,12 @@ function Demo(props) {
341349

342350
const initialFocusRef = React.useRef(null);
343351
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();
350353
}
351354

352355
return (
353356
<div className={classes.root}>
354-
{/* We're actually preventing interaction here */}
355-
{/* eslint-disable-next-line jsx-a11y/no-static-element-interactions */}
356357
<div
357-
aria-label={t('initialFocusLabel')}
358358
className={clsx(classes.demo, {
359359
[classes.demoHiddenToolbar]: demoOptions.hideToolbar,
360360
[classes.demoBgOutlined]: demoOptions.bg === 'outlined',
@@ -363,10 +363,13 @@ function Demo(props) {
363363
})}
364364
onMouseEnter={handleDemoHover}
365365
onMouseLeave={handleDemoHover}
366-
onMouseDown={handleDemoMouseDown}
367-
ref={initialFocusRef}
368-
tabIndex={-1}
369366
>
367+
<IconButton
368+
aria-label={t('initialFocusLabel')}
369+
className={classes.initialFocus}
370+
action={initialFocusRef}
371+
tabIndex={-1}
372+
/>
370373
<DemoSandboxed
371374
key={demoKey}
372375
style={demoSandboxedStyle}

0 commit comments

Comments
 (0)