mtrl 0.8.0-next.27 → 0.8.0-next.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Keeps track of which menu is open, so that opening one closes the last.
3
+ *
4
+ * A menu button's menu is dismissed once the interaction moves outside it, so
5
+ * two menus should never be open together: the screen reader would be told
6
+ * there are two, since both openers carry aria-expanded="true".
7
+ *
8
+ * Menus used to rely on the document click listener each open menu installs to
9
+ * notice a click elsewhere and close. That never fired for another menu's
10
+ * opener, because the opener stops the click from propagating, so menus piled
11
+ * up. Announcing the open here does not depend on how the menu was opened,
12
+ * which the click path could never cover: a menu opened by keyboard or by code
13
+ * closes the previous one just the same.
14
+ *
15
+ * Only root menus take part. Submenus belong to their parent, which closes them.
16
+ */
17
+ /** What the registry needs of a menu: a way to close it */
18
+ export interface RegisteredMenu {
19
+ close: (event?: Event) => void;
20
+ }
21
+ /**
22
+ * Announces that a menu has opened, closing whichever was open before.
23
+ *
24
+ * @param menu - The menu that is opening
25
+ * @param event - The event that opened it, passed to the menu being closed
26
+ */
27
+ export declare const menuOpened: (menu: RegisteredMenu, event?: Event) => void;
28
+ /**
29
+ * Announces that a menu has closed. Closing a menu that is not the open one is
30
+ * a no-op, which is what makes the call safe from any close path, including
31
+ * destroy.
32
+ *
33
+ * @param menu - The menu that is closing
34
+ */
35
+ export declare const menuClosed: (menu: RegisteredMenu) => void;
36
+ /** The menu that is currently open, if any. Exported for tests */
37
+ export declare const currentlyOpenMenu: () => RegisteredMenu | null;