Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[docs] Revert to (improved) focusable container
  • Loading branch information
eps1lon committed Apr 24, 2020
commit 9bbd0bcffb1a6779fa8857dcc7cc2ebcbfc2d267
30 changes: 15 additions & 15 deletions docs/src/modules/components/Demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,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: {
Expand Down Expand Up @@ -125,14 +128,6 @@ const styles = (theme) => ({
marginTop: -64, // height of toolbar
position: 'absolute',
},
initialFocus: {
position: 'absolute',
top: 0,
left: 0,
width: theme.spacing(4),
height: theme.spacing(4),
pointerEvents: 'none',
},
});

function getDemoName(location) {
Expand Down Expand Up @@ -346,12 +341,20 @@ function Demo(props) {

const initialFocusRef = React.useRef(null);
function handleResetFocusClick() {
initialFocusRef.current.focusVisible();
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();
Copy link
Member

@oliviertassinari oliviertassinari Apr 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have discovered a negative side effect. Developers will no longer be able to copy and paste from the demos. For instance, try copy and paste the output of the playground in your project (my use case for making a new demo with #20755)

https://master--material-ui.netlify.app/components/popover/#anchor-playground

=> we can't.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going back to the original implementation.

}

return (
<div className={classes.root}>
{/* We're actually preventing interaction here */}
{/* eslint-disable-next-line jsx-a11y/no-static-element-interactions */}
<div
aria-label={t('initialFocusLabel')}
className={clsx(classes.demo, {
[classes.demoHiddenToolbar]: demoOptions.hideToolbar,
[classes.demoBgOutlined]: demoOptions.bg === 'outlined',
Expand All @@ -360,13 +363,10 @@ function Demo(props) {
})}
onMouseEnter={handleDemoHover}
onMouseLeave={handleDemoHover}
onMouseDown={handleDemoMouseDown}
ref={initialFocusRef}
tabIndex={-1}
>
<IconButton
aria-label={t('initialFocusLabel')}
className={classes.initialFocus}
action={initialFocusRef}
tabIndex={-1}
/>
<DemoSandboxed
key={demoKey}
style={demoSandboxedStyle}
Expand Down