Skip to content

Instantly share code, notes, and snippets.

@amberhinds
Created August 26, 2024 21:46
Show Gist options
  • Save amberhinds/897ba0ebca7dc14d50ddb5ec3fa749b8 to your computer and use it in GitHub Desktop.
Save amberhinds/897ba0ebca7dc14d50ddb5ec3fa749b8 to your computer and use it in GitHub Desktop.
Code that restores the ability for keyboard only users to trigger links and buttons on EDD checkout pages when using the Payment Elements experience.
/**
* Fix broken return key on checkout page.
*
* THIS IS A TEMPORARY FIX TILL EDD FIXES THE ISSUE.
*
* Edd has a stripe script that binds to the entire document and runs
* preventDefault on the return key. This is a temporary fix to allow
* the return key to work on the checkout page.
*/
export const checkoutFixBrokenReturnKey = () => {
if (!document.getElementById('edd_purchase_form')) {
return;
}
// find every a and button
const elements = document.querySelectorAll('a, button');
// loop through each element and check if it has anything bound to keyup or keydown
elements.forEach((element) => {
element.addEventListener('keydown', triggerClick);
});
function triggerClick(event) {
if (event.key === 'Enter') {
event.target.click();
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment