-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
HH: Andrico Karoulla
committed
Jan 21, 2021
1 parent
1e29aed
commit d5d4a47
Showing
5 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
packages/ra-ui-materialui/src/button/SkipNavigationButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import React from 'react'; | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
import Button from './Button'; | ||
import { useTranslate } from 'ra-core'; | ||
import classnames from 'classnames'; | ||
|
||
function skipToContent() { | ||
const element = document.getElementById('main-content'); | ||
|
||
if (!element) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
console.warn( | ||
'No element with id "main-content" was found. Ensure the element that contains your main content has an id of "main-content".' | ||
); | ||
} | ||
|
||
return; | ||
} | ||
|
||
element.setAttribute('tabIndex', '-1'); | ||
element.focus(); | ||
element.blur(); | ||
element.removeAttribute('tabIndex'); | ||
} | ||
|
||
const useStyles = makeStyles(theme => ({ | ||
skipToContentButton: { | ||
position: 'fixed', | ||
padding: theme.spacing(1), | ||
backgroundColor: theme.palette.background.default, | ||
color: theme.palette.getContrastText(theme.palette.background.default), | ||
transition: theme.transitions.create(['top', 'opacity'], { | ||
easing: theme.transitions.easing.easeIn, | ||
duration: theme.transitions.duration.leavingScreen, | ||
}), | ||
left: theme.spacing(2), | ||
top: theme.spacing(-10), | ||
zIndex: 5000, | ||
'&:hover': { | ||
opacity: 0.8, | ||
backgroundColor: theme.palette.background.default, | ||
}, | ||
'&:focus': { | ||
top: theme.spacing(2), | ||
transition: theme.transitions.create(['top', 'opacity'], { | ||
easing: theme.transitions.easing.easeOut, | ||
duration: theme.transitions.duration.enteringScreen, | ||
}), | ||
}, | ||
}, | ||
})); | ||
|
||
function SkipNavigationButton() { | ||
const classes = useStyles(); | ||
const translate = useTranslate(); | ||
|
||
return ( | ||
<Button | ||
onClick={skipToContent} | ||
className={classnames( | ||
classes.skipToContentButton, | ||
'skip-nav-button' | ||
)} | ||
label={translate('ra.navigation.skip_nav')} | ||
variant="contained" | ||
/> | ||
); | ||
} | ||
|
||
export default SkipNavigationButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters