diff --git a/docs/src/modules/components/Demo.js b/docs/src/modules/components/Demo.js index 88abdd577be00d..c8eba87630d1ec 100644 --- a/docs/src/modules/components/Demo.js +++ b/docs/src/modules/components/Demo.js @@ -18,6 +18,7 @@ import MenuItem from '@material-ui/core/MenuItem'; import MoreVertIcon from '@material-ui/icons/MoreVert'; import Tooltip from '@material-ui/core/Tooltip'; import RefreshIcon from '@material-ui/icons/Refresh'; +import ResetFocusIcon from '@material-ui/icons/CenterFocusWeak'; import HighlightedCode from 'docs/src/modules/components/HighlightedCode'; import DemoSandboxed from 'docs/src/modules/components/DemoSandboxed'; import DemoLanguages from 'docs/src/modules/components/DemoLanguages'; @@ -61,6 +62,9 @@ const styles = (theme) => ({ [theme.breakpoints.up('sm')]: { borderRadius: theme.shape.borderRadius, }, + '&:focus': { + outline: `2px dashed ${theme.palette.text.primary}`, + }, }, /* Isolate the demo with an outline. */ demoBgOutlined: { @@ -335,18 +339,33 @@ function Demo(props) { const demoSourceId = useUniqueId(`demo-`); const openDemoSource = codeOpen || showPreview; + const initialFocusRef = React.useRef(null); + function handleResetFocusClick() { + initialFocusRef.current.focus(); + } + function handleDemoMouseDown(event) { + // Otherwise clicking any non-focusable element in the demo focuses the demo container + // which is surprising and not how the code would behave outside of this page + event.preventDefault(); + } + return (
+ {/* We're actually preventing interaction here */} + {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions */}
+ + + + +