Skip to content

Commit

Permalink
feat: improve accessibility (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
halcin authored Nov 4, 2023
1 parent 7947e22 commit cd4b92b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
3 changes: 3 additions & 0 deletions public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,6 @@ ul {
cursor: pointer;
color: var(--li-hover-color);
}
li[role=link]:focus {
outline: 2px solid black;
}
4 changes: 2 additions & 2 deletions public/css/themes/light.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
:root {
--primary-text-color: #263238;
--secondary-text-color: #607d8be5;
--secondary-text-color: black;
--primary-border-color: rgba(55, 71, 79, 0.1);
--faded-border-color: rgba(78, 99, 109, 0.1);
--head-paragraph-color: #90A4AE;
--head-paragraph-color: black;
--main-color: #304FFE;
--default-margin: 15px;
--avatar-border-color: #FFF;
Expand Down
24 changes: 18 additions & 6 deletions public/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,24 @@ function createChart(elementId, type = "bar", payload = {}) {
}
window.createChart = createChart;

function liPackageClick() {
function liPackageNavigateLink(e) {
const dataValue = this.getAttribute("data-value");
window.open(`https://www.npmjs.com/package/${dataValue}`, "_blank");
if (e.type === "click" || e.key === "Enter") {
const ref = e.target ?? e.srcElement;
if (ref) {
window.open(`https://www.npmjs.com/package/${dataValue}`, "_blank");
}
}
}

function nodeDepClick() {
function nodeDepNavigateLink(e) {
const dataValue = this.getAttribute("data-value");
window.open(`https://nodejs.org/dist/latest/docs/api/${dataValue}.html`, "_blank");
if (e.type === "click" || e.key === "Enter") {
const ref = e.target ?? e.srcElement;
if (ref) {
window.open(`https://nodejs.org/dist/latest/docs/api/${dataValue}.html`, "_blank");
}
}
}

document.addEventListener("DOMContentLoaded", () => {
Expand All @@ -117,12 +127,14 @@ document.addEventListener("DOMContentLoaded", () => {

const packagesList = document.querySelectorAll("ul.npm-packages-list li");
for (const liElement of packagesList) {
liElement.addEventListener("click", liPackageClick);
liElement.addEventListener("click", liPackageNavigateLink);
liElement.addEventListener("keydown", liPackageNavigateLink);
}

const nodeList = document.querySelectorAll("ul.node-list li");
for (const liElement of nodeList) {
liElement.addEventListener("click", nodeDepClick);
liElement.addEventListener("click", nodeDepNavigateLink);
liElement.addEventListener("keydown", nodeDepNavigateLink);
}

setTimeout(() => {
Expand Down
14 changes: 7 additions & 7 deletions views/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<div class="page">
<header>
<div class="logo">
<img src="[[=z.report_logo]]" />
<img src="[[=z.report_logo]]" alt="logo"/>
</div>
<h1>[[=z.report_title]]</h1>
<p>[[=z.report_date]]</p>
Expand Down Expand Up @@ -56,7 +56,7 @@ <h3><span>[[=z.npm_stats.packages_count.internal]]</span>Internal Dependencies</
<ul class="npm-packages-list">
[[ for (const [name, option] of Object.entries(z.npm_stats.packages)) { ]]
[[ if (!option.isThird) { ]]
<li data-value="[[=name]]">
<li data-value="[[=name]]" tabindex="0" role="link" class="link">
<p>[[=name]]</p>
</li>
[[ } ]]
Expand All @@ -71,7 +71,7 @@ <h3><span>[[=z.npm_stats.packages_count.external]]</span>Third-party Dependencie
<ul class="npm-packages-list">
[[ for (const [name, option] of Object.entries(z.npm_stats.packages)) { ]]
[[ if (option.isThird) { ]]
<li data-value="[[=name]]">
<li data-value="[[=name]]" tabindex="0" role="link" class="link">
<p>[[=name]]</p>
</li>
[[ } ]]
Expand All @@ -87,7 +87,7 @@ <h3><span>[[=z.npm_stats.deps.transitive.size]]</span>Transitive Dependencies</h
</div>
<ul class="npm-packages-list">
[[ for (const name of z.npm_stats.deps.transitive) { ]]
<li data-value="[[=name]]">
<li data-value="[[=name]]" tabindex="0" role="link" class="link">
<p>[[=name]]</p>
</li>
[[ } ]]
Expand All @@ -100,7 +100,7 @@ <h3><span>[[=z.npm_stats.deps.node.size]]</span>Node.js Core Dependencies</h3>
</div>
<ul class="node-list">
[[ for (const name of z.npm_stats.deps.node) { ]]
<li data-value="[[=name]]">
<li data-value="[[=name]]" tabindex="0" role="link" class="link">
<p>[[=name]]</p>
</li>
[[ } ]]
Expand Down Expand Up @@ -171,7 +171,7 @@ <h3><span>[[=z.git_stats.packages_count.internal]]</span>Internal Dependencies</
<ul class="npm-packages-list">
[[ for (const [name, option] of Object.entries(z.git_stats.packages)) { ]]
[[ if (!option.isThird) { ]]
<li data-value="[[=name]]">
<li data-value="[[=name]]" tabindex="0" role="link" class="link">
<p>[[=name]]</p>
</li>
[[ } ]]
Expand All @@ -186,7 +186,7 @@ <h3><span>[[=z.git_stats.packages_count.external]]</span>Third-party Dependencie
<ul class="npm-packages-list">
[[ for (const [name, option] of Object.entries(z.git_stats.packages)) { ]]
[[ if (option.isThird) { ]]
<li data-value="[[=name]]">
<li data-value="[[=name]]" tabindex="0" role="link" class="link">
<p>[[=name]]</p>
</li>
[[ } ]]
Expand Down

0 comments on commit cd4b92b

Please sign in to comment.