@material/web 1.1.2-nightly.c97362c.0 → 1.2.0

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 (41) hide show
  1. package/button/internal/button.d.ts +8 -0
  2. package/button/internal/button.js +9 -1
  3. package/button/internal/button.js.map +1 -1
  4. package/dialog/internal/_dialog.scss +50 -42
  5. package/dialog/internal/dialog-styles.css.js +1 -1
  6. package/dialog/internal/dialog-styles.css.js.map +1 -1
  7. package/divider/internal/_divider.scss +6 -6
  8. package/divider/internal/divider-styles.css.js +1 -1
  9. package/divider/internal/divider-styles.css.js.map +1 -1
  10. package/elevation/internal/_elevation.scss +10 -4
  11. package/elevation/internal/elevation-styles.css.js +1 -1
  12. package/elevation/internal/elevation-styles.css.js.map +1 -1
  13. package/iconbutton/internal/icon-button.d.ts +8 -0
  14. package/iconbutton/internal/icon-button.js +9 -1
  15. package/iconbutton/internal/icon-button.js.map +1 -1
  16. package/menu/internal/menuitem/_menu-item.scss +31 -52
  17. package/menu/internal/menuitem/menu-item-styles.css.js +1 -1
  18. package/menu/internal/menuitem/menu-item-styles.css.js.map +1 -1
  19. package/package.json +5 -3
  20. package/radio/internal/_radio.scss +34 -34
  21. package/radio/internal/radio-styles.css.js +1 -1
  22. package/radio/internal/radio-styles.css.js.map +1 -1
  23. package/ripple/internal/_ripple.scss +8 -9
  24. package/ripple/internal/ripple-styles.css.js +1 -1
  25. package/ripple/internal/ripple-styles.css.js.map +1 -1
  26. package/switch/internal/_handle.scss +42 -37
  27. package/switch/internal/_icon.scss +17 -17
  28. package/switch/internal/_switch.scss +52 -52
  29. package/switch/internal/_track.scss +18 -18
  30. package/switch/internal/switch-styles.css.js +1 -1
  31. package/switch/internal/switch-styles.css.js.map +1 -1
  32. package/testing/harness.d.ts +371 -0
  33. package/testing/harness.js +737 -0
  34. package/testing/harness.js.map +1 -0
  35. package/testing/transform-pseudo-classes.d.ts +39 -0
  36. package/testing/transform-pseudo-classes.js +172 -0
  37. package/testing/transform-pseudo-classes.js.map +1 -0
  38. package/tokens/_index.scss +0 -1
  39. package/tokens/_md-comp-list-item.scss +2 -2
  40. package/tokens/_md-comp-menu-item.scss +63 -7
  41. package/tokens/_md-comp-menu-list-item.scss +0 -162
@@ -0,0 +1,371 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2021 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * Retrieves the element type from a `Harness` type.
8
+ *
9
+ * @template H The harness type.
10
+ */
11
+ export type HarnessElement<H extends Harness> = H extends Harness<infer E> ? ElementWithHarness<E, H> : never;
12
+ /**
13
+ * Harnesses will attach themselves to their element for convenience.
14
+ *
15
+ * @template E The element type.
16
+ * @template H The harness type.
17
+ */
18
+ export type ElementWithHarness<E extends HTMLElement = HTMLElement, H extends Harness<E> = Harness<E>> = E & {
19
+ /**
20
+ * The harness for this element.
21
+ */
22
+ harness: H;
23
+ /**
24
+ * Associated form element.
25
+ */
26
+ form?: HTMLFormElement | null;
27
+ };
28
+ /**
29
+ * Checks whether or not an element has a Harness attached to it on the
30
+ * `element.harness` property.
31
+ *
32
+ * @param element The element to check.
33
+ * @return True if the element has a harness property.
34
+ */
35
+ export declare function isElementWithHarness(element: Element): element is ElementWithHarness;
36
+ /**
37
+ * A test harness class that can be used to simulate interaction with an
38
+ * element.
39
+ *
40
+ * @template E The harness's element type.
41
+ */
42
+ export declare class Harness<E extends HTMLElement = HTMLElement> {
43
+ /**
44
+ * The pseudo classes that should be transformed for simulation. Component
45
+ * subclasses may override this to add additional pseudo classes.
46
+ */
47
+ protected transformPseudoClasses: string[];
48
+ /**
49
+ * The element that this harness controls.
50
+ */
51
+ readonly element: E & ElementWithHarness<E, this>;
52
+ /**
53
+ * A set of elements that have already been patched to support transformed
54
+ * pseudo classes.
55
+ */
56
+ private readonly patchedElements;
57
+ /**
58
+ * Creates a new harness for the given element.
59
+ *
60
+ * @param element The element that this harness controls.
61
+ */
62
+ constructor(element: E);
63
+ /**
64
+ * Resets the element's simulated classes to the default state.
65
+ */
66
+ reset(): Promise<void>;
67
+ /**
68
+ * Hovers and clicks on an element. This will generate a `click` event.
69
+ *
70
+ * @param init Additional event options.
71
+ */
72
+ clickWithMouse(init?: PointerEventInit): Promise<void>;
73
+ /**
74
+ * Begins a click with a mouse. Use this along with `endClickWithMouse()` to
75
+ * customize the length of the click.
76
+ *
77
+ * @param init Additional event options.
78
+ */
79
+ startClickWithMouse(init?: PointerEventInit): Promise<void>;
80
+ /**
81
+ * Finishes a click with a mouse. Use this along with `startClickWithMouse()`
82
+ * to customize the length of the click. This will generate a `click` event.
83
+ *
84
+ * @param init Additional event options.
85
+ */
86
+ endClickWithMouse(init?: PointerEventInit): Promise<void>;
87
+ /**
88
+ * Clicks an element with the keyboard (defaults to spacebar). This will
89
+ * generate a `click` event.
90
+ *
91
+ * @param init Additional event options.
92
+ */
93
+ clickWithKeyboard(init?: KeyboardEventInit): Promise<void>;
94
+ /**
95
+ * Begins a click with the keyboard (defaults to spacebar). Use this along
96
+ * with `endClickWithKeyboard()` to customize the length of the click.
97
+ *
98
+ * @param init Additional event options.
99
+ */
100
+ startClickWithKeyboard(init?: KeyboardEventInit): Promise<void>;
101
+ /**
102
+ * Finishes a click with the keyboard (defaults to spacebar). Use this along
103
+ * with `startClickWithKeyboard()` to customize the length of the click.
104
+ *
105
+ * @param init Additional event options.
106
+ */
107
+ endClickWithKeyboard(init?: KeyboardEventInit): Promise<void>;
108
+ /**
109
+ * Right-clicks and opens a context menu. This will generate a `contextmenu`
110
+ * event.
111
+ */
112
+ rightClickWithMouse(): Promise<void>;
113
+ /**
114
+ * Taps once on the element with a simulated touch. This will generate a
115
+ * `click` event.
116
+ *
117
+ * @param init Additional event options.
118
+ * @param touchInit Additional touch event options.
119
+ */
120
+ tap(init?: PointerEventInit, touchInit?: TouchEventInit): Promise<void>;
121
+ /**
122
+ * Begins a touch tap. Use this along with `endTap()` to customize the length
123
+ * or number of taps.
124
+ *
125
+ * @param init Additional event options.
126
+ * @param touchInit Additional touch event options.
127
+ */
128
+ startTap(init?: PointerEventInit, touchInit?: TouchEventInit): Promise<void>;
129
+ /**
130
+ * Simulates a `contextmenu` event for touch. Use this along with `startTap()`
131
+ * to generate a tap-and-hold context menu interaction.
132
+ *
133
+ * @param init Additional event options.
134
+ */
135
+ startTapContextMenu(init?: MouseEventInit): Promise<void>;
136
+ /**
137
+ * Finished a touch tap. Use this along with `startTap()` to customize the
138
+ * length or number of taps.
139
+ *
140
+ * This will NOT generate a `click` event.
141
+ *
142
+ * @param init Additional event options.
143
+ * @param touchInit Additional touch event options.
144
+ */
145
+ endTap(init?: PointerEventInit, touchInit?: TouchEventInit): Promise<void>;
146
+ /**
147
+ * Simulates a `click` event for touch. Use this along with `endTap()` to
148
+ * control the timing of tap and click events.
149
+ *
150
+ * @param init Additional event options.
151
+ */
152
+ endTapClick(init?: PointerEventInit): Promise<void>;
153
+ /**
154
+ * Cancels a touch tap.
155
+ *
156
+ * @param init Additional event options.
157
+ * @param touchInit Additional touch event options.
158
+ */
159
+ cancelTap(init?: PointerEventInit, touchInit?: TouchEventInit): Promise<void>;
160
+ /**
161
+ * Hovers over the element with a simulated mouse.
162
+ */
163
+ startHover(): Promise<void>;
164
+ /**
165
+ * Moves the simulated mouse cursor off of the element.
166
+ */
167
+ endHover(): Promise<void>;
168
+ /**
169
+ * Simulates focusing an element with the keyboard.
170
+ *
171
+ * @param init Additional event options.
172
+ */
173
+ focusWithKeyboard(init?: KeyboardEventInit): Promise<void>;
174
+ /**
175
+ * Simulates focusing an element with a pointer.
176
+ */
177
+ focusWithPointer(): Promise<void>;
178
+ /**
179
+ * Simulates unfocusing an element.
180
+ */
181
+ blur(): Promise<void>;
182
+ /**
183
+ * Simulates a keypress on an element.
184
+ *
185
+ * @param key The key to press.
186
+ * @param init Additional event options.
187
+ */
188
+ keypress(key: string, init?: KeyboardEventInit): Promise<void>;
189
+ /**
190
+ * Simulates submitting the element's associated form element.
191
+ *
192
+ * @param form (Optional) form to submit, defaults to the elemnt's form.
193
+ * @return The submitted form data or null if the element has no associated
194
+ * form.
195
+ */
196
+ submitForm(form?: HTMLFormElement): FormData | Promise<FormData>;
197
+ /**
198
+ * Returns the element that should be used for interaction simulation.
199
+ * Defaults to the host element itself.
200
+ *
201
+ * Subclasses should override this if the interactive element is not the host.
202
+ *
203
+ * @return The element to use in simulation.
204
+ */
205
+ protected getInteractiveElement(): Promise<HTMLElement>;
206
+ /**
207
+ * Adds a pseudo class to an element. The element's shadow root styles (or
208
+ * document if not in a shadow root) will be transformed to support
209
+ * simulated pseudo classes.
210
+ *
211
+ * @param element The element to add a pseudo class to.
212
+ * @param pseudoClass The pseudo class to add.
213
+ */
214
+ protected addPseudoClass(element: HTMLElement, pseudoClass: string): void;
215
+ /**
216
+ * Removes a pseudo class from an element.
217
+ *
218
+ * @param element The element to remove a pseudo class from.
219
+ * @param pseudoClass The pseudo class to remove.
220
+ */
221
+ protected removePseudoClass(element: HTMLElement, pseudoClass: string): void;
222
+ /**
223
+ * Simulates a click event.
224
+ *
225
+ * @param element The element to click.
226
+ * @param init Additional event options.
227
+ */
228
+ protected simulateClick(element: HTMLElement, init?: MouseEventInit): void;
229
+ /**
230
+ * Simulates a contextmenu event.
231
+ *
232
+ * @param element The element to generate an event for.
233
+ * @param init Additional event options.
234
+ */
235
+ protected simulateContextmenu(element: HTMLElement, init?: MouseEventInit): void;
236
+ /**
237
+ * Simulates focusing with a keyboard. The difference between this and
238
+ * `simulatePointerFocus` is that keyboard focus will include the
239
+ * `:focus-visible` pseudo class.
240
+ *
241
+ * @param element The element to focus with a keyboard.
242
+ */
243
+ protected simulateKeyboardFocus(element: HTMLElement): void;
244
+ /**
245
+ * Simulates focusing with a pointer.
246
+ *
247
+ * @param element The element to focus with a pointer.
248
+ */
249
+ protected simulatePointerFocus(element: HTMLElement): void;
250
+ /**
251
+ * Simulates unfocusing an element.
252
+ *
253
+ * @param element The element to blur.
254
+ */
255
+ protected simulateBlur(element: HTMLElement): void;
256
+ /**
257
+ * Simulates a mouse pointer hovering over an element.
258
+ *
259
+ * @param element The element to hover over.
260
+ * @param init Additional event options.
261
+ */
262
+ protected simulateStartHover(element: HTMLElement, init?: PointerEventInit): void;
263
+ /**
264
+ * Simulates a mouse pointer leaving the element.
265
+ *
266
+ * @param element The element to stop hovering over.
267
+ * @param init Additional event options.
268
+ */
269
+ protected simulateEndHover(element: HTMLElement, init?: PointerEventInit): void;
270
+ /**
271
+ * Simulates a mouse press and hold on an element.
272
+ *
273
+ * @param element The element to press with a mouse.
274
+ * @param init Additional event options.
275
+ */
276
+ protected simulateMousePress(element: HTMLElement, init?: PointerEventInit): void;
277
+ /**
278
+ * Simulates a mouse press release from an element.
279
+ *
280
+ * @param element The element to release pressing from.
281
+ * @param init Additional event options.
282
+ */
283
+ protected simulateMouseRelease(element: HTMLElement, init?: PointerEventInit): void;
284
+ /**
285
+ * Simulates a touch press and hold on an element.
286
+ *
287
+ * @param element The element to press with a touch pointer.
288
+ * @param init Additional event options.
289
+ */
290
+ protected simulateTouchPress(element: HTMLElement, init?: PointerEventInit, touchInit?: TouchEventInit): void;
291
+ /**
292
+ * Simulates a touch press release from an element.
293
+ *
294
+ * @param element The element to release pressing from.
295
+ * @param init Additional event options.
296
+ */
297
+ protected simulateTouchRelease(element: HTMLElement, init?: PointerEventInit, touchInit?: TouchEventInit): void;
298
+ /**
299
+ * Simulates a touch cancel from an element.
300
+ *
301
+ * @param element The element to cancel a touch for.
302
+ * @param init Additional event options.
303
+ */
304
+ protected simulateTouchCancel(element: HTMLElement, init?: PointerEventInit, touchInit?: TouchEventInit): void;
305
+ /**
306
+ * Simulates a keypress on an element.
307
+ *
308
+ * @param element The element to press a key on.
309
+ * @param key The key to press.
310
+ * @param init Additional event options.
311
+ */
312
+ protected simulateKeypress(element: EventTarget, key: string, init?: KeyboardEventInit): void;
313
+ /**
314
+ * Simulates a keydown press on an element.
315
+ *
316
+ * @param element The element to press a key on.
317
+ * @param key The key to press.
318
+ * @param init Additional event options.
319
+ */
320
+ protected simulateKeydown(element: EventTarget, key: string, init?: KeyboardEventInit): void;
321
+ /**
322
+ * Simulates a keyup release from an element.
323
+ *
324
+ * @param element The element to release a key from.
325
+ * @param key The key to release.
326
+ * @param init Additional keyboard options.
327
+ */
328
+ protected simulateKeyup(element: EventTarget, key: string, init?: KeyboardEventInit): void;
329
+ /**
330
+ * Creates a MouseEventInit for an element. The default x/y coordinates of the
331
+ * event init will be in the center of the element.
332
+ *
333
+ * @param element The element to create a `MouseEventInit` for.
334
+ * @return The init object for a `MouseEvent`.
335
+ */
336
+ protected createMouseEventInit(element: HTMLElement): MouseEventInit;
337
+ /**
338
+ * Creates a Touch instance for an element. The default x/y coordinates of the
339
+ * touch will be in the center of the element. This can be used in the
340
+ * `TouchEvent` constructor.
341
+ *
342
+ * @param element The element to create a touch for.
343
+ * @param identifier Optional identifier for the touch. Defaults to 0 for
344
+ * every touch instance.
345
+ * @return The `Touch` instance.
346
+ */
347
+ protected createTouch(element: HTMLElement, identifier?: number): Touch;
348
+ /**
349
+ * Visit each node up the parent tree from the given child until reaching the
350
+ * given parent.
351
+ *
352
+ * This is used to perform logic such as adding/removing recursive pseudo
353
+ * classes like `:hover`.
354
+ *
355
+ * @param child The first child element to start from.
356
+ * @param callback A callback that is invoked with each `HTMLElement` node
357
+ * from the child to the parent.
358
+ * @param parent The last parent element to visit.
359
+ */
360
+ protected forEachNodeFrom(child: HTMLElement, callback: (node: HTMLElement) => void, parent?: HTMLElement): void;
361
+ /**
362
+ * Patch an element's methods, such as `querySelector` and `matches` to
363
+ * handle transformed pseudo classes.
364
+ *
365
+ * For example, `element.matches(':focus')` will return true when the
366
+ * `._focus` class is applied.
367
+ *
368
+ * @param element The element to patch.
369
+ */
370
+ protected patchForTransformedPseudoClasses(element: HTMLElement): void;
371
+ }