docbrown/app/javascript/packs/homePageFeedShortcuts.jsx
Robin Gagnon 27a3df7d73
A11y: Add keyboard navigation to article feed (#10468)
Co-authored-by: Andrew Bone <AndrewB05@gmail.com>
Co-authored-by: Nick Taylor <nick@dev.to>
2020-11-10 22:38:15 -05:00

29 lines
873 B
JavaScript

import { h, render, Fragment } from 'preact';
import { ListNavigation } from '../shared/components/useListNavigation';
import { KeyboardShortcuts } from '../shared/components/useKeyboardShortcuts';
document.addEventListener('DOMContentLoaded', () => {
const root = document.querySelector('#articles-list');
render(
<Fragment>
<KeyboardShortcuts
shortcuts={{
b: (event) => {
const article = event.target?.closest('.crayons-story');
if (!article) return;
article.querySelector('button[id^=article-save-button-]')?.click();
},
}}
/>
<ListNavigation
itemSelector=".crayons-story"
focusableSelector="a.crayons-story__hidden-navigation-link"
waterfallItemContainerSelector="div.paged-stories,div.substories"
/>
</Fragment>,
root,
);
});