Skip to content

Instantly share code, notes, and snippets.

@dimasmds
Last active September 20, 2020 08:21
Show Gist options
  • Select an option

  • Save dimasmds/abb7bad7d08b69e8bf24e833fb9f5e98 to your computer and use it in GitHub Desktop.

Select an option

Save dimasmds/abb7bad7d08b69e8bf24e833fb9f5e98 to your computer and use it in GitHub Desktop.
Skip Content using Button
import UrlParser from '../routes/url-parser';
import routes from '../routes';
class App {
constructor({ content, skipLink }) {
this._content = content;
this._skipLink = skipLink;
this._initialAppShell();
}
_initialAppShell() {
this._initialDrawer();
this._initialSkipLink();
}
async renderPage() {
const url = UrlParser.parseActiveUrlWithCombiner();
const page = routes[url];
this._content.innerHTML = await page.render();
await page.afterRender();
}
_initialDrawer() {
const appBarElement = document.querySelector('app-bar');
this._content.addEventListener('click', () => {
appBarElement._isDrawerOpen = false;
});
}
_initialSkipLink() {
this._skipLink.addEventListener('click', () => {
this._content.tabIndex = 0;
this._content.focus();
});
}
}
export default App;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#606e6b"/>
<meta name="description" content="Free Restaurant Catalogue for You">
<title>Hunger Apps</title>
<link rel="manifest" href="./manifest.json">
<link rel="icon" href="./favicon.png">
<link href="https://fonts.googleapis.com/css2?family=Maven+Pro:wght@400;500;600;700&display=swap" rel="stylesheet">
</head>
<body>
<button id="skipLink" class="skip-link">Skip to Content</button>
<app-bar></app-bar>
<main id="mainContent"></main>
<foot-bar></foot-bar>
<script src="./vendor/webcomponents-loader.js"></script>
</body>
</html>
// Main dependencies
import 'regenerator-runtime';
// Components Inject
import './presentations/components';
// Style Inject
import '../styles/main.scss';
import App from './presentations/App';
import registerSW from './utils/register-sw';
const app = new App({
content: document.querySelector('#mainContent'),
skipLink: document.querySelector('#skipLink'),
});
window.addEventListener('DOMContentLoaded', async () => {
await app.renderPage();
await registerSW();
});
window.addEventListener('hashchange', async () => {
await app.renderPage();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment