material 3.15.3 → 3.16.1

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.
Files changed (219) hide show
  1. package/README.md +5 -5
  2. package/dist/components/button/button.js +2 -15
  3. package/dist/components/button/compose.js +17 -0
  4. package/dist/components/button/config.js +20 -2
  5. package/dist/components/drawer/api.js +14 -0
  6. package/dist/components/drawer/config.js +5 -0
  7. package/dist/components/drawer/constants.d.ts +10 -0
  8. package/dist/components/drawer/constants.js +10 -0
  9. package/dist/components/drawer/drawer.js +11 -3
  10. package/dist/components/drawer/features/items.js +252 -109
  11. package/dist/components/drawer/index.d.ts +92 -10
  12. package/dist/components/drawer/index.js +1 -1
  13. package/dist/components/fab-menu/fab-menu.js +55 -10
  14. package/dist/components/index.js +2 -2
  15. package/dist/components/menu/features/position.js +18 -27
  16. package/dist/components/menu/types.d.ts +1 -1
  17. package/dist/components/search/features/input.js +12 -11
  18. package/dist/components/select/index.d.ts +4 -1
  19. package/dist/components/top-app-bar/index.d.ts +22 -4
  20. package/dist/components/top-app-bar/index.js +1 -1
  21. package/dist/components/top-app-bar/top-app-bar.js +1 -0
  22. package/dist/core/dom/placement.js +11 -0
  23. package/dist/elements/app-bar.js +106 -0
  24. package/dist/elements/button.js +3 -2
  25. package/dist/elements/css/dialog.css +1 -1
  26. package/dist/elements/css/drawer.css +1 -1
  27. package/dist/elements/css/fab-menu.css +1 -1
  28. package/dist/elements/css/fab-menu.js +1 -0
  29. package/dist/elements/css/hosts/app-bar.css +1 -0
  30. package/dist/elements/css/hosts/navigation-drawer.css +1 -0
  31. package/dist/elements/css/menu.css +1 -1
  32. package/dist/elements/drawer.js +6 -119
  33. package/dist/elements/extended-fab.js +3 -2
  34. package/dist/elements/fab-menu.js +1 -1
  35. package/dist/elements/fab.js +3 -2
  36. package/dist/elements/form-button.d.ts +40 -0
  37. package/dist/elements/form-button.js +45 -1
  38. package/dist/elements/icon-button.d.ts +21 -6
  39. package/dist/elements/icon-button.js +3 -2
  40. package/dist/elements/index.d.ts +525 -44
  41. package/dist/elements/index.js +10 -1
  42. package/dist/elements/navigation-drawer.js +197 -0
  43. package/dist/elements/preupgrade/app-bar.css +2 -0
  44. package/dist/elements/preupgrade/badge.css +1 -1
  45. package/dist/elements/preupgrade/bottom-app-bar.css +1 -1
  46. package/dist/elements/preupgrade/bottom-sheet.css +1 -1
  47. package/dist/elements/preupgrade/button-group.css +1 -1
  48. package/dist/elements/preupgrade/button.css +1 -1
  49. package/dist/elements/preupgrade/card.css +1 -1
  50. package/dist/elements/preupgrade/carousel.css +1 -1
  51. package/dist/elements/preupgrade/checkbox.css +1 -1
  52. package/dist/elements/preupgrade/chips.css +1 -1
  53. package/dist/elements/preupgrade/datepicker.css +1 -1
  54. package/dist/elements/preupgrade/dialog.css +1 -1
  55. package/dist/elements/preupgrade/divider.css +1 -1
  56. package/dist/elements/preupgrade/drawer.css +2 -2
  57. package/dist/elements/preupgrade/extended-fab.css +1 -1
  58. package/dist/elements/preupgrade/fab-menu.css +1 -1
  59. package/dist/elements/preupgrade/fab.css +1 -1
  60. package/dist/elements/preupgrade/icon-button.css +1 -1
  61. package/dist/elements/preupgrade/list.css +1 -1
  62. package/dist/elements/preupgrade/loading-indicator.css +1 -1
  63. package/dist/elements/preupgrade/menu.css +1 -1
  64. package/dist/elements/preupgrade/navigation-bar.css +1 -1
  65. package/dist/elements/preupgrade/navigation-drawer.css +2 -0
  66. package/dist/elements/preupgrade/navigation-rail.css +1 -1
  67. package/dist/elements/preupgrade/progress.css +1 -1
  68. package/dist/elements/preupgrade/radios.css +1 -1
  69. package/dist/elements/preupgrade/search.css +1 -1
  70. package/dist/elements/preupgrade/select.css +1 -1
  71. package/dist/elements/preupgrade/side-sheet.css +1 -1
  72. package/dist/elements/preupgrade/slider.css +1 -1
  73. package/dist/elements/preupgrade/snackbar.css +1 -1
  74. package/dist/elements/preupgrade/split-button.css +1 -1
  75. package/dist/elements/preupgrade/switch.css +1 -1
  76. package/dist/elements/preupgrade/tabs.css +1 -1
  77. package/dist/elements/preupgrade/text-field.css +1 -1
  78. package/dist/elements/preupgrade/timepicker.css +1 -1
  79. package/dist/elements/preupgrade/toolbar.css +1 -1
  80. package/dist/elements/preupgrade/tooltip.css +1 -1
  81. package/dist/elements/preupgrade/top-app-bar.css +1 -1
  82. package/dist/elements/preupgrade.css +2 -2
  83. package/dist/elements/split-button.js +4 -1
  84. package/dist/elements/styles.js +5 -5
  85. package/dist/elements/top-app-bar.js +2 -102
  86. package/dist/index.d.ts +4 -4
  87. package/dist/react/app-bar.js +5 -0
  88. package/dist/react/fab-menu.js +1 -0
  89. package/dist/react/index.d.ts +11 -2
  90. package/dist/react/index.js +3 -0
  91. package/dist/react/jsx.d.ts +6 -0
  92. package/dist/react/navigation-drawer-item.js +4 -0
  93. package/dist/react/navigation-drawer.js +5 -0
  94. package/dist/solid/app-bar.js +4 -0
  95. package/dist/solid/fab-menu.js +1 -0
  96. package/dist/solid/index.d.ts +11 -2
  97. package/dist/solid/index.js +3 -0
  98. package/dist/solid/jsx.d.ts +19 -3
  99. package/dist/solid/navigation-drawer-item.js +3 -0
  100. package/dist/solid/navigation-drawer.js +4 -0
  101. package/dist/styles/badge.css +1 -1
  102. package/dist/styles/base-elements.css +1 -1
  103. package/dist/styles/base-lite.css +1 -1
  104. package/dist/styles/base.css +1 -1
  105. package/dist/styles/bottom-app-bar-toolbar.css +1 -1
  106. package/dist/styles/bottom-app-bar.css +1 -1
  107. package/dist/styles/bottom-sheet.css +1 -1
  108. package/dist/styles/button-filled-small-round.css +1 -1
  109. package/dist/styles/button-group.css +1 -1
  110. package/dist/styles/button.css +1 -1
  111. package/dist/styles/card.css +1 -1
  112. package/dist/styles/carousel.css +1 -1
  113. package/dist/styles/checkbox.css +1 -1
  114. package/dist/styles/chips.css +1 -1
  115. package/dist/styles/contrast.css +1 -1
  116. package/dist/styles/datepicker.css +1 -1
  117. package/dist/styles/dialog.css +2 -2
  118. package/dist/styles/divider.css +1 -1
  119. package/dist/styles/drawer.css +2 -2
  120. package/dist/styles/extended-fab.css +1 -1
  121. package/dist/styles/fab-menu.css +2 -2
  122. package/dist/styles/fab-menu.js +1 -0
  123. package/dist/styles/fab.css +1 -1
  124. package/dist/styles/icon-button.css +1 -1
  125. package/dist/styles/list.css +1 -1
  126. package/dist/styles/listbox.css +1 -1
  127. package/dist/styles/loading-indicator.css +1 -1
  128. package/dist/styles/menu.css +2 -2
  129. package/dist/styles/navigation-bar.css +1 -1
  130. package/dist/styles/navigation-rail.css +1 -1
  131. package/dist/styles/progress.css +1 -1
  132. package/dist/styles/radios.css +1 -1
  133. package/dist/styles/search.css +1 -1
  134. package/dist/styles/select.css +1 -1
  135. package/dist/styles/side-sheet.css +1 -1
  136. package/dist/styles/slider.css +1 -1
  137. package/dist/styles/snackbar.css +1 -1
  138. package/dist/styles/split-button.css +1 -1
  139. package/dist/styles/switch.css +1 -1
  140. package/dist/styles/tabs.css +1 -1
  141. package/dist/styles/text-field.css +1 -1
  142. package/dist/styles/timepicker.css +1 -1
  143. package/dist/styles/toolbar.css +1 -1
  144. package/dist/styles/tooltip.css +1 -1
  145. package/dist/styles/top-app-bar.css +1 -1
  146. package/dist/styles/typography.css +1 -1
  147. package/dist/styles/utilities.css +1 -1
  148. package/dist/styles.css +2 -2
  149. package/dist/svelte/AppBar.svelte +25 -0
  150. package/dist/svelte/AppBar.svelte.d.ts +5 -0
  151. package/dist/svelte/Drawer.svelte.d.ts +1 -0
  152. package/dist/svelte/DrawerItem.svelte.d.ts +1 -0
  153. package/dist/svelte/FabMenu.svelte +1 -0
  154. package/dist/svelte/NavigationDrawer.svelte +26 -0
  155. package/dist/svelte/NavigationDrawer.svelte.d.ts +5 -0
  156. package/dist/svelte/NavigationDrawerItem.svelte +11 -0
  157. package/dist/svelte/NavigationDrawerItem.svelte.d.ts +5 -0
  158. package/dist/svelte/TopAppBar.svelte.d.ts +1 -0
  159. package/dist/svelte/index.d.ts +3 -0
  160. package/dist/svelte/index.js +3 -0
  161. package/dist/themes/autumn-contrast.css +1 -1
  162. package/dist/themes/autumn.css +1 -1
  163. package/dist/themes/baseline-contrast.css +1 -1
  164. package/dist/themes/baseline.css +1 -1
  165. package/dist/themes/brownbeige-contrast.css +1 -1
  166. package/dist/themes/brownbeige.css +1 -1
  167. package/dist/themes/content-contrast.css +1 -1
  168. package/dist/themes/content.css +1 -1
  169. package/dist/themes/desert-contrast.css +1 -1
  170. package/dist/themes/desert.css +1 -1
  171. package/dist/themes/expressive-contrast.css +1 -1
  172. package/dist/themes/expressive.css +1 -1
  173. package/dist/themes/fidelity-contrast.css +1 -1
  174. package/dist/themes/fidelity.css +1 -1
  175. package/dist/themes/forest-contrast.css +1 -1
  176. package/dist/themes/forest.css +1 -1
  177. package/dist/themes/fruit-salad-contrast.css +1 -1
  178. package/dist/themes/fruit-salad.css +1 -1
  179. package/dist/themes/highcontrast-contrast.css +1 -1
  180. package/dist/themes/highcontrast.css +1 -1
  181. package/dist/themes/monochrome-contrast.css +1 -1
  182. package/dist/themes/monochrome.css +1 -1
  183. package/dist/themes/neutral-contrast.css +1 -1
  184. package/dist/themes/neutral.css +1 -1
  185. package/dist/themes/ocean-contrast.css +1 -1
  186. package/dist/themes/ocean.css +1 -1
  187. package/dist/themes/rainbow-contrast.css +1 -1
  188. package/dist/themes/rainbow.css +1 -1
  189. package/dist/themes/sageivory-contrast.css +1 -1
  190. package/dist/themes/sageivory.css +1 -1
  191. package/dist/themes/spring-contrast.css +1 -1
  192. package/dist/themes/spring.css +1 -1
  193. package/dist/themes/summer-contrast.css +1 -1
  194. package/dist/themes/summer.css +1 -1
  195. package/dist/themes/sunset-contrast.css +1 -1
  196. package/dist/themes/sunset.css +1 -1
  197. package/dist/themes/tealcaramel-contrast.css +1 -1
  198. package/dist/themes/tealcaramel.css +1 -1
  199. package/dist/themes/vibrant-contrast.css +1 -1
  200. package/dist/themes/vibrant.css +1 -1
  201. package/dist/tokens/catalogue.json +21 -3
  202. package/dist/vue/app-bar.js +4 -0
  203. package/dist/vue/fab-menu.js +1 -0
  204. package/dist/vue/index.d.ts +11 -2
  205. package/dist/vue/index.js +3 -0
  206. package/dist/vue/navigation-drawer-item.js +3 -0
  207. package/dist/vue/navigation-drawer.js +4 -0
  208. package/package.json +1 -1
  209. package/src/styles/components/_dialog.scss +2 -1
  210. package/src/styles/components/_drawer.scss +75 -7
  211. package/src/styles/components/_fab-menu.scss +50 -9
  212. package/src/styles/components/_menu.scss +3 -0
  213. package/src/styles/elements/_app-bar.scss +6 -0
  214. package/src/styles/elements/_drawer.scss +3 -12
  215. package/src/styles/elements/_index.scss +2 -0
  216. package/src/styles/elements/_navigation-drawer.scss +10 -0
  217. package/src/styles/elements/_shared-app-bar.scss +49 -0
  218. package/src/styles/elements/_shared-drawer.scss +18 -0
  219. package/src/styles/elements/_top-app-bar.scss +2 -46
@@ -4,16 +4,32 @@ import type { ForwardedEventPayload } from "../../core/dom/index.js";
4
4
  /**
5
5
  * Creates a new Drawer component with the specified configuration.
6
6
  * @param config
7
+ * @deprecated use {@link createNavigationDrawer}. Material Design 3 names the
8
+ * component the navigation drawer; this name stays for 3.x.
7
9
  */
8
- declare const createDrawer: (config?: DrawerConfig) => DrawerComponent;
10
+ declare function createDrawer(config?: DrawerConfig): DrawerComponent;
9
11
 
10
- /** Drawer variant type — controls layout behavior */
12
+ declare const createShadowDrawer: (config: DrawerConfig) => DrawerComponent;
13
+
14
+ /** Creates a navigation drawer: the same factory as {@link createDrawer}, under the name Material Design 3 gives the component. */
15
+ declare const createNavigationDrawer: typeof createDrawer;
16
+
17
+ /**
18
+ * Drawer variant type — controls layout behavior
19
+ * @deprecated use `NavigationDrawerVariant`. Removal in 4.0.
20
+ */
11
21
  type DrawerVariant = "standard" | "modal";
12
22
 
13
- /** Drawer position — which edge the drawer anchors to */
23
+ /**
24
+ * Drawer position — which edge the drawer anchors to
25
+ * @deprecated use `NavigationDrawerPosition`. Removal in 4.0.
26
+ */
14
27
  type DrawerPosition = "start" | "end";
15
28
 
16
- /** Configuration for a navigation destination item */
29
+ /**
30
+ * Configuration for a navigation destination item
31
+ * @deprecated use `NavigationDrawerItemConfig`. Removal in 4.0.
32
+ */
17
33
  interface DrawerItemConfig {
18
34
  /** Item type — defaults to 'item' if omitted */
19
35
  type?: "item" | "divider" | "section";
@@ -25,6 +41,12 @@ interface DrawerItemConfig {
25
41
  icon?: string;
26
42
  /** Icon HTML content shown while this item is the active destination, in place of `icon`. */
27
43
  activeIcon?: string;
44
+ /** Navigation URL for a leaf destination. */
45
+ href?: string;
46
+ /** A non-empty list makes this item a disclosure section. */
47
+ items?: DrawerItemConfig[];
48
+ /** Initial section state. */
49
+ expanded?: boolean;
28
50
  /** Badge text (e.g. */
29
51
  badge?: string;
30
52
  /** Whether this item is initially active/selected */
@@ -35,7 +57,10 @@ interface DrawerItemConfig {
35
57
  disabled?: boolean;
36
58
  }
37
59
 
38
- /** Event detail emitted when a drawer item is selected */
60
+ /**
61
+ * Event detail emitted when a drawer item is selected
62
+ * @deprecated use `NavigationDrawerSelectEvent`. Removal in 4.0.
63
+ */
39
64
  interface DrawerSelectEvent {
40
65
  /** The selected item's id */
41
66
  id: string;
@@ -49,17 +74,37 @@ interface DrawerSelectEvent {
49
74
  originalEvent: Event;
50
75
  }
51
76
 
52
- /** Events emitted by drawer state, navigation items and root DOM forwarding. */
77
+ /**
78
+ * The new state of a drawer disclosure section.
79
+ * @deprecated use `NavigationDrawerSectionEvent`. Removal in 4.0.
80
+ */
81
+ interface DrawerSectionEvent {
82
+ id: string;
83
+ value: string;
84
+ label: string;
85
+ expanded: boolean;
86
+ originalEvent?: Event;
87
+ }
88
+
89
+ /**
90
+ * Events emitted by drawer state, navigation items and root DOM forwarding.
91
+ * @deprecated use `NavigationDrawerEvents`. Removal in 4.0.
92
+ */
53
93
  interface DrawerEvents {
54
94
  open: () => void;
55
95
  close: () => void;
56
96
  /** User activation only; setActive() is silent. */
57
97
  select: (payload: DrawerSelectEvent) => void;
98
+ expand: (payload: DrawerSectionEvent) => void;
99
+ collapse: (payload: DrawerSectionEvent) => void;
58
100
  click: (payload: ForwardedEventPayload<MouseEvent, HTMLElement>) => void;
59
101
  keydown: (payload: ForwardedEventPayload<KeyboardEvent, HTMLElement>) => void;
60
102
  }
61
103
 
62
- /** Configuration interface for the Drawer component */
104
+ /**
105
+ * Configuration interface for the Drawer component
106
+ * @deprecated use `NavigationDrawerConfig`. Removal in 4.0.
107
+ */
63
108
  interface DrawerConfig extends BaseComponentConfig {
64
109
  /**
65
110
  * Drawer variant that determines layout behavior
@@ -119,9 +164,15 @@ interface DrawerConfig extends BaseComponentConfig {
119
164
  onOpen?: DrawerEvents["open"];
120
165
  /** `close` listener registered at creation. */
121
166
  onClose?: DrawerEvents["close"];
167
+ /** Section listeners registered at creation. */
168
+ onExpand?: DrawerEvents["expand"];
169
+ onCollapse?: DrawerEvents["collapse"];
122
170
  }
123
171
 
124
- /** Drawer component interface — public API */
172
+ /**
173
+ * Drawer component interface — public API
174
+ * @deprecated use `NavigationDrawerComponent`. Removal in 4.0.
175
+ */
125
176
  interface DrawerComponent {
126
177
  /** The drawer's root DOM element */
127
178
  element: HTMLElement;
@@ -167,6 +218,13 @@ interface DrawerComponent {
167
218
  * @param badge
168
219
  */
169
220
  setBadge: (id: string, badge: string) => DrawerComponent;
221
+ /** Open, close or toggle the disclosure with this id. */
222
+ expandSection: (id: string) => DrawerComponent;
223
+ collapseSection: (id: string) => DrawerComponent;
224
+ toggleSection: (id: string) => DrawerComponent;
225
+ isSectionExpanded: (id: string) => boolean;
226
+ /** Expanded section ids in document order. */
227
+ getExpandedSections: () => string[];
170
228
  /**
171
229
  * Adds an event listener
172
230
  * @param event
@@ -192,5 +250,29 @@ interface DrawerComponent {
192
250
  destroy: () => void;
193
251
  };
194
252
  }
195
- export type { DrawerComponent, DrawerConfig, DrawerEvents, DrawerItemConfig, DrawerPosition, DrawerSelectEvent, DrawerVariant };
196
- export { createDrawer, createDrawer as default };
253
+
254
+ /** The navigation drawer's config; the drawer is the navigation drawer. */
255
+ type NavigationDrawerConfig = DrawerConfig;
256
+
257
+ /** The navigation drawer's component. */
258
+ type NavigationDrawerComponent = DrawerComponent;
259
+
260
+ /** The navigation drawer's variant. */
261
+ type NavigationDrawerVariant = DrawerVariant;
262
+
263
+ /** The navigation drawer's position. */
264
+ type NavigationDrawerPosition = DrawerPosition;
265
+
266
+ /** The navigation drawer's item config. */
267
+ type NavigationDrawerItemConfig = DrawerItemConfig;
268
+
269
+ /** The navigation drawer's select event detail. */
270
+ type NavigationDrawerSelectEvent = DrawerSelectEvent;
271
+
272
+ /** The navigation drawer's section event detail. */
273
+ type NavigationDrawerSectionEvent = DrawerSectionEvent;
274
+
275
+ /** The navigation drawer's events. */
276
+ type NavigationDrawerEvents = DrawerEvents;
277
+ export type { DrawerComponent, DrawerConfig, DrawerEvents, DrawerItemConfig, DrawerPosition, DrawerSectionEvent, DrawerSelectEvent, DrawerVariant, NavigationDrawerComponent, NavigationDrawerConfig, NavigationDrawerEvents, NavigationDrawerItemConfig, NavigationDrawerPosition, NavigationDrawerSectionEvent, NavigationDrawerSelectEvent, NavigationDrawerVariant };
278
+ export { createDrawer, createDrawer as default, createNavigationDrawer };
@@ -1 +1 @@
1
- export { default, default as createDrawer } from "./drawer.js";
1
+ export { default, default as createDrawer, createNavigationDrawer } from "./drawer.js";
@@ -8,7 +8,9 @@ import { activeElementOf } from "../../core/dom/focus.js";
8
8
  import { setHTML } from "../../core/dom/html.js";
9
9
  import { getIcon } from "../../core/icons/registry.js";
10
10
  import { warnDev } from "../../core/utils/warn.js";
11
+ import { composeButton } from "../button/compose.js";
11
12
  import createFab from "../fab/index.js";
13
+ import { fitVertically } from "../../core/dom/placement.js";
12
14
  import { createConfig, CLOSE_ICON } from "./config.js";
13
15
  import { staggerDelays } from "./stagger.js";
14
16
  import { FAB_MENU_EVENTS, FAB_MENU_ITEMS, FAB_MENU_ITEM_EXIT, FAB_MENU_MENU_FROM, FAB_MENU_MENU_GAP, FAB_MENU_LIST_GAP, } from "./constants.js";
@@ -61,9 +63,13 @@ list.setAttribute("role", "menu");
61
63
  list.setAttribute("aria-labelledby", button.id);
62
64
  list.setAttribute("inert", "");
63
65
  const entries = items.map((item) => {
64
- const element = document.createElement("button");
65
- element.type = "button";
66
- element.className = `${block}__item`;
66
+ const itemButton = composeButton({
67
+ variant: "text",
68
+ size: "m",
69
+ class: `${block}__item`,
70
+ }, undefined, true);
71
+ resources.add(() => itemButton.destroy());
72
+ const element = itemButton.element;
67
73
  element.setAttribute("role", "menuitem");
68
74
  element.tabIndex = -1;
69
75
  const content = document.createElement("span");
@@ -157,8 +163,10 @@ preload();
157
163
  button.addEventListener("pointerenter", preload, { once: true });
158
164
  button.addEventListener("focus", preload, { once: true });
159
165
  const reduced = () => matches("(prefers-reduced-motion: reduce)");
160
- const stagger = (opening) => {
161
- const delays = reduced() ? entries.map(() => 0) : staggerDelays(entries.length, opening);
166
+ let opensDownward = false;
167
+ const stagger = (opening, downward = false) => {
168
+ const byDistance = reduced() ? entries.map(() => 0) : staggerDelays(entries.length, opening);
169
+ const delays = downward ? [...byDistance].reverse() : byDistance;
162
170
  entries.forEach(({ element }, index) => element.style.setProperty(`--${PREFIX}-fab-menu-delay`, `${delays[index]}ms`));
163
171
  return Math.max(0, ...delays);
164
172
  };
@@ -167,14 +175,51 @@ if (!event.composedPath().includes(root))
167
175
  closeList(false);
168
176
  };
169
177
  const measure = () => entries.forEach(({ element }) => {
170
- const content = element.firstElementChild;
178
+ const content = element.querySelector(`.${block}__item-content`);
171
179
  element.style.setProperty(`--${PREFIX}-fab-menu-item-width`, `${content.offsetWidth}px`);
172
180
  });
181
+ const placeList = () => {
182
+ const fab = root.getBoundingClientRect();
183
+ if (fab.height === 0)
184
+ return false;
185
+ const above = fab.top - FAB_MENU_LIST_GAP - WINDOW_MARGIN;
186
+ const below = window.innerHeight - fab.bottom - FAB_MENU_LIST_GAP - WINDOW_MARGIN;
187
+ const fit = fitVertically({ preferred: "top", height: list.scrollHeight, above, below });
188
+ const downward = fit.side === "bottom";
189
+ root.classList.toggle(`${block}--list-down`, downward);
190
+ placeHorizontally(fab);
191
+ list.style.maxHeight = downward
192
+ ? fit.maxHeight === null ? "" : `${fit.maxHeight}px`
193
+ : above > 0 ? `${above}px` : "";
194
+ return downward;
195
+ };
196
+ const placeHorizontally = (fab) => {
197
+ const width = widest();
198
+ const rtl = getComputedStyle(root).direction === "rtl";
199
+ const endLeft = rtl ? fab.left : fab.right - width;
200
+ const startLeft = rtl ? fab.right - width : fab.left;
201
+ const inside = (left) => left >= 0 && left + width <= window.innerWidth;
202
+ let start = false;
203
+ let shift = 0;
204
+ if (width > 0 && !inside(endLeft)) {
205
+ if (inside(startLeft)) {
206
+ start = true;
207
+ }
208
+ else {
209
+ shift = endLeft < 0 ? -endLeft : window.innerWidth - (endLeft + width);
210
+ }
211
+ }
212
+ root.classList.toggle(`${block}--list-start`, start);
213
+ root.style.setProperty(`--${PREFIX}-fab-menu-shift`, `${shift}px`);
214
+ };
215
+ const widest = () => entries.reduce((widest, { element }) => {
216
+ const content = element.querySelector(`.${block}__item-content`);
217
+ return Math.max(widest, content?.offsetWidth ?? 0);
218
+ }, 0);
173
219
  const openList = () => {
174
220
  measure();
175
- stagger(true);
176
- const top = root.getBoundingClientRect().top;
177
- list.style.maxHeight = top > 0 ? `${Math.max(0, top - FAB_MENU_LIST_GAP - WINDOW_MARGIN)}px` : "";
221
+ opensDownward = placeList();
222
+ stagger(true, opensDownward);
178
223
  list.removeAttribute("inert");
179
224
  root.classList.add(`${block}--open`);
180
225
  document.addEventListener("pointerdown", onOutside, true);
@@ -183,7 +228,7 @@ setOpened(true);
183
228
  function closeList(restoreFocus) {
184
229
  if (!opened)
185
230
  return;
186
- const last = stagger(false);
231
+ const last = stagger(false, opensDownward);
187
232
  list.style.setProperty(`--${PREFIX}-fab-menu-exit`, `${last + FAB_MENU_ITEM_EXIT}ms`);
188
233
  const hadFocus = list.contains(activeElementOf(list));
189
234
  list.setAttribute("inert", "");
@@ -11,7 +11,7 @@ export { createAssistChip, createFilterChip, createInputChip, createSuggestionCh
11
11
  export { default as createDatePicker } from "./datepicker/index.js";
12
12
  export { default as createDialog } from "./dialog/index.js";
13
13
  export { createDivider } from "./divider/index.js";
14
- export { default as createDrawer } from "./drawer/index.js";
14
+ export { default as createDrawer, createNavigationDrawer } from "./drawer/index.js";
15
15
  export { default as createFab } from "./fab/index.js";
16
16
  export { default as createFabMenu } from "./fab-menu/index.js";
17
17
  export { default as createExtendedFab } from "./extended-fab/index.js";
@@ -35,6 +35,6 @@ export { createTab } from "./tabs/tab.js";
35
35
  export { default as createTextField } from "./text-field/index.js";
36
36
  export { default as createTimePicker } from "./timepicker/index.js";
37
37
  export { default as createToolbar } from "./toolbar/index.js";
38
- export { default as createTopAppBar } from "./top-app-bar/index.js";
38
+ export { default as createTopAppBar, createAppBar } from "./top-app-bar/index.js";
39
39
  export { default as createTooltip } from "./tooltip/index.js";
40
40
  export { createCardContent, createCardHeader, createCardActions, createCardMedia, } from "./card/content.js";
@@ -1,3 +1,4 @@
1
+ import { fitVertically } from "../../../core/dom/placement.js";
1
2
  export const createPositioner = (component, config) => {
2
3
  const VIEWPORT_MARGIN = 48;
3
4
  const MIN_MENU_HEIGHT = 100;
@@ -49,15 +50,17 @@ let left = 0;
49
50
  let calculatedPosition = preferredPosition;
50
51
  if (isSubmenu) {
51
52
  calculatedPosition = preferredPosition || "right-start";
52
- if (calculatedPosition.startsWith("right") &&
53
+ if (config.autoFlip !== false &&
54
+ calculatedPosition.startsWith("right") &&
53
55
  horizontalRect.right + menuRect.width + offset > viewportWidth - 16) {
54
56
  calculatedPosition = calculatedPosition.replace("right", "left");
55
57
  }
56
- else if (calculatedPosition.startsWith("left") &&
58
+ else if (config.autoFlip !== false &&
59
+ calculatedPosition.startsWith("left") &&
57
60
  horizontalRect.left - menuRect.width - offset < 16) {
58
61
  calculatedPosition = calculatedPosition.replace("left", "right");
59
62
  }
60
- if (openerRect.top + menuRect.height > viewportHeight - 48) {
63
+ if (config.autoFlip !== false && openerRect.top + menuRect.height > viewportHeight - 48) {
61
64
  if (calculatedPosition === "right-start") {
62
65
  calculatedPosition = "right-end";
63
66
  }
@@ -68,23 +71,6 @@ calculatedPosition = "left-end";
68
71
  }
69
72
  else {
70
73
  switch (preferredPosition) {
71
- case "top-start":
72
- case "top":
73
- case "top-end":
74
- if (openerRect.top < menuRect.height + offset + 48) {
75
- calculatedPosition = preferredPosition.replace("top", "bottom");
76
- }
77
- break;
78
- case "bottom-start":
79
- case "bottom":
80
- case "bottom-end":
81
- if (openerRect.bottom + menuRect.height + offset + 48 >
82
- viewportHeight) {
83
- if (openerRect.top > viewportHeight - openerRect.bottom) {
84
- calculatedPosition = preferredPosition.replace("bottom", "top");
85
- }
86
- }
87
- break;
88
74
  case "right-start":
89
75
  case "right":
90
76
  case "left-start":
@@ -113,13 +99,18 @@ let fitted = null;
113
99
  if (!isSubmenu && /^(top|bottom)/.test(calculatedPosition)) {
114
100
  const below = viewportHeight - openerRect.bottom - offset - VIEWPORT_MARGIN;
115
101
  const above = openerRect.top - offset - VIEWPORT_MARGIN;
116
- if (height > (calculatedPosition.startsWith("bottom") ? below : above)) {
117
- calculatedPosition = calculatedPosition.replace(/^(top|bottom)/, below >= above ? "bottom" : "top");
118
- }
119
- const room = Math.max(calculatedPosition.startsWith("bottom") ? below : above, MIN_MENU_HEIGHT);
120
- if (height > room) {
121
- fitted = room;
122
- height = room;
102
+ const fit = fitVertically({
103
+ preferred: calculatedPosition.startsWith("top") ? "top" : "bottom",
104
+ height,
105
+ above,
106
+ below,
107
+ minHeight: MIN_MENU_HEIGHT,
108
+ autoFlip: config.autoFlip !== false,
109
+ });
110
+ calculatedPosition = calculatedPosition.replace(/^(top|bottom)/, fit.side);
111
+ if (fit.maxHeight !== null) {
112
+ fitted = fit.maxHeight;
113
+ height = fit.maxHeight;
123
114
  }
124
115
  }
125
116
  menuElement.style.maxHeight = fitted !== null ? `${fitted}px` : (config.maxHeight ?? "");
@@ -126,7 +126,7 @@ export interface MenuConfig {
126
126
  */
127
127
  offset?: number;
128
128
  /**
129
- * Whether the menu should automatically flip position to stay in viewport
129
+ * Whether the menu may take the other side of its opener to stay in the viewport.
130
130
  * @default true
131
131
  */
132
132
  autoFlip?: boolean;
@@ -202,25 +202,26 @@ clear();
202
202
  }
203
203
  });
204
204
  }
205
- if (leadingIcon) {
206
- leadingIcon.addEventListener("click", (e) => {
207
- e.preventDefault();
205
+ const activateLeadingIcon = () => {
208
206
  if (component.states?.isExpanded?.()) {
209
207
  component.states.collapse();
208
+ return;
210
209
  }
211
- else {
212
- component.states?.expand();
210
+ if (config.expandOnFocus === false) {
211
+ input.focus();
212
+ return;
213
213
  }
214
+ component.states?.expand();
215
+ };
216
+ if (leadingIcon) {
217
+ leadingIcon.addEventListener("click", (e) => {
218
+ e.preventDefault();
219
+ activateLeadingIcon();
214
220
  });
215
221
  leadingIcon.addEventListener("keydown", (e) => {
216
222
  if (e.key === "Enter" || e.key === " ") {
217
223
  e.preventDefault();
218
- if (component.states?.isExpanded?.()) {
219
- component.states.collapse();
220
- }
221
- else {
222
- component.states?.expand();
223
- }
224
+ activateLeadingIcon();
224
225
  }
225
226
  });
226
227
  }
@@ -59,7 +59,10 @@ interface SelectConfig {
59
59
  container?: HTMLElement | null;
60
60
  /** The menu's max height (a CSS length); the list scrolls inside it */
61
61
  maxHeight?: string;
62
- /** Whether the menu flips above the field when there is no room below */
62
+ /**
63
+ * Whether the menu may take the other side of the field when it does not fit below.
64
+ * @default true
65
+ */
63
66
  autoFlip?: boolean;
64
67
  /** The menu's variant: 'vertical' is the M3 expressive menu, items apart in a rounded container */
65
68
  variant?: MenuVariant;
@@ -2,14 +2,23 @@ import { ElementComponent } from "../../core/compose/index.js";
2
2
 
3
3
  /**
4
4
  * Creates a top app bar component
5
+ * @deprecated use {@link createAppBar}. Material Design 3 names the
6
+ * component the app bar; this name stays for 3.x.
5
7
  * @param config
6
8
  */
7
9
  declare const createTopAppBar: (config?: TopAppBarConfig) => TopAppBarComponent;
8
10
 
11
+ /** Creates an app bar: the same factory as {@link createTopAppBar}, under the name Material Design 3 gives the component. */
12
+ declare const createAppBar: (config?: TopAppBarConfig) => TopAppBarComponent;
13
+
9
14
  /** Top App Bar types */
10
15
  type TopAppBarType = 'small' | 'medium' | 'large' | 'center';
11
16
 
12
- /** Configuration options for Top App Bar component */
17
+ /**
18
+ * Configuration options for Top App Bar component
19
+ * @deprecated use `AppBarConfig`. Material Design 3 names the component the
20
+ * app bar. Removal in 4.0.
21
+ */
13
22
  interface TopAppBarConfig {
14
23
  /**
15
24
  * Element to use for the container
@@ -51,7 +60,10 @@ interface TopAppBarConfig {
51
60
  componentName?: string;
52
61
  }
53
62
 
54
- /** Top App Bar component interface */
63
+ /**
64
+ * Top App Bar component interface
65
+ * @deprecated use `AppBarComponent`. Removal in 4.0.
66
+ */
55
67
  interface TopAppBarComponent extends ElementComponent {
56
68
  /**
57
69
  * Sets the title of the top app bar
@@ -87,6 +99,12 @@ interface TopAppBarComponent extends ElementComponent {
87
99
  /** Gets the trailing container element */
88
100
  getTrailingContainer: () => HTMLElement;
89
101
  }
90
- export type { TopAppBarComponent, TopAppBarConfig };
91
- export { createTopAppBar, createTopAppBar as default };
102
+
103
+ /** The app bar's configuration; the top app bar is the app bar. */
104
+ type AppBarConfig = TopAppBarConfig;
105
+
106
+ /** The app bar's component; the top app bar is the app bar. */
107
+ type AppBarComponent = TopAppBarComponent;
108
+ export type { AppBarComponent, AppBarConfig, TopAppBarComponent, TopAppBarConfig };
109
+ export { createAppBar, createTopAppBar, createTopAppBar as default };
92
110
  export { TOP_APP_BAR_CLASSES, TOP_APP_BAR_DEFAULTS, TOP_APP_BAR_STATES, TOP_APP_BAR_TYPES } from "./constants.js";
@@ -1,4 +1,4 @@
1
1
  import { createTopAppBar } from "./top-app-bar.js";
2
2
  export { TOP_APP_BAR_TYPES, TOP_APP_BAR_STATES, TOP_APP_BAR_DEFAULTS, TOP_APP_BAR_CLASSES } from "./constants.js";
3
3
  export default createTopAppBar;
4
- export { createTopAppBar };
4
+ export { createTopAppBar, createAppBar } from "./top-app-bar.js";
@@ -162,3 +162,4 @@ return trailingContainer;
162
162
  };
163
163
  return topAppBar;
164
164
  };
165
+ export const createAppBar = createTopAppBar;
@@ -0,0 +1,11 @@
1
+ export const MIN_VERTICAL_FIT = 100;
2
+ export const fitVertically = ({ preferred, height, above, below, minHeight = MIN_VERTICAL_FIT, autoFlip = true, }) => {
3
+ const room = (side) => (side === "top" ? above : below);
4
+ if (height <= room(preferred))
5
+ return { side: preferred, maxHeight: null };
6
+ const side = !autoFlip || above === below
7
+ ? preferred
8
+ : below > above ? "bottom" : "top";
9
+ const available = Math.max(room(side), minHeight);
10
+ return { side, maxHeight: available < height ? available : null };
11
+ };
@@ -0,0 +1,106 @@
1
+ import createTopAppBar from "../components/top-app-bar/index.js";
2
+ import { TOP_APP_BAR_DEFAULTS } from "../components/top-app-bar/constants.js";
3
+ import { defineElement } from "./define.js";
4
+ const namedSlot = (name) => {
5
+ const slot = document.createElement("slot");
6
+ slot.name = name;
7
+ return slot;
8
+ };
9
+ const create = (config) => {
10
+ const bar = createTopAppBar(config);
11
+ const headline = bar.getHeadlineElement();
12
+ const text = document.createElement("span");
13
+ text.textContent = headline.textContent;
14
+ headline.replaceChildren(document.createElement("slot"), text);
15
+ bar.addLeadingElement(namedSlot("leading"));
16
+ bar.addTrailingElement(namedSlot("trailing"));
17
+ return bar;
18
+ };
19
+ const headlineText = (component) => component.getHeadlineElement().querySelector("span");
20
+ const leadingEmptiness = (component) => {
21
+ const leading = component.getLeadingContainer();
22
+ const slot = leading.querySelector("slot");
23
+ const sync = () => {
24
+ leading.toggleAttribute("data-empty", slot.assignedElements().length === 0);
25
+ };
26
+ sync();
27
+ slot.addEventListener("slotchange", sync);
28
+ return () => slot.removeEventListener("slotchange", sync);
29
+ };
30
+ const headlineFallback = (component) => {
31
+ const slot = component.getHeadlineElement().querySelector("slot");
32
+ const sync = () => {
33
+ const text = headlineText(component);
34
+ if (text) {
35
+ text.hidden = slot
36
+ .assignedNodes()
37
+ .some((node) => node.nodeType === Node.ELEMENT_NODE || (node.textContent ?? "").trim() !== "");
38
+ }
39
+ };
40
+ sync();
41
+ slot.addEventListener("slotchange", sync);
42
+ return () => slot.removeEventListener("slotchange", sync);
43
+ };
44
+ const readBar = (host) => ({
45
+ scrollable: !host.hasAttribute("no-scroll") && !host.hasAttribute("scroll-target"),
46
+ compressible: !host.hasAttribute("no-compress"),
47
+ });
48
+ const threshold = (host) => {
49
+ const value = Number(host.getAttribute("scroll-threshold") ?? TOP_APP_BAR_DEFAULTS.SCROLL_THRESHOLD);
50
+ return Number.isNaN(value) ? TOP_APP_BAR_DEFAULTS.SCROLL_THRESHOLD : value;
51
+ };
52
+ const followScrollTarget = (host, component) => {
53
+ const id = host.getAttribute("scroll-target");
54
+ if (!id || host.hasAttribute("no-scroll"))
55
+ return () => undefined;
56
+ const update = (target) => void component.setScrollState(target.scrollTop > threshold(host));
57
+ const onScroll = (event) => {
58
+ const target = event.composedPath()[0];
59
+ if (target instanceof Element && target.id === id)
60
+ update(target);
61
+ };
62
+ const initial = host.ownerDocument.getElementById(id);
63
+ if (initial)
64
+ update(initial);
65
+ host.ownerDocument.addEventListener("scroll", onScroll, { capture: true, passive: true });
66
+ return () => host.ownerDocument.removeEventListener("scroll", onScroll, { capture: true });
67
+ };
68
+ export const createBarSpec = (name) => ({
69
+ name,
70
+ slots: ["leading", "trailing"],
71
+ create: (config) => create(config),
72
+ styles: ["top-app-bar"],
73
+ hostStyles: ":host{display:block}",
74
+ attributes: {
75
+ type: { type: "string", config: "type", update: (c, v) => void c.setType((v ?? "small")) },
76
+ headline: {
77
+ type: "string",
78
+ config: "title",
79
+ update: (c, v) => {
80
+ const text = headlineText(c);
81
+ if (text)
82
+ text.textContent = v === null ? "" : String(v);
83
+ },
84
+ },
85
+ "no-scroll": { type: "boolean" },
86
+ "no-compress": { type: "boolean" },
87
+ "scroll-threshold": { type: "number", config: "scrollThreshold" },
88
+ "scroll-target": { type: "string" },
89
+ "aria-label": {
90
+ type: "string",
91
+ update: (c, v) => c.element.setAttribute("aria-label", v === null ? "Top app bar" : String(v)),
92
+ },
93
+ },
94
+ methods: ["setScrollState"],
95
+ config: readBar,
96
+ setup: (host, component) => {
97
+ const label = host.getAttribute("aria-label");
98
+ if (label !== null)
99
+ component.element.setAttribute("aria-label", label);
100
+ const cleanups = [headlineFallback(component), leadingEmptiness(component), followScrollTarget(host, component)];
101
+ return () => cleanups.forEach((cleanup) => cleanup());
102
+ },
103
+ });
104
+ export const appBarSpec = createBarSpec("app-bar");
105
+ export const appBarElement = defineElement(appBarSpec);
106
+ export const defineAppBar = (options) => appBarElement.define(options);
@@ -1,6 +1,6 @@
1
1
  import createButton from "../components/button/index.js";
2
2
  import { defineElement } from "./define.js";
3
- import { buttonForm, submitOnClick, typeAttribute } from "./form-button.js";
3
+ import { buttonAria, buttonForm, setupFormButton, typeAttribute } from "./form-button.js";
4
4
  const buttonSpec = {
5
5
  name: "button",
6
6
  create: (config) => createButton({ ...config, type: "button" }),
@@ -18,6 +18,7 @@ toggle: { type: "boolean", config: "toggle" },
18
18
  selected: { type: "boolean", config: "selected", update: (c, v) => void c.setSelected(Boolean(v)) },
19
19
  value: { type: "string", config: "value", update: (c, v) => void c.setValue(String(v ?? "")) },
20
20
  type: typeAttribute,
21
+ ...buttonAria,
21
22
  "aria-label": { type: "string", config: "ariaLabel", update: (c, v) => void c.setAriaLabel(String(v ?? "")) },
22
23
  },
23
24
  properties: {
@@ -42,7 +43,7 @@ return { selected, value };
42
43
  },
43
44
  },
44
45
  form: buttonForm(),
45
- setup: submitOnClick,
46
+ setup: setupFormButton,
46
47
  };
47
48
  export const buttonElement = defineElement(buttonSpec);
48
49
  export const defineButton = (options) => buttonElement.define(options);