From d3fcc0c5b9e014c8101dcb6f275163a3c7c729cc Mon Sep 17 00:00:00 2001 From: Michael Chadwick Date: Fri, 13 Dec 2024 14:52:55 -0800 Subject: [PATCH] fix to use elem clicked instead of querying from doc root --- .../components/course/publication-menu.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/ilios-common/addon/components/course/publication-menu.js b/packages/ilios-common/addon/components/course/publication-menu.js index 6a4b0f79b9..31a5e494ff 100644 --- a/packages/ilios-common/addon/components/course/publication-menu.js +++ b/packages/ilios-common/addon/components/course/publication-menu.js @@ -64,9 +64,9 @@ export default class CoursePublicationMenuComponent extends Component { return 'notpublished'; } - focusFirstLink = task(async () => { + focusFirstLink = task(async (item) => { await timeout(1); - document.querySelector('.publication-menu .menu button:first-of-type').focus(); + item.querySelector('.menu button:first-of-type').focus(); }); handleArrowUp(item) { @@ -80,22 +80,22 @@ export default class CoursePublicationMenuComponent extends Component { async handleArrowDown(item) { if (item.classList.value == 'toggle') { this.isOpen = true; - await this.focusFirstLink.perform(); + await this.focusFirstLink.perform(item.parentElement); } else { if (item.nextElementSibling) { item.nextElementSibling.focus(); } else { - await this.focusFirstLink.perform(); + await this.focusFirstLink.perform(item.parentElement); } } } @action - async toggleMenu() { + async toggleMenu({ target }) { this.isOpen = !this.isOpen; if (this.isOpen) { - await this.focusFirstLink.perform(); + await this.focusFirstLink.perform(target.parentElement.parentElement); } } @action @@ -118,9 +118,9 @@ export default class CoursePublicationMenuComponent extends Component { return false; } @action - clearFocus() { - const buttons = document.querySelectorAll('.publication-menu .menu button'); - buttons.forEach((el) => el.blur()); + clearFocus({ target }) { + const menu = target.parentElement.parentElement; + menu.querySelectorAll('button').forEach((el) => el.blur()); } @action close() {