Skip to content

Commit

Permalink
a11y: Make "Link" and "Source" keyboard-accessible
Browse files Browse the repository at this point in the history
  • Loading branch information
tnajdek committed May 31, 2024
1 parent b5c18cd commit 070197c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion frontend/scss/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ h2 {
cursor: pointer;
text-decoration: underline;

li:hover & {
li:hover &,
li:focus-within & {
display: inline;
}
}
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ const App = () => {
}, []);

const handleStyleItemLinkClick = useCallback((e) => {
if (e.type === 'keydown' && !(e.key == 'Enter' || e.key == ' ')) {
return;
}
e.preventDefault();
const styleName = e.target.closest('li').dataset.name;
if (styleName) {
dispatch({ type: 'QUERY', query: { search: `id:${styleName}` } });
Expand Down Expand Up @@ -488,7 +492,7 @@ const StyleItem = ({ style, onMouseEnter, onMouseLeave, onLinkClick }) => {
{style.title}
</a>
<span className="metadata">({style.updated})</span>
<a className="style-individual-link" onClick={ onLinkClick }>
<a className="style-individual-link" tabIndex={ 0 } onClick={ onLinkClick } onKeyDown={ onLinkClick }>
Link
</a>
<a className="style-view-source" href={style.href + '?source=1'}>
Expand Down

0 comments on commit 070197c

Please sign in to comment.