@vaadin/field-base 24.0.0-rc2 → 24.1.0-alpha1

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/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export { CheckedMixin } from './src/checked-mixin.js';
2
- export { FieldAriaController } from './src/field-aria-controller.js';
3
2
  export { FieldMixin } from './src/field-mixin.js';
4
3
  export { InputController } from './src/input-controller.js';
5
4
  export { InputControlMixin } from './src/input-control-mixin.js';
package/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  export { CheckedMixin } from './src/checked-mixin.js';
2
- export { FieldAriaController } from './src/field-aria-controller.js';
3
2
  export { FieldMixin } from './src/field-mixin.js';
4
3
  export { InputController } from './src/input-controller.js';
5
4
  export { InputControlMixin } from './src/input-control-mixin.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/field-base",
3
- "version": "24.0.0-rc2",
3
+ "version": "24.1.0-alpha1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -32,7 +32,8 @@
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-rc2",
35
+ "@vaadin/a11y-base": "24.1.0-alpha1",
36
+ "@vaadin/component-base": "24.1.0-alpha1",
36
37
  "lit": "^2.0.0"
37
38
  },
38
39
  "devDependencies": {
@@ -40,5 +41,5 @@
40
41
  "@vaadin/testing-helpers": "^0.4.0",
41
42
  "sinon": "^13.0.2"
42
43
  },
43
- "gitHead": "7601e71eaf22c45309852d5d491e0e01bb6322f0"
44
+ "gitHead": "599a339181595923b9ad6373d6888d8a79540141"
44
45
  }
@@ -4,8 +4,8 @@
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { Constructor } from '@open-wc/dedupe-mixin';
7
+ import type { DisabledMixinClass } from '@vaadin/a11y-base/src/disabled-mixin.js';
7
8
  import type { DelegateStateMixinClass } from '@vaadin/component-base/src/delegate-state-mixin.js';
8
- import type { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
9
9
  import type { InputMixinClass } from './input-mixin.js';
10
10
 
11
11
  /**
@@ -4,9 +4,9 @@
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/a11y-base/src/disabled-mixin.js';
8
+ import { isElementFocused } from '@vaadin/a11y-base/src/focus-utils.js';
7
9
  import { DelegateStateMixin } from '@vaadin/component-base/src/delegate-state-mixin.js';
8
- import { DisabledMixin } from '@vaadin/component-base/src/disabled-mixin.js';
9
- import { isElementFocused } from '@vaadin/component-base/src/focus-utils.js';
10
10
  import { InputMixin } from './input-mixin.js';
11
11
 
12
12
  /**
@@ -4,8 +4,8 @@
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { Constructor } from '@open-wc/dedupe-mixin';
7
+ import type { KeyboardMixinClass } from '@vaadin/a11y-base/src/keyboard-mixin.js';
7
8
  import type { ControllerMixinClass } from '@vaadin/component-base/src/controller-mixin.js';
8
- import type { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js';
9
9
  import type { InputMixinClass } from './input-mixin.js';
10
10
 
11
11
  /**
@@ -13,7 +13,11 @@ import type { InputMixinClass } from './input-mixin.js';
13
13
  */
14
14
  export declare function ClearButtonMixin<T extends Constructor<HTMLElement>>(
15
15
  base: T,
16
- ): Constructor<ClearButtonMixinClass> & Constructor<InputMixinClass> & Constructor<KeyboardMixinClass> & T;
16
+ ): Constructor<ClearButtonMixinClass> &
17
+ Constructor<ControllerMixinClass> &
18
+ Constructor<InputMixinClass> &
19
+ Constructor<KeyboardMixinClass> &
20
+ T;
17
21
 
18
22
  export declare class ClearButtonMixinClass {
19
23
  /**
@@ -3,7 +3,7 @@
3
3
  * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { KeyboardMixin } from '@vaadin/component-base/src/keyboard-mixin.js';
6
+ import { KeyboardMixin } from '@vaadin/a11y-base/src/keyboard-mixin.js';
7
7
  import { InputMixin } from './input-mixin.js';
8
8
 
9
9
  /**
@@ -3,9 +3,9 @@
3
3
  * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
+ import { FieldAriaController } from '@vaadin/a11y-base/src/field-aria-controller.js';
6
7
  import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
7
8
  import { ErrorController } from './error-controller.js';
8
- import { FieldAriaController } from './field-aria-controller.js';
9
9
  import { HelperController } from './helper-controller.js';
10
10
  import { LabelMixin } from './label-mixin.js';
11
11
  import { ValidateMixin } from './validate-mixin.js';
@@ -4,12 +4,12 @@
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { Constructor } from '@open-wc/dedupe-mixin';
7
+ import type { DelegateFocusMixinClass } from '@vaadin/a11y-base/src/delegate-focus-mixin.js';
8
+ import type { DisabledMixinClass } from '@vaadin/a11y-base/src/disabled-mixin.js';
9
+ import type { FocusMixinClass } from '@vaadin/a11y-base/src/focus-mixin.js';
10
+ import type { KeyboardMixinClass } from '@vaadin/a11y-base/src/keyboard-mixin.js';
7
11
  import type { ControllerMixinClass } from '@vaadin/component-base/src/controller-mixin.js';
8
- import type { DelegateFocusMixinClass } from '@vaadin/component-base/src/delegate-focus-mixin.js';
9
12
  import type { DelegateStateMixinClass } from '@vaadin/component-base/src/delegate-state-mixin.js';
10
- import type { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
11
- import type { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js';
12
- import type { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js';
13
13
  import type { ClearButtonMixinClass } from './clear-button-mixin.js';
14
14
  import type { FieldMixinClass } from './field-mixin.js';
15
15
  import type { InputConstraintsMixinClass } from './input-constraints-mixin.js';
@@ -3,10 +3,10 @@
3
3
  * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
+ import { DelegateFocusMixin } from '@vaadin/a11y-base/src/delegate-focus-mixin.js';
7
+ import { KeyboardMixin } from '@vaadin/a11y-base/src/keyboard-mixin.js';
6
8
  import { timeOut } from '@vaadin/component-base/src/async.js';
7
9
  import { Debouncer } from '@vaadin/component-base/src/debounce.js';
8
- import { DelegateFocusMixin } from '@vaadin/component-base/src/delegate-focus-mixin.js';
9
- import { KeyboardMixin } from '@vaadin/component-base/src/keyboard-mixin.js';
10
10
  import { ClearButtonMixin } from './clear-button-mixin.js';
11
11
  import { FieldMixin } from './field-mixin.js';
12
12
  import { InputConstraintsMixin } from './input-constraints-mixin.js';
@@ -4,12 +4,12 @@
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { Constructor } from '@open-wc/dedupe-mixin';
7
+ import type { DelegateFocusMixinClass } from '@vaadin/a11y-base/src/delegate-focus-mixin.js';
8
+ import type { DisabledMixinClass } from '@vaadin/a11y-base/src/disabled-mixin.js';
9
+ import type { FocusMixinClass } from '@vaadin/a11y-base/src/focus-mixin.js';
10
+ import type { KeyboardMixinClass } from '@vaadin/a11y-base/src/keyboard-mixin.js';
7
11
  import type { ControllerMixinClass } from '@vaadin/component-base/src/controller-mixin.js';
8
- import type { DelegateFocusMixinClass } from '@vaadin/component-base/src/delegate-focus-mixin.js';
9
12
  import type { DelegateStateMixinClass } from '@vaadin/component-base/src/delegate-state-mixin.js';
10
- import type { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
11
- import type { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js';
12
- import type { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js';
13
13
  import type { ClearButtonMixinClass } from './clear-button-mixin.js';
14
14
  import type { FieldMixinClass } from './field-mixin.js';
15
15
  import type { InputConstraintsMixinClass } from './input-constraints-mixin.js';
@@ -34,6 +34,18 @@ export declare class InputMixinClass {
34
34
  */
35
35
  protected readonly _hasValue: boolean;
36
36
 
37
+ /**
38
+ * A property for accessing the input element's value.
39
+ *
40
+ * Override this getter if the property is different from the default `value` one.
41
+ */
42
+ protected readonly _inputElementValueProperty: string;
43
+
44
+ /**
45
+ * The input element's value.
46
+ */
47
+ protected _inputElementValue: string | undefined;
48
+
37
49
  /**
38
50
  * Clear the value of the field.
39
51
  */
@@ -86,6 +86,39 @@ export const InputMixin = dedupingMixin(
86
86
  return this.value != null && this.value !== '';
87
87
  }
88
88
 
89
+ /**
90
+ * A property for accessing the input element's value.
91
+ *
92
+ * Override this getter if the property is different from the default `value` one.
93
+ *
94
+ * @protected
95
+ * @return {string}
96
+ */
97
+ get _inputElementValueProperty() {
98
+ return 'value';
99
+ }
100
+
101
+ /**
102
+ * The input element's value.
103
+ *
104
+ * @protected
105
+ * @return {string}
106
+ */
107
+ get _inputElementValue() {
108
+ return this.inputElement ? this.inputElement[this._inputElementValueProperty] : undefined;
109
+ }
110
+
111
+ /**
112
+ * The input element's value.
113
+ *
114
+ * @protected
115
+ */
116
+ set _inputElementValue(value) {
117
+ if (this.inputElement) {
118
+ this.inputElement[this._inputElementValueProperty] = value;
119
+ }
120
+ }
121
+
89
122
  /**
90
123
  * Clear the value of the field.
91
124
  */
@@ -96,9 +129,7 @@ export const InputMixin = dedupingMixin(
96
129
 
97
130
  // Clear the input immediately without waiting for the observer.
98
131
  // Otherwise, when using Lit, the old value would be restored.
99
- if (this.inputElement) {
100
- this.inputElement.value = '';
101
- }
132
+ this._inputElementValue = '';
102
133
  }
103
134
 
104
135
  /**
@@ -138,11 +169,7 @@ export const InputMixin = dedupingMixin(
138
169
  return;
139
170
  }
140
171
 
141
- if (value != null) {
142
- this.inputElement.value = value;
143
- } else {
144
- this.inputElement.value = '';
145
- }
172
+ this._inputElementValue = value != null ? value : '';
146
173
  }
147
174
 
148
175
  /**
@@ -1,56 +0,0 @@
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
-
7
- /**
8
- * A controller for managing ARIA attributes for a field element:
9
- * either the component itself or slotted `<input>` element.
10
- */
11
- export class FieldAriaController {
12
- /**
13
- * The controller host element.
14
- */
15
- host: HTMLElement;
16
-
17
- constructor(host: HTMLElement);
18
-
19
- /**
20
- * Sets a target element to which ARIA attributes are added.
21
- */
22
- setTarget(target: HTMLElement): void;
23
-
24
- /**
25
- * Toggles the `aria-required` attribute on the target element
26
- * if the target is the host component (e.g. a field group).
27
- * Otherwise, it does nothing.
28
- */
29
- setRequired(required: boolean): void;
30
-
31
- /**
32
- * Links the target element with a slotted label element
33
- * via the target's attribute `aria-labelledby`.
34
- *
35
- * To unlink the previous slotted label element, pass `null` as `labelId`.
36
- */
37
- setLabelId(labelId: string | null): void;
38
-
39
- /**
40
- * Links the target element with a slotted error element via the target's attribute:
41
- * - `aria-labelledby` if the target is the host component (e.g a field group).
42
- * - `aria-describedby` otherwise.
43
- *
44
- * To unlink the previous slotted error element, pass `null` as `errorId`.
45
- */
46
- setErrorId(errorId: string | null): void;
47
-
48
- /**
49
- * Links the target element with a slotted helper element via the target's attribute:
50
- * - `aria-labelledby` if the target is the host component (e.g a field group).
51
- * - `aria-describedby` otherwise.
52
- *
53
- * To unlink the previous slotted helper element, pass `null` as `helperId`.
54
- */
55
- setHelperId(helperId: string | null): void;
56
- }
@@ -1,172 +0,0 @@
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 { addValueToAttribute, removeValueFromAttribute } from '@vaadin/component-base/src/dom-utils.js';
7
-
8
- /**
9
- * A controller for managing ARIA attributes for a field element:
10
- * either the component itself or slotted `<input>` element.
11
- */
12
- export class FieldAriaController {
13
- constructor(host) {
14
- this.host = host;
15
- this.__required = false;
16
- }
17
-
18
- /**
19
- * `true` if the target element is the host component itself, `false` otherwise.
20
- *
21
- * @return {boolean}
22
- * @private
23
- */
24
- get __isGroupField() {
25
- return this.__target === this.host;
26
- }
27
-
28
- /**
29
- * Sets a target element to which ARIA attributes are added.
30
- *
31
- * @param {HTMLElement} target
32
- */
33
- setTarget(target) {
34
- this.__target = target;
35
- this.__setAriaRequiredAttribute(this.__required);
36
- this.__setLabelIdToAriaAttribute(this.__labelId);
37
- this.__setErrorIdToAriaAttribute(this.__errorId);
38
- this.__setHelperIdToAriaAttribute(this.__helperId);
39
- }
40
-
41
- /**
42
- * Toggles the `aria-required` attribute on the target element
43
- * if the target is the host component (e.g. a field group).
44
- * Otherwise, it does nothing.
45
- *
46
- * @param {boolean} required
47
- */
48
- setRequired(required) {
49
- this.__setAriaRequiredAttribute(required);
50
- this.__required = required;
51
- }
52
-
53
- /**
54
- * Links the target element with a slotted label element
55
- * via the target's attribute `aria-labelledby`.
56
- *
57
- * To unlink the previous slotted label element, pass `null` as `labelId`.
58
- *
59
- * @param {string | null} labelId
60
- */
61
- setLabelId(labelId) {
62
- this.__setLabelIdToAriaAttribute(labelId, this.__labelId);
63
- this.__labelId = labelId;
64
- }
65
-
66
- /**
67
- * Links the target element with a slotted error element via the target's attribute:
68
- * - `aria-labelledby` if the target is the host component (e.g a field group).
69
- * - `aria-describedby` otherwise.
70
- *
71
- * To unlink the previous slotted error element, pass `null` as `errorId`.
72
- *
73
- * @param {string | null} errorId
74
- */
75
- setErrorId(errorId) {
76
- this.__setErrorIdToAriaAttribute(errorId, this.__errorId);
77
- this.__errorId = errorId;
78
- }
79
-
80
- /**
81
- * Links the target element with a slotted helper element via the target's attribute:
82
- * - `aria-labelledby` if the target is the host component (e.g a field group).
83
- * - `aria-describedby` otherwise.
84
- *
85
- * To unlink the previous slotted helper element, pass `null` as `helperId`.
86
- *
87
- * @param {string | null} helperId
88
- */
89
- setHelperId(helperId) {
90
- this.__setHelperIdToAriaAttribute(helperId, this.__helperId);
91
- this.__helperId = helperId;
92
- }
93
-
94
- /**
95
- * @param {string | null | undefined} labelId
96
- * @param {string | null | undefined} oldLabelId
97
- * @private
98
- */
99
- __setLabelIdToAriaAttribute(labelId, oldLabelId) {
100
- this.__setAriaAttributeId('aria-labelledby', labelId, oldLabelId);
101
- }
102
-
103
- /**
104
- * @param {string | null | undefined} errorId
105
- * @param {string | null | undefined} oldErrorId
106
- * @private
107
- */
108
- __setErrorIdToAriaAttribute(errorId, oldErrorId) {
109
- // For groups, add all IDs to aria-labelledby rather than aria-describedby -
110
- // that should guarantee that it's announced when the group is entered.
111
- if (this.__isGroupField) {
112
- this.__setAriaAttributeId('aria-labelledby', errorId, oldErrorId);
113
- } else {
114
- this.__setAriaAttributeId('aria-describedby', errorId, oldErrorId);
115
- }
116
- }
117
-
118
- /**
119
- * @param {string | null | undefined} helperId
120
- * @param {string | null | undefined} oldHelperId
121
- * @private
122
- */
123
- __setHelperIdToAriaAttribute(helperId, oldHelperId) {
124
- // For groups, add all IDs to aria-labelledby rather than aria-describedby -
125
- // that should guarantee that it's announced when the group is entered.
126
- if (this.__isGroupField) {
127
- this.__setAriaAttributeId('aria-labelledby', helperId, oldHelperId);
128
- } else {
129
- this.__setAriaAttributeId('aria-describedby', helperId, oldHelperId);
130
- }
131
- }
132
-
133
- /**
134
- * @param {boolean} required
135
- * @private
136
- */
137
- __setAriaRequiredAttribute(required) {
138
- if (!this.__target) {
139
- return;
140
- }
141
-
142
- if (['input', 'textarea'].includes(this.__target.localName)) {
143
- // Native <input> or <textarea>, required is enough
144
- return;
145
- }
146
-
147
- if (required) {
148
- this.__target.setAttribute('aria-required', 'true');
149
- } else {
150
- this.__target.removeAttribute('aria-required');
151
- }
152
- }
153
-
154
- /**
155
- * @param {string | null | undefined} newId
156
- * @param {string | null | undefined} oldId
157
- * @private
158
- */
159
- __setAriaAttributeId(attr, newId, oldId) {
160
- if (!this.__target) {
161
- return;
162
- }
163
-
164
- if (oldId) {
165
- removeValueFromAttribute(this.__target, attr, oldId);
166
- }
167
-
168
- if (newId) {
169
- addValueToAttribute(this.__target, attr, newId);
170
- }
171
- }
172
- }