refactor: extract utility

This commit is contained in:
Carlos Valente
2024-12-31 10:57:42 +01:00
committed by Carlos Valente
parent 760de608e3
commit 44f65b2fcc
2 changed files with 9 additions and 8 deletions
+8
View File
@@ -7,3 +7,11 @@ export function isKeyEnter<T>(event: KeyboardEvent<T>): boolean {
export function isKeyEscape<T>(event: KeyboardEvent<T>): boolean {
return event.key === 'Escape';
}
export function preventEscape<T>(event: KeyboardEvent<T>, callback?: () => void): void {
if (isKeyEscape(event)) {
event.preventDefault();
event.stopPropagation();
callback?.();
}
}