MCPcopy Index your code
hub / github.com/refined-github/refined-github / withMenuOpen

Function withMenuOpen

source/github-helpers/with-menu-open.ts:5–22  ·  view source on GitHub ↗
(
	menuButton: HTMLButtonElement,
	callback: (menu: HTMLElement) => T,
)

Source from the content-addressed store, hash-verified

3import {frame} from '../helpers/dom-utils.js';
4
5export 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}

Callers 2

addQuickEditButtonFunction · 0.85

Calls 1

frameFunction · 0.85

Tested by

no test coverage detected