@timmo001/groundwork-ui 0.9.1 → 0.9.3

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.
@@ -3613,7 +3613,7 @@
3613
3613
  "type": {
3614
3614
  "text": "\"button\"|\"submit\"|\"reset\""
3615
3615
  },
3616
- "description": "The native button type. Defaults to `button`.",
3616
+ "description": "What a click does: nothing more, or submit or reset the form the button is in. Defaults to `button`.",
3617
3617
  "name": "type"
3618
3618
  },
3619
3619
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@timmo001/groundwork-ui",
3
- "version": "0.9.1",
3
+ "version": "0.9.3",
4
4
  "description": "Groundwork's framework-free web components, styled by the --gw-* tokens",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
package/src/gw-button.ts CHANGED
@@ -32,7 +32,7 @@ import { base, controlSizes, createIcon, setIconPath } from "./styles.js";
32
32
  * @attr {"brand"|"neutral"|"info"|"success"|"warning"|"danger"} variant - The color. Defaults to `brand`.
33
33
  * @attr {"accent"|"filled"|"outlined"|"plain"} appearance - How the color is applied. Defaults to `accent`.
34
34
  * @attr {"xs"|"small"|"medium"|"large"|"xl"} size - The size, 24 to 56px tall. Defaults to `medium`.
35
- * @attr {"button"|"submit"|"reset"} type - The native button type. Defaults to `button`.
35
+ * @attr {"button"|"submit"|"reset"} type - What a click does: nothing more, or submit or reset the form the button is in. Defaults to `button`.
36
36
  * @attr {string} href - Renders a link to this address instead of a button.
37
37
  * @attr {string} label - The accessible name, when the text alone isn't enough.
38
38
  * @attr {boolean} disabled - Disables the button.
@@ -423,6 +423,25 @@ export class GwButton extends GwElement {
423
423
  if (link !== null && !event.composedPath().includes(link)) {
424
424
  link.click();
425
425
  }
426
+
427
+ // The native button is in the shadow root, so it has no form of its
428
+ // own; submit and reset act on the form around the element instead
429
+ const form = this.closest("form");
430
+
431
+ if (
432
+ form === null ||
433
+ this.disabled ||
434
+ event.defaultPrevented ||
435
+ !(this.#control instanceof HTMLButtonElement)
436
+ ) {
437
+ return;
438
+ }
439
+
440
+ if (this.type === "submit") {
441
+ form.requestSubmit();
442
+ } else if (this.type === "reset") {
443
+ form.reset();
444
+ }
426
445
  });
427
446
 
428
447
  const focus = () => {
package/src/on.ts CHANGED
@@ -12,12 +12,26 @@ export type { GwEventMap } from "./events.js";
12
12
 
13
13
  type EventTag = keyof GwEventMap;
14
14
 
15
+ /**
16
+ * Each event-firing element's class, by tag. An app only declares the tags it
17
+ * imports, so the ones it doesn't load are `never` rather than an error.
18
+ */
19
+ type Loaded = {
20
+ [T in EventTag]: T extends keyof HTMLElementTagNameMap
21
+ ? HTMLElementTagNameMap[T]
22
+ : never;
23
+ };
24
+
15
25
  /** A `gw-` element that fires events of its own. */
16
- export type GwEventTarget = HTMLElementTagNameMap[EventTag];
26
+ export type GwEventTarget = Loaded[EventTag];
17
27
 
18
28
  /** The events an element fires, found from the tag its class is defined for. */
19
29
  export type GwEventsOf<E extends GwEventTarget> = {
20
- [T in EventTag]: E extends HTMLElementTagNameMap[T] ? GwEventMap[T] : never;
30
+ [T in EventTag]: [Loaded[T]] extends [never]
31
+ ? never
32
+ : E extends Loaded[T]
33
+ ? GwEventMap[T]
34
+ : never;
21
35
  }[EventTag];
22
36
 
23
37
  /**