@vaadin/field-base 22.0.1 → 22.0.5

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 (58) hide show
  1. package/LICENSE +1 -1
  2. package/package.json +3 -3
  3. package/src/checked-mixin.d.ts +1 -1
  4. package/src/checked-mixin.js +1 -1
  5. package/src/delegate-focus-mixin.d.ts +7 -2
  6. package/src/delegate-focus-mixin.js +54 -6
  7. package/src/delegate-state-mixin.d.ts +1 -1
  8. package/src/delegate-state-mixin.js +1 -1
  9. package/src/error-controller.d.ts +36 -0
  10. package/src/error-controller.js +134 -0
  11. package/src/field-aria-controller.d.ts +1 -1
  12. package/src/field-aria-controller.js +1 -1
  13. package/src/field-mixin.d.ts +3 -1
  14. package/src/field-mixin.js +57 -221
  15. package/src/helper-controller.d.ts +23 -0
  16. package/src/helper-controller.js +185 -0
  17. package/src/input-constraints-mixin.d.ts +1 -1
  18. package/src/input-constraints-mixin.js +1 -1
  19. package/src/input-control-mixin.d.ts +1 -1
  20. package/src/input-control-mixin.js +11 -8
  21. package/src/input-controller.d.ts +3 -3
  22. package/src/input-controller.js +5 -4
  23. package/src/input-field-mixin.d.ts +1 -1
  24. package/src/input-field-mixin.js +16 -1
  25. package/src/input-mixin.d.ts +1 -1
  26. package/src/input-mixin.js +1 -1
  27. package/src/label-controller.d.ts +26 -0
  28. package/src/label-controller.js +188 -0
  29. package/src/label-mixin.d.ts +4 -3
  30. package/src/label-mixin.js +10 -49
  31. package/src/labelled-input-controller.d.ts +1 -1
  32. package/src/labelled-input-controller.js +17 -4
  33. package/src/pattern-mixin.d.ts +1 -1
  34. package/src/pattern-mixin.js +1 -1
  35. package/src/shadow-focus-mixin.d.ts +1 -1
  36. package/src/shadow-focus-mixin.js +16 -4
  37. package/src/slot-styles-mixin.d.ts +1 -1
  38. package/src/slot-styles-mixin.js +1 -1
  39. package/src/slot-target-controller.d.ts +31 -0
  40. package/src/slot-target-controller.js +119 -0
  41. package/src/styles/clear-button-styles.d.ts +1 -1
  42. package/src/styles/clear-button-styles.js +1 -1
  43. package/src/styles/field-shared-styles.d.ts +1 -1
  44. package/src/styles/field-shared-styles.js +1 -1
  45. package/src/styles/input-field-container-styles.d.ts +1 -1
  46. package/src/styles/input-field-container-styles.js +1 -1
  47. package/src/styles/input-field-shared-styles.d.ts +1 -1
  48. package/src/styles/input-field-shared-styles.js +1 -1
  49. package/src/text-area-controller.d.ts +3 -3
  50. package/src/text-area-controller.js +5 -4
  51. package/src/validate-mixin.d.ts +1 -1
  52. package/src/validate-mixin.js +1 -1
  53. package/src/slot-controller.d.ts +0 -8
  54. package/src/slot-controller.js +0 -36
  55. package/src/slot-label-mixin.d.ts +0 -15
  56. package/src/slot-label-mixin.js +0 -38
  57. package/src/slot-target-mixin.d.ts +0 -25
  58. package/src/slot-target-mixin.js +0 -110
package/LICENSE CHANGED
@@ -175,7 +175,7 @@
175
175
 
176
176
  END OF TERMS AND CONDITIONS
177
177
 
178
- Copyright 2021 Vaadin Ltd.
178
+ Copyright 2021 - 2022 Vaadin Ltd..
179
179
 
180
180
  Licensed under the Apache License, Version 2.0 (the "License");
181
181
  you may not use this file except in compliance with the License.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/field-base",
3
- "version": "22.0.1",
3
+ "version": "22.0.5",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -31,7 +31,7 @@
31
31
  "dependencies": {
32
32
  "@open-wc/dedupe-mixin": "^1.3.0",
33
33
  "@polymer/polymer": "^3.0.0",
34
- "@vaadin/component-base": "^22.0.1",
34
+ "@vaadin/component-base": "^22.0.5",
35
35
  "lit": "^2.0.0"
36
36
  },
37
37
  "devDependencies": {
@@ -39,5 +39,5 @@
39
39
  "@vaadin/testing-helpers": "^0.3.2",
40
40
  "sinon": "^9.2.1"
41
41
  },
42
- "gitHead": "2b0a2bff0369d6020f7cc33ad35506aa2d1f6f68"
42
+ "gitHead": "3e1990867670f3de2dec6fa1200d945623b2710c"
43
43
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2022 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { Constructor } from '@open-wc/dedupe-mixin';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2022 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
@@ -1,18 +1,23 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2022 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { Constructor } from '@open-wc/dedupe-mixin';
7
7
  import { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
8
8
  import { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js';
9
+ import { TabindexMixinClass } from '@vaadin/component-base/src/tabindex-mixin.js';
9
10
 
10
11
  /**
11
12
  * A mixin to forward focus to an element in the light DOM.
12
13
  */
13
14
  export declare function DelegateFocusMixin<T extends Constructor<HTMLElement>>(
14
15
  base: T
15
- ): T & Constructor<DelegateFocusMixinClass> & Constructor<DisabledMixinClass> & Constructor<FocusMixinClass>;
16
+ ): T &
17
+ Constructor<DelegateFocusMixinClass> &
18
+ Constructor<DisabledMixinClass> &
19
+ Constructor<FocusMixinClass> &
20
+ Constructor<TabindexMixinClass>;
16
21
 
17
22
  export declare class DelegateFocusMixinClass {
18
23
  /**
@@ -1,22 +1,22 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2022 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
7
- import { DisabledMixin } from '@vaadin/component-base/src/disabled-mixin.js';
8
7
  import { FocusMixin } from '@vaadin/component-base/src/focus-mixin.js';
8
+ import { TabindexMixin } from '@vaadin/component-base/src/tabindex-mixin.js';
9
9
 
10
10
  /**
11
11
  * A mixin to forward focus to an element in the light DOM.
12
12
  *
13
13
  * @polymerMixin
14
- * @mixes DisabledMixin
15
14
  * @mixes FocusMixin
15
+ * @mixes TabindexMixin
16
16
  */
17
17
  export const DelegateFocusMixin = dedupingMixin(
18
18
  (superclass) =>
19
- class DelegateFocusMixinClass extends FocusMixin(DisabledMixin(superclass)) {
19
+ class DelegateFocusMixinClass extends FocusMixin(TabindexMixin(superclass)) {
20
20
  static get properties() {
21
21
  return {
22
22
  /**
@@ -40,6 +40,19 @@ export const DelegateFocusMixin = dedupingMixin(
40
40
  type: Object,
41
41
  readOnly: true,
42
42
  observer: '_focusElementChanged'
43
+ },
44
+
45
+ /**
46
+ * Indicates whether the element can be focused and where it participates in sequential keyboard navigation.
47
+ *
48
+ * By default, the host element does not have tabindex attribute. Instead, `focusElement` should have it.
49
+ * Toggling `tabindex` attribute on the host element propagates its value to `focusElement`.
50
+ *
51
+ * @protected
52
+ */
53
+ tabindex: {
54
+ type: Number,
55
+ value: undefined
43
56
  }
44
57
  };
45
58
  }
@@ -103,6 +116,7 @@ export const DelegateFocusMixin = dedupingMixin(
103
116
  if (element) {
104
117
  element.disabled = this.disabled;
105
118
  this._addFocusListeners(element);
119
+ this.__forwardTabIndex(this.tabindex);
106
120
  } else if (oldElement) {
107
121
  this._removeFocusListeners(oldElement);
108
122
  }
@@ -162,10 +176,12 @@ export const DelegateFocusMixin = dedupingMixin(
162
176
 
163
177
  /**
164
178
  * @param {boolean} disabled
179
+ * @param {boolean} oldDisabled
165
180
  * @protected
181
+ * @override
166
182
  */
167
- _disabledChanged(disabled) {
168
- super._disabledChanged(disabled);
183
+ _disabledChanged(disabled, oldDisabled) {
184
+ super._disabledChanged(disabled, oldDisabled);
169
185
 
170
186
  if (this.focusElement) {
171
187
  this.focusElement.disabled = disabled;
@@ -175,5 +191,37 @@ export const DelegateFocusMixin = dedupingMixin(
175
191
  this.blur();
176
192
  }
177
193
  }
194
+
195
+ /**
196
+ * Override an observer from `TabindexMixin`.
197
+ * Do not call super to remove tabindex attribute
198
+ * from the host after it has been forwarded.
199
+ * @param {string} tabindex
200
+ * @protected
201
+ * @override
202
+ */
203
+ _tabindexChanged(tabindex) {
204
+ this.__forwardTabIndex(tabindex);
205
+ }
206
+
207
+ /** @private */
208
+ __forwardTabIndex(tabindex) {
209
+ if (tabindex !== undefined && this.focusElement) {
210
+ this.focusElement.tabIndex = tabindex;
211
+
212
+ // Preserve tabindex="-1" on the host element
213
+ if (tabindex !== -1) {
214
+ this.tabindex = undefined;
215
+ }
216
+ }
217
+
218
+ if (this.disabled && tabindex) {
219
+ // If tabindex attribute was changed while component was disabled
220
+ if (tabindex !== -1) {
221
+ this.__lastTabIndex = tabindex;
222
+ }
223
+ this.tabindex = undefined;
224
+ }
225
+ }
178
226
  }
179
227
  );
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2022 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { Constructor } from '@open-wc/dedupe-mixin';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2022 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2021 - 2022 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
7
+
8
+ /**
9
+ * A controller that manages the error message node content.
10
+ */
11
+ export class ErrorController extends SlotController {
12
+ /**
13
+ * ID attribute value set on the error message element.
14
+ */
15
+ readonly errorId: string;
16
+
17
+ /**
18
+ * String used for the error message text content.
19
+ */
20
+ protected errorMessage: string | null | undefined;
21
+
22
+ /**
23
+ * Set to true when the host element is invalid.
24
+ */
25
+ protected invalid: boolean;
26
+
27
+ /**
28
+ * Set the error message element text content.
29
+ */
30
+ setErrorMessage(errorMessage: string | null | undefined): void;
31
+
32
+ /**
33
+ * Set invalid state for detecting whether to show error message.
34
+ */
35
+ setInvalid(invalid: boolean): void;
36
+ }
@@ -0,0 +1,134 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2021 - 2022 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
7
+
8
+ /**
9
+ * A controller that manages the error message node content.
10
+ */
11
+ export class ErrorController extends SlotController {
12
+ constructor(host) {
13
+ super(
14
+ host,
15
+ 'error-message',
16
+ () => document.createElement('div'),
17
+ (_host, node) => {
18
+ this.__updateErrorId(node);
19
+
20
+ this.__updateHasError();
21
+ }
22
+ );
23
+ }
24
+
25
+ /**
26
+ * ID attribute value set on the error message element.
27
+ *
28
+ * @return {string}
29
+ */
30
+ get errorId() {
31
+ return this.node && this.node.id;
32
+ }
33
+
34
+ /**
35
+ * Set the error message element text content.
36
+ *
37
+ * @param {string} errorMessage
38
+ */
39
+ setErrorMessage(errorMessage) {
40
+ this.errorMessage = errorMessage;
41
+
42
+ this.__updateHasError();
43
+ }
44
+
45
+ /**
46
+ * Set invalid state for detecting whether to show error message.
47
+ *
48
+ * @param {boolean} invalid
49
+ */
50
+ setInvalid(invalid) {
51
+ this.invalid = invalid;
52
+
53
+ this.__updateHasError();
54
+ }
55
+
56
+ /**
57
+ * Override to initialize the newly added custom label.
58
+ *
59
+ * @param {Node} errorNode
60
+ * @protected
61
+ * @override
62
+ */
63
+ initCustomNode(errorNode) {
64
+ this.__updateErrorId(errorNode);
65
+
66
+ // Save the custom error message content on the host.
67
+ if (errorNode.textContent && !this.errorMessage) {
68
+ this.errorMessage = errorNode.textContent.trim();
69
+ }
70
+
71
+ this.__updateHasError();
72
+ }
73
+
74
+ /**
75
+ * Override to cleanup label node when it's removed.
76
+ *
77
+ * @param {Node} node
78
+ * @protected
79
+ * @override
80
+ */
81
+ teardownNode(node) {
82
+ let errorNode = this.getSlotChild();
83
+
84
+ // If custom error was removed, restore the default one.
85
+ if (!errorNode && node !== this.defaultNode) {
86
+ errorNode = this.attachDefaultNode();
87
+
88
+ // Run initializer to update default label and ID.
89
+ this.initNode(errorNode);
90
+ }
91
+
92
+ this.__updateHasError();
93
+ }
94
+
95
+ /**
96
+ * @param {string} error
97
+ * @private
98
+ */
99
+ __isNotEmpty(error) {
100
+ return Boolean(error && error.trim() !== '');
101
+ }
102
+
103
+ /** @private */
104
+ __updateHasError() {
105
+ const errorNode = this.node;
106
+ const hasError = Boolean(this.invalid && this.__isNotEmpty(this.errorMessage));
107
+
108
+ // Update both default and custom error message node.
109
+ if (errorNode) {
110
+ errorNode.textContent = hasError ? this.errorMessage : '';
111
+ errorNode.hidden = !hasError;
112
+
113
+ // Role alert will make the error message announce immediately
114
+ // as the field becomes invalid
115
+ if (hasError) {
116
+ errorNode.setAttribute('role', 'alert');
117
+ } else {
118
+ errorNode.removeAttribute('role');
119
+ }
120
+ }
121
+
122
+ this.host.toggleAttribute('has-error-message', hasError);
123
+ }
124
+
125
+ /**
126
+ * @param {HTMLElement} errorNode
127
+ * @private
128
+ */
129
+ __updateErrorId(errorNode) {
130
+ if (!errorNode.id) {
131
+ errorNode.id = this.defaultId;
132
+ }
133
+ }
134
+ }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2022 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2022 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
 
@@ -1,10 +1,11 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2022 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { Constructor } from '@open-wc/dedupe-mixin';
7
7
  import { ControllerMixinClass } from '@vaadin/component-base/src/controller-mixin.js';
8
+ import { SlotMixinClass } from '@vaadin/component-base/src/slot-mixin.js';
8
9
  import { LabelMixinClass } from './label-mixin.js';
9
10
  import { ValidateMixinClass } from './validate-mixin.js';
10
11
 
@@ -17,6 +18,7 @@ export declare function FieldMixin<T extends Constructor<HTMLElement>>(
17
18
  Constructor<ControllerMixinClass> &
18
19
  Constructor<FieldMixinClass> &
19
20
  Constructor<LabelMixinClass> &
21
+ Constructor<SlotMixinClass> &
20
22
  Constructor<ValidateMixinClass>;
21
23
 
22
24
  export declare class FieldMixinClass {