Limit comment toggle querySelector call to nearest answerbox

This commit is contained in:
Andreas Nedbal 2023-10-15 08:23:11 +02:00 committed by Andreas Nedbal
parent 3afa52c59e
commit ac05489329
2 changed files with 10 additions and 4 deletions

View File

@ -1,7 +1,10 @@
export function commentHotkeyHandler(event: Event): void { export function commentHotkeyHandler(event: Event): void {
const button = event.target as HTMLButtonElement; const button = event.target as HTMLButtonElement;
const id = button.dataset.aId; const id = button.dataset.aId;
const answerbox = button.closest('.answerbox');
document.querySelector(`#ab-comments-section-${id}`).classList.remove('d-none'); if (answerbox !== null) {
document.querySelector<HTMLElement>(`[name="ab-comment-new"][data-a-id="${id}"]`).focus(); answerbox.querySelector(`#ab-comments-section-${id}`).classList.toggle('d-none');
answerbox.querySelector<HTMLElement>(`[name="ab-comment-new"][data-a-id="${id}"]`).focus();
}
} }

View File

@ -1,6 +1,9 @@
export function commentToggleHandler(event: Event): void { export function commentToggleHandler(event: Event): void {
const button = event.target as HTMLButtonElement; const button = event.target as HTMLButtonElement;
const id = button.dataset.aId; const id = button.dataset.aId;
const answerbox = button.closest('.answerbox');
document.querySelector(`#ab-comments-section-${id}`).classList.toggle('d-none'); if (answerbox !== null) {
answerbox.querySelector(`#ab-comments-section-${id}`).classList.toggle('d-none');
}
} }