Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Allow default actions of nested elements #20777

Merged
Merged
Changes from all commits
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
27 changes: 15 additions & 12 deletions docs/src/modules/components/Demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ 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 @@ -341,20 +349,12 @@ function Demo(props) {

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();
initialFocusRef.current.focusVisible();
}

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 @@ -363,10 +363,13 @@ 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