Skip to content

Add skip link for better keyboard accessibility Fix-#3084 #3101

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

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
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
35 changes: 35 additions & 0 deletions client/components/SkipLink.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React, { useState } from 'react';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import { useTranslation } from 'react-i18next';

const SkipLink = ({ targetId, text }) => {
const [focus, setFocus] = useState(false);
const { t } = useTranslation();
const handleFocus = () => {
setFocus(true);
};

const handleBlur = () => {
setFocus(false);
};
const linkClasses = classNames('skip_link', { focus });

return (
<a
href={`#${targetId}`}
className={linkClasses}
onFocus={handleFocus}
onBlur={handleBlur}
>
{t(`SkipLink.${text}`)}
</a>
);
};

SkipLink.propTypes = {
targetId: PropTypes.string.isRequired,
text: PropTypes.string.isRequired
};

export default SkipLink;
2 changes: 2 additions & 0 deletions client/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Routing from './routes';
import ThemeProvider from './modules/App/components/ThemeProvider';
import Loader from './modules/App/components/loader';
import './i18n';
import SkipLink from './components/SkipLink';

require('./styles/main.scss');

Expand All @@ -23,6 +24,7 @@ const App = () => (
<Provider store={store}>
<ThemeProvider>
<Router history={browserHistory}>
<SkipLink targetId="play-sketch" text="PlaySketch" />
<Routing />
</Router>
</ThemeProvider>
Expand Down
1 change: 1 addition & 0 deletions client/modules/IDE/components/Header/Toolbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const Toolbar = (props) => {
</button>
<button
className={playButtonClass}
id="play-sketch"
onClick={() => {
props.syncFileContent();
dispatch(startSketch());
Expand Down
29 changes: 29 additions & 0 deletions client/styles/components/_skip-link.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@use "sass:math";

.skip_link {
left: 50%;
transform: translateX(-50%);
top: 1%;
clip: rect(0 0 0 0);
overflow: hidden;
position: absolute;
border-radius: 3px;
white-space: nowrap;
vertical-align: middle;
background-color: transparent;
font-size: #{math.div(12, $base-font-size)}rem;
line-height: #{math.div(50, $base-font-size)}rem;line-height: 11px;
padding: #{math.div(10, $base-font-size)}rem #{math.div(10, $base-font-size)}rem;
background: #fff;
display: inline-block;
text-transform: uppercase;
transition: none;
z-index: 5;
}

.skip_link:focus {
clip: auto;
overflow: visible;
width: auto;
height: auto;
}
1 change: 1 addition & 0 deletions client/styles/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
@import 'components/collection';
@import 'components/collection-create';
@import 'components/quick-add';
@import 'components/skip-link';

@import 'layout/dashboard';
@import 'layout/ide';
3 changes: 3 additions & 0 deletions translations/locales/en-US/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -621,5 +621,8 @@
"PrivacyPolicy": "Privacy Policy",
"TermsOfUse": "Terms of Use",
"CodeOfConduct": "Code of Conduct"
},
"SkipLink": {
"PlaySketch": "Skip to Play Sketch"
}
}
Loading