Skip to content

Commit

Permalink
Merge pull request #11 from bbeaudry/a11y-keyboard
Browse files Browse the repository at this point in the history
Make the symbols keyboard accessible
  • Loading branch information
samwho committed Apr 20, 2024
2 parents 62f4635 + 403667b commit 4f0120d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
</div>

<div class="symbols"></div>
</body>
</body>
12 changes: 11 additions & 1 deletion symbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,11 @@ function renderSymbols(searchTerm) {
}
const elem = document.createElement("div");
elem.classList = "symbol";
elem.tabIndex = 0;
elem.textContent = symbolInfo.display || symbolInfo.glyph;
elem.title = symbolInfo.name;
elem.addEventListener("click", () => {

const handleAction = () => {
if (elem.classList.contains("symbol-clicked")) return;

navigator.clipboard.writeText(symbolInfo.glyph);
Expand All @@ -283,6 +285,14 @@ function renderSymbols(searchTerm) {
elem.classList.remove("symbol-clicked");
elem.classList.add("symbol");
}, 1000);
}
elem.addEventListener("click", handleAction);

elem.addEventListener("keydown", (event) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
handleAction();
}
});
parent.appendChild(elem);
}
Expand Down

0 comments on commit 4f0120d

Please sign in to comment.