@timmo001/groundwork-ui 0.9.22 → 0.9.23
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.
- package/custom-elements.json +1 -1
- package/package.json +1 -1
- package/src/gw-input.ts +27 -1
package/custom-elements.json
CHANGED
|
@@ -9837,7 +9837,7 @@
|
|
|
9837
9837
|
"declarations": [
|
|
9838
9838
|
{
|
|
9839
9839
|
"kind": "class",
|
|
9840
|
-
"description": "A labeled native `<input>`, with an optional hint and error.",
|
|
9840
|
+
"description": "A labeled native `<input>`, with an optional hint and error. Enter submits\nits form when the form's submit button is a `gw-button`, as it would with a\nnative one.",
|
|
9841
9841
|
"name": "GwInput",
|
|
9842
9842
|
"cssProperties": [
|
|
9843
9843
|
{
|
package/package.json
CHANGED
package/src/gw-input.ts
CHANGED
|
@@ -10,7 +10,9 @@ import { FieldInfo } from "./field-info.js";
|
|
|
10
10
|
import { LightElement, fieldId } from "./fields.js";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* A labeled native `<input>`, with an optional hint and error.
|
|
13
|
+
* A labeled native `<input>`, with an optional hint and error. Enter submits
|
|
14
|
+
* its form when the form's submit button is a `gw-button`, as it would with a
|
|
15
|
+
* native one.
|
|
14
16
|
*
|
|
15
17
|
* @element gw-input
|
|
16
18
|
* @summary A labeled text field in light DOM, so forms and autofill see it.
|
|
@@ -105,6 +107,30 @@ export class GwInput extends LightElement {
|
|
|
105
107
|
this.#input.addEventListener("input", () => {
|
|
106
108
|
this.value = this.#input.value;
|
|
107
109
|
});
|
|
110
|
+
// A gw-button's native button is in its shadow root, out of the form's
|
|
111
|
+
// reach, so Enter only submits on its own with a single field. Submit
|
|
112
|
+
// here instead, as a native submit button would
|
|
113
|
+
this.#input.addEventListener("keydown", (event) => {
|
|
114
|
+
const form = this.#input.form;
|
|
115
|
+
|
|
116
|
+
if (
|
|
117
|
+
event.key !== "Enter" ||
|
|
118
|
+
event.isComposing ||
|
|
119
|
+
event.defaultPrevented ||
|
|
120
|
+
form === null ||
|
|
121
|
+
form.querySelector(
|
|
122
|
+
'button:not([type]), button[type="submit"], input[type="submit"]',
|
|
123
|
+
) !== null ||
|
|
124
|
+
form.querySelector(
|
|
125
|
+
'gw-button[type="submit"]:not([disabled], [loading])',
|
|
126
|
+
) === null
|
|
127
|
+
) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
event.preventDefault();
|
|
132
|
+
form.requestSubmit();
|
|
133
|
+
});
|
|
108
134
|
root.append(
|
|
109
135
|
this.#info.heading,
|
|
110
136
|
h("span", { class: "gw-input-control" }, this.#icon, this.#input),
|