Create focus.js

This commit is contained in:
Anirudh Sevugan 2025-08-03 20:32:31 -05:00 committed by GitHub
parent b5fdd87dd4
commit 8cd926e0df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -0,0 +1,19 @@
document.addEventListener("keydown", function(e) {
if (e.key === "Enter") {
const focused = document.activeElement;
if (focused) {
// If focus is on a button, just click it
if (focused.tagName === "BUTTON") {
focused.click();
e.preventDefault();
}
// If focus is on a text input or checkbox, find the highlighted button and click it
else if (focused.tagName === "INPUT") {
// You can define which button to click here.
// For example, the button with id="myButton"
focused.focus();
}
}
}
});