As the title says, I can't get my event to fire ON a div, only when I click on the page, in terms od accessibility, the user should be able to click on the esc key, directly, and not after clicking on the page.
This is how it is now on my div:
@keydown="handleEscKey($event)"
then my function
const handleEscKey = (event: KeyboardEvent) => {
emit("close")
}
This is another option, of how I have tried, that works. I have removed the @keydown event and used this:
const handleEscKey = (e: KeyboardEvent) => {
if (e.shiftKey) {
emit("close")
}
}
// Event listeners for "Esc" and "Enter" keys
onMounted(() => {
window.addEventListener('keydown', handleEscKey);
});
// Remove event listeners on component unmount
onBeforeUnmount(() => {
window.removeEventListener('keydown', handleEscKey);
});
Is there any answer of how to use @keydown event from vue?