Created
June 11, 2019 17:43
-
-
Save ryanflorence/16e8e5e9ec58792f3a396d2139694e64 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createAriaLink(element) { | |
const href = element.getAttribute("data-aria-href") | |
element.setAttribute("role", "link") | |
element.setAttribute("tabindex", 0) | |
element.addEventListener("click", triggerAction) | |
element.addEventListener("keydown", keydownHandler) | |
onRemove(element, destroy) | |
function keydownHandler(event) { | |
if (event.key === "Enter") { | |
triggerAction(event) | |
} | |
} | |
function triggerAction(event) { | |
event.preventDefault() | |
event.stopPropagation() | |
goToLink() | |
} | |
function goToLink() { | |
window.location.href = href | |
} | |
function destroy() { | |
element.removeEventListener("click", triggerAction) | |
element.removeEventListener("keydown", keydownHandler) | |
} | |
} | |
link = createAriaLink(element) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment