diff --git a/app/javascript/retrospring/features/answerbox/comment/hotkey.ts b/app/javascript/retrospring/features/answerbox/comment/hotkey.ts index 0e15dd7f..e56cb0e9 100644 --- a/app/javascript/retrospring/features/answerbox/comment/hotkey.ts +++ b/app/javascript/retrospring/features/answerbox/comment/hotkey.ts @@ -1,7 +1,10 @@ export function commentHotkeyHandler(event: Event): void { const button = event.target as HTMLButtonElement; const id = button.dataset.aId; + const answerbox = button.closest('.answerbox'); - document.querySelector(`#ab-comments-section-${id}`).classList.remove('d-none'); - document.querySelector(`[name="ab-comment-new"][data-a-id="${id}"]`).focus(); + if (answerbox !== null) { + answerbox.querySelector(`#ab-comments-section-${id}`).classList.toggle('d-none'); + answerbox.querySelector(`[name="ab-comment-new"][data-a-id="${id}"]`).focus(); + } } diff --git a/app/javascript/retrospring/features/answerbox/comment/toggle.ts b/app/javascript/retrospring/features/answerbox/comment/toggle.ts index 578351f8..c53b9cfc 100644 --- a/app/javascript/retrospring/features/answerbox/comment/toggle.ts +++ b/app/javascript/retrospring/features/answerbox/comment/toggle.ts @@ -1,6 +1,9 @@ export function commentToggleHandler(event: Event): void { const button = event.target as HTMLButtonElement; const id = button.dataset.aId; + const answerbox = button.closest('.answerbox'); - document.querySelector(`#ab-comments-section-${id}`).classList.toggle('d-none'); -} \ No newline at end of file + if (answerbox !== null) { + answerbox.querySelector(`#ab-comments-section-${id}`).classList.toggle('d-none'); + } +}