( menuButton: HTMLButtonElement, callback: (menu: HTMLElement) => T, )
| 3 | import {frame} from '../helpers/dom-utils.js'; |
| 4 | |
| 5 | export default async function withMenuOpen<T>( |
| 6 | menuButton: HTMLButtonElement, |
| 7 | callback: (menu: HTMLElement) => T, |
| 8 | ): Promise<T> { |
| 9 | menuButton.click(); |
| 10 | // Wait for the menu DOM to be created, but not rendered |
| 11 | await frame(); |
| 12 | |
| 13 | try { |
| 14 | // When executing concurrently, there might be multiple menus open, so we find the one that is associated with the given button |
| 15 | // If the button itself is labelled by another element, the menu will be labelled by that element too |
| 16 | const menu = $(`[aria-labelledby="${menuButton.getAttribute('aria-labelledby') ?? menuButton.id}"]`); |
| 17 | const result = callback(menu); |
| 18 | return result; |
| 19 | } finally { |
| 20 | menuButton.click(); |
| 21 | } |
| 22 | } |
no test coverage detected