mtrl 0.8.0-next.27 → 0.8.0-next.29

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;
@@ -8,7 +8,7 @@
8
8
  * @category Components
9
9
  */
10
10
  export { default } from './menu';
11
- export type { MenuConfig, MenuComponent, MenuItem, MenuDivider, MenuContent, MenuEvent, MenuSelectEvent, MenuPosition } from './types';
11
+ export type { MenuConfig, MenuComponent, MenuItem, MenuDivider, MenuGap, MenuContent, MenuEvent, MenuSelectEvent, MenuPosition } from './types';
12
12
  /**
13
13
  * Constants for menu position values - use these instead of string literals
14
14
  * for better code completion and type safety.
@@ -103,11 +103,33 @@ export interface MenuDivider {
103
103
  id?: string;
104
104
  }
105
105
  /**
106
- * Combined type for menu content items (regular items or dividers)
106
+ * Menu item type for a gap between groups.
107
+ *
108
+ * The M3 expressive vertical menu separates groups two ways: a divider line,
109
+ * or a gap. A gap splits the menu into separate surfaces, each with its own
110
+ * rounded container, rather than drawing a line across one surface
111
+ * (m3.material.io/components/menus, vertical menus).
112
+ *
113
+ * A standard menu is a single surface, so a gap there is simply space.
114
+ *
115
+ * @category Components
116
+ */
117
+ export interface MenuGap {
118
+ /**
119
+ * Type must be 'gap' to differentiate from regular menu items
120
+ */
121
+ type: "gap";
122
+ /**
123
+ * Optional ID for the gap (for accessibility)
124
+ */
125
+ id?: string;
126
+ }
127
+ /**
128
+ * Combined type for menu content items (regular items, dividers or gaps)
107
129
  *
108
130
  * @category Components
109
131
  */
110
- export type MenuContent = MenuItem | MenuDivider;
132
+ export type MenuContent = MenuItem | MenuDivider | MenuGap;
111
133
  /**
112
134
  * Configuration interface for the Menu component
113
135
  *