-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path@spectrum-web-components+textfield+0.35.0.patch
79 lines (79 loc) · 3 KB
/
@spectrum-web-components+textfield+0.35.0.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
diff --git a/node_modules/@spectrum-web-components/textfield/src/Textfield.dev.js b/node_modules/@spectrum-web-components/textfield/src/Textfield.dev.js
index 6cdfaba..c82821c 100644
--- a/node_modules/@spectrum-web-components/textfield/src/Textfield.dev.js
+++ b/node_modules/@spectrum-web-components/textfield/src/Textfield.dev.js
@@ -54,6 +54,13 @@ export class TextfieldBase extends ManageHelpText(
this._value = "";
this.quiet = false;
this.required = false;
+ this._eventHandlers = {
+ input: this.handleInput.bind(this),
+ change: this.handleChange.bind(this),
+ focus: this.onFocus.bind(this),
+ blur: this.onBlur.bind(this)
+ };
+ this._firstUpdateAfterConnected = false;
}
static get styles() {
return [textfieldStyles, checkmarkStyles];
@@ -134,6 +141,41 @@ export class TextfieldBase extends ManageHelpText(
onBlur() {
this.focused = !this.readonly && false;
}
+
+ firstUpdateAfterConnected() {
+ this.abortController = new AbortController();
+ const { signal } = this.abortController;
+
+ this.inputElement.addEventListener("change", this._eventHandlers["change"], { signal });
+ this.inputElement.addEventListener("input", this._eventHandlers["input"], { signal });
+ this.inputElement.addEventListener("focus", this._eventHandlers["focus"], { signal });
+ this.inputElement.addEventListener("blur", this._eventHandlers["blur"], { signal });
+ }
+
+ updated(changes) {
+ super.updated(changes);
+ // Adding this here instead of firstUpdated because we want to make sure
+ // this is called again on the first update after a previous disconnect
+ // since firstUpdated is called only once
+ if (this._firstUpdateAfterConnected) {
+ this._firstUpdateAfterConnected = false;
+ this.firstUpdateAfterConnected();
+ }
+ }
+
+ connectedCallback() {
+ super.connectedCallback();
+
+ this._firstUpdateAfterConnected = true;
+ this.requestUpdate();
+ }
+
+ disconnectedCallback() {
+ // Cleanup all event listeners
+ this.abortController?.abort();
+ super.disconnectedCallback();
+ }
+
renderStateIcons() {
if (this.invalid) {
return html`
@@ -191,6 +233,7 @@ export class TextfieldBase extends ManageHelpText(
return html`
<!-- @ts-ignore -->
<input
+ data-test-id="patched"
type=${this.type}
aria-describedby=${this.helpTextId}
aria-label=${this.label || this.appliedLabel || this.placeholder}
@@ -206,10 +249,6 @@ export class TextfieldBase extends ManageHelpText(
pattern=${ifDefined(this.pattern)}
placeholder=${this.placeholder}
.value=${live(this.displayValue)}
- @change=${this.handleChange}
- @input=${this.handleInput}
- @focus=${this.onFocus}
- @blur=${this.onBlur}
?disabled=${this.disabled}
?required=${this.required}
?readonly=${this.readonly}