@vaadin/field-base 24.0.5 → 24.1.0-alpha10

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.5",
3
+ "version": "24.1.0-alpha10",
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.5",
35
+ "@vaadin/a11y-base": "24.1.0-alpha10",
36
+ "@vaadin/component-base": "24.1.0-alpha10",
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": "e384c1b5c02e01a4382a433f727d075de9a4ee97"
44
+ "gitHead": "12e39be7eb3b49c68708e8ca3de2fb22e91051a1"
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
  /**
@@ -39,6 +39,18 @@ export declare class FieldMixinClass {
39
39
  */
40
40
  errorMessage: string | null | undefined;
41
41
 
42
+ /**
43
+ * String used to label the component to screen reader users.
44
+ * @attr {string} accessible-name
45
+ */
46
+ accessibleName: string | null | undefined;
47
+
48
+ /**
49
+ * Id of the element used as label of the component to screen reader users.
50
+ * @attr {string} accessible-name-ref
51
+ */
52
+ accessibleNameRef: string | null | undefined;
53
+
42
54
  protected readonly _errorNode: HTMLElement;
43
55
 
44
56
  protected readonly _helperNode?: HTMLElement;
@@ -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';
@@ -49,6 +49,24 @@ export const FieldMixin = (superclass) =>
49
49
  type: String,
50
50
  observer: '_helperTextChanged',
51
51
  },
52
+
53
+ /**
54
+ * String used to label the component to screen reader users.
55
+ * @attr {string} accessible-name
56
+ */
57
+ accessibleName: {
58
+ type: String,
59
+ observer: '_accessibleNameChanged',
60
+ },
61
+
62
+ /**
63
+ * Id of the element used as label of the component to screen reader users.
64
+ * @attr {string} accessible-name-ref
65
+ */
66
+ accessibleNameRef: {
67
+ type: String,
68
+ observer: '_accessibleNameRefChanged',
69
+ },
52
70
  };
53
71
  }
54
72
 
@@ -113,6 +131,16 @@ export const FieldMixin = (superclass) =>
113
131
  }
114
132
  }
115
133
 
134
+ /** @protected */
135
+ _accessibleNameChanged(accessibleName) {
136
+ this._fieldAriaController.setAriaLabel(accessibleName);
137
+ }
138
+
139
+ /** @protected */
140
+ _accessibleNameRefChanged(accessibleNameRef) {
141
+ this._fieldAriaController.setLabelId(accessibleNameRef, true);
142
+ }
143
+
116
144
  /** @private */
117
145
  __labelChanged(hasLabel, labelNode) {
118
146
  // Label ID should be only added when the label content is present.
@@ -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';
@@ -26,4 +26,17 @@ export const fieldShared = css`
26
26
  :host(:not([has-label])) [part='label'] {
27
27
  display: none;
28
28
  }
29
+
30
+ @media (forced-colors: active) {
31
+ :host(:not([readonly])) [part='input-field'] {
32
+ outline: 1px solid;
33
+ outline-offset: -1px;
34
+ }
35
+ :host([focused]) [part='input-field'] {
36
+ outline-width: 2px;
37
+ }
38
+ :host([disabled]) [part='input-field'] {
39
+ outline-color: GrayText;
40
+ }
41
+ }
29
42
  `;
@@ -0,0 +1,8 @@
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 { CSSResult } from 'lit';
7
+
8
+ export const screenReaderOnly: CSSResult;
@@ -0,0 +1,28 @@
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
+ * @note Taken from Gaël Poupard gist
9
+ * @author Gaël Poupard
10
+ * @see https://gist.github.com/ffoodd/000b59f431e3e64e4ce1a24d5bb36034
11
+ */
12
+ import { css } from 'lit';
13
+
14
+ export const screenReaderOnly = css`
15
+ .sr-only {
16
+ border: 0 !important;
17
+ clip: rect(1px, 1px, 1px, 1px) !important;
18
+ -webkit-clip-path: inset(50%) !important;
19
+ clip-path: inset(50%) !important;
20
+ height: 1px !important;
21
+ margin: -1px !important;
22
+ overflow: hidden !important;
23
+ padding: 0 !important;
24
+ position: absolute !important;
25
+ width: 1px !important;
26
+ white-space: nowrap !important;
27
+ }
28
+ `;
@@ -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
- }