@vaadin/field-base 24.0.0-beta1 → 24.0.0-beta3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/field-base",
3
- "version": "24.0.0-beta1",
3
+ "version": "24.0.0-beta3",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -32,7 +32,7 @@
32
32
  "dependencies": {
33
33
  "@open-wc/dedupe-mixin": "^1.3.0",
34
34
  "@polymer/polymer": "^3.0.0",
35
- "@vaadin/component-base": "24.0.0-beta1",
35
+ "@vaadin/component-base": "24.0.0-beta3",
36
36
  "lit": "^2.0.0"
37
37
  },
38
38
  "devDependencies": {
@@ -40,5 +40,5 @@
40
40
  "@vaadin/testing-helpers": "^0.4.0",
41
41
  "sinon": "^13.0.2"
42
42
  },
43
- "gitHead": "c5b48921a62482746df8e46994b37e1490fec27e"
43
+ "gitHead": "4daeac63327393aacd9cfaa5abeb031ea86b14a5"
44
44
  }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import type { Constructor } from '@open-wc/dedupe-mixin';
7
+ import type { ControllerMixinClass } from '@vaadin/component-base/src/controller-mixin.js';
8
+ import type { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js';
9
+ import type { InputMixinClass } from './input-mixin.js';
10
+
11
+ /**
12
+ * A mixin that manages the clear button.
13
+ */
14
+ export declare function ClearButtonMixin<T extends Constructor<HTMLElement>>(
15
+ base: T,
16
+ ): Constructor<ClearButtonMixinClass> & Constructor<InputMixinClass> & Constructor<KeyboardMixinClass> & T;
17
+
18
+ export declare class ClearButtonMixinClass {
19
+ /**
20
+ * Set to true to display the clear icon which clears the input.
21
+ *
22
+ * It is up to the component to choose where to place the clear icon:
23
+ * in the Shadow DOM or in the light DOM. In any way, a reference to
24
+ * the clear icon element should be provided via the `clearElement` getter.
25
+ *
26
+ * @attr {boolean} clear-button-visible
27
+ */
28
+ clearButtonVisible: boolean;
29
+
30
+ /**
31
+ * Clears the value and dispatches `input` and `change` events
32
+ * on the input element. This method should be called
33
+ * when the clear action originates from the user.
34
+ */
35
+ protected _onClearAction(): void;
36
+ }
@@ -0,0 +1,100 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { KeyboardMixin } from '@vaadin/component-base/src/keyboard-mixin.js';
7
+ import { InputMixin } from './input-mixin.js';
8
+
9
+ /**
10
+ * A mixin that manages the clear button.
11
+ *
12
+ * @polymerMixin
13
+ * @mixes InputMixin
14
+ * @mixes KeyboardMixin
15
+ */
16
+ export const ClearButtonMixin = (superclass) =>
17
+ class ClearButtonMixinClass extends InputMixin(KeyboardMixin(superclass)) {
18
+ static get properties() {
19
+ return {
20
+ /**
21
+ * Set to true to display the clear icon which clears the input.
22
+ *
23
+ * It is up to the component to choose where to place the clear icon:
24
+ * in the Shadow DOM or in the light DOM. In any way, a reference to
25
+ * the clear icon element should be provided via the `clearElement` getter.
26
+ *
27
+ * @attr {boolean} clear-button-visible
28
+ */
29
+ clearButtonVisible: {
30
+ type: Boolean,
31
+ reflectToAttribute: true,
32
+ value: false,
33
+ },
34
+ };
35
+ }
36
+
37
+ /**
38
+ * Any element extending this mixin is required to implement this getter.
39
+ * It returns the reference to the clear button element.
40
+ *
41
+ * @protected
42
+ * @return {Element | null | undefined}
43
+ */
44
+ get clearElement() {
45
+ console.warn(`Please implement the 'clearElement' property in <${this.localName}>`);
46
+ return null;
47
+ }
48
+
49
+ /** @protected */
50
+ ready() {
51
+ super.ready();
52
+
53
+ if (this.clearElement) {
54
+ this.clearElement.addEventListener('click', (event) => this._onClearButtonClick(event));
55
+ }
56
+ }
57
+
58
+ /**
59
+ * @param {Event} event
60
+ * @protected
61
+ */
62
+ _onClearButtonClick(event) {
63
+ event.preventDefault();
64
+ this.inputElement.focus();
65
+ this._onClearAction();
66
+ }
67
+
68
+ /**
69
+ * Override an event listener inherited from `KeydownMixin` to clear on Esc.
70
+ * Components that extend this mixin can prevent this behavior by overriding
71
+ * this method without calling `super._onEscape` to provide custom logic.
72
+ *
73
+ * @param {KeyboardEvent} event
74
+ * @protected
75
+ * @override
76
+ */
77
+ _onEscape(event) {
78
+ super._onEscape(event);
79
+
80
+ if (this.clearButtonVisible && !!this.value) {
81
+ event.stopPropagation();
82
+ this._onClearAction();
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Clears the value and dispatches `input` and `change` events
88
+ * on the input element. This method should be called
89
+ * when the clear action originates from the user.
90
+ *
91
+ * @protected
92
+ */
93
+ _onClearAction() {
94
+ this.clear();
95
+ // Note, according to the HTML spec, the native change event isn't composed
96
+ // while the input event is composed.
97
+ this.inputElement.dispatchEvent(new Event('input', { bubbles: true, composed: true }));
98
+ this.inputElement.dispatchEvent(new Event('change', { bubbles: true }));
99
+ }
100
+ };
@@ -10,6 +10,7 @@ import type { DelegateStateMixinClass } from '@vaadin/component-base/src/delegat
10
10
  import type { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
11
11
  import type { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js';
12
12
  import type { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js';
13
+ import type { ClearButtonMixinClass } from './clear-button-mixin.js';
13
14
  import type { FieldMixinClass } from './field-mixin.js';
14
15
  import type { InputConstraintsMixinClass } from './input-constraints-mixin.js';
15
16
  import type { InputMixinClass } from './input-mixin.js';
@@ -22,7 +23,8 @@ import type { ValidateMixinClass } from './validate-mixin.js';
22
23
  */
23
24
  export declare function InputControlMixin<T extends Constructor<HTMLElement>>(
24
25
  base: T,
25
- ): Constructor<ControllerMixinClass> &
26
+ ): Constructor<ClearButtonMixinClass> &
27
+ Constructor<ControllerMixinClass> &
26
28
  Constructor<DelegateFocusMixinClass> &
27
29
  Constructor<DelegateStateMixinClass> &
28
30
  Constructor<DisabledMixinClass> &
@@ -57,12 +59,6 @@ export declare class InputControlMixinClass {
57
59
  */
58
60
  autoselect: boolean;
59
61
 
60
- /**
61
- * Set to true to display the clear icon which clears the input.
62
- * @attr {boolean} clear-button-visible
63
- */
64
- clearButtonVisible: boolean;
65
-
66
62
  /**
67
63
  * The name of this field.
68
64
  */
@@ -7,6 +7,7 @@ import { timeOut } from '@vaadin/component-base/src/async.js';
7
7
  import { Debouncer } from '@vaadin/component-base/src/debounce.js';
8
8
  import { DelegateFocusMixin } from '@vaadin/component-base/src/delegate-focus-mixin.js';
9
9
  import { KeyboardMixin } from '@vaadin/component-base/src/keyboard-mixin.js';
10
+ import { ClearButtonMixin } from './clear-button-mixin.js';
10
11
  import { FieldMixin } from './field-mixin.js';
11
12
  import { InputConstraintsMixin } from './input-constraints-mixin.js';
12
13
  import { SlotStylesMixin } from './slot-styles-mixin.js';
@@ -19,11 +20,12 @@ import { SlotStylesMixin } from './slot-styles-mixin.js';
19
20
  * @mixes FieldMixin
20
21
  * @mixes InputConstraintsMixin
21
22
  * @mixes KeyboardMixin
23
+ * @mixes ClearButtonMixin
22
24
  * @mixes SlotStylesMixin
23
25
  */
24
26
  export const InputControlMixin = (superclass) =>
25
27
  class InputControlMixinClass extends SlotStylesMixin(
26
- DelegateFocusMixin(InputConstraintsMixin(FieldMixin(KeyboardMixin(superclass)))),
28
+ DelegateFocusMixin(InputConstraintsMixin(FieldMixin(ClearButtonMixin(KeyboardMixin(superclass))))),
27
29
  ) {
28
30
  static get properties() {
29
31
  return {
@@ -52,16 +54,6 @@ export const InputControlMixin = (superclass) =>
52
54
  value: false,
53
55
  },
54
56
 
55
- /**
56
- * Set to true to display the clear icon which clears the input.
57
- * @attr {boolean} clear-button-visible
58
- */
59
- clearButtonVisible: {
60
- type: Boolean,
61
- reflectToAttribute: true,
62
- value: false,
63
- },
64
-
65
57
  /**
66
58
  * The name of this field.
67
59
  */
@@ -109,17 +101,6 @@ export const InputControlMixin = (superclass) =>
109
101
  this._boundOnBeforeInput = this._onBeforeInput.bind(this);
110
102
  }
111
103
 
112
- /**
113
- * Any element extending this mixin is required to implement this getter.
114
- * It returns the reference to the clear button element.
115
- * @protected
116
- * @return {Element | null | undefined}
117
- */
118
- get clearElement() {
119
- console.warn(`Please implement the 'clearElement' property in <${this.localName}>`);
120
- return null;
121
- }
122
-
123
104
  /** @protected */
124
105
  get slotStyles() {
125
106
  // Needed for Safari, where ::slotted(...)::placeholder does not work
@@ -133,25 +114,6 @@ export const InputControlMixin = (superclass) =>
133
114
  ];
134
115
  }
135
116
 
136
- /** @protected */
137
- ready() {
138
- super.ready();
139
-
140
- if (this.clearElement) {
141
- this.clearElement.addEventListener('click', (e) => this._onClearButtonClick(e));
142
- }
143
- }
144
-
145
- /**
146
- * @param {Event} event
147
- * @protected
148
- */
149
- _onClearButtonClick(event) {
150
- event.preventDefault();
151
- this.inputElement.focus();
152
- this.__clear();
153
- }
154
-
155
117
  /**
156
118
  * Override an event listener from `DelegateFocusMixin`.
157
119
  * @param {FocusEvent} event
@@ -166,23 +128,6 @@ export const InputControlMixin = (superclass) =>
166
128
  }
167
129
  }
168
130
 
169
- /**
170
- * Override an event listener inherited from `KeydownMixin` to clear on Esc.
171
- * Components that extend this mixin can prevent this behavior by overriding
172
- * this method without calling `super._onEscape` to provide custom logic.
173
- * @param {KeyboardEvent} event
174
- * @protected
175
- * @override
176
- */
177
- _onEscape(event) {
178
- super._onEscape(event);
179
-
180
- if (this.clearButtonVisible && !!this.value) {
181
- event.stopPropagation();
182
- this.__clear();
183
- }
184
- }
185
-
186
131
  /**
187
132
  * Override an event listener inherited from `InputMixin`
188
133
  * to capture native `change` event and make sure that
@@ -207,13 +152,6 @@ export const InputControlMixin = (superclass) =>
207
152
  );
208
153
  }
209
154
 
210
- /** @private */
211
- __clear() {
212
- this.clear();
213
- this.inputElement.dispatchEvent(new Event('input', { bubbles: true, composed: true }));
214
- this.inputElement.dispatchEvent(new Event('change', { bubbles: true }));
215
- }
216
-
217
155
  /**
218
156
  * Override a method from `InputMixin`.
219
157
  * @param {!HTMLElement} input
@@ -10,6 +10,7 @@ import type { DelegateStateMixinClass } from '@vaadin/component-base/src/delegat
10
10
  import type { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
11
11
  import type { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js';
12
12
  import type { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js';
13
+ import type { ClearButtonMixinClass } from './clear-button-mixin.js';
13
14
  import type { FieldMixinClass } from './field-mixin.js';
14
15
  import type { InputConstraintsMixinClass } from './input-constraints-mixin.js';
15
16
  import type { InputControlMixinClass } from './input-control-mixin.js';
@@ -23,7 +24,8 @@ import type { ValidateMixinClass } from './validate-mixin.js';
23
24
  */
24
25
  export declare function InputFieldMixin<T extends Constructor<HTMLElement>>(
25
26
  base: T,
26
- ): Constructor<ControllerMixinClass> &
27
+ ): Constructor<ClearButtonMixinClass> &
28
+ Constructor<ControllerMixinClass> &
27
29
  Constructor<DelegateFocusMixinClass> &
28
30
  Constructor<DelegateStateMixinClass> &
29
31
  Constructor<DisabledMixinClass> &