You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte/site/src/utils/events.js

20 lines
364 B

export function keyEvent(code) {
return function (node, callback) {
node.addEventListener('keydown', handleKeydown);
function handleKeydown(event) {
if (event.keyCode === code) {
callback.call(this, event);
}
}
return {
destroy() {
node.removeEventListener('keydown', handleKeydown);
}
};
};
}
export const enter = keyEvent(13);