@vaadin/checkbox-group 24.2.0-dev.f254716fe → 24.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/checkbox-group",
3
- "version": "24.2.0-dev.f254716fe",
3
+ "version": "24.3.0-alpha1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -36,22 +36,22 @@
36
36
  ],
37
37
  "dependencies": {
38
38
  "@polymer/polymer": "^3.0.0",
39
- "@vaadin/a11y-base": "24.2.0-dev.f254716fe",
40
- "@vaadin/checkbox": "24.2.0-dev.f254716fe",
41
- "@vaadin/component-base": "24.2.0-dev.f254716fe",
42
- "@vaadin/field-base": "24.2.0-dev.f254716fe",
43
- "@vaadin/vaadin-lumo-styles": "24.2.0-dev.f254716fe",
44
- "@vaadin/vaadin-material-styles": "24.2.0-dev.f254716fe",
45
- "@vaadin/vaadin-themable-mixin": "24.2.0-dev.f254716fe"
39
+ "@vaadin/a11y-base": "24.3.0-alpha1",
40
+ "@vaadin/checkbox": "24.3.0-alpha1",
41
+ "@vaadin/component-base": "24.3.0-alpha1",
42
+ "@vaadin/field-base": "24.3.0-alpha1",
43
+ "@vaadin/vaadin-lumo-styles": "24.3.0-alpha1",
44
+ "@vaadin/vaadin-material-styles": "24.3.0-alpha1",
45
+ "@vaadin/vaadin-themable-mixin": "24.3.0-alpha1"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@esm-bundle/chai": "^4.3.4",
49
- "@vaadin/testing-helpers": "^0.4.3",
49
+ "@vaadin/testing-helpers": "^0.5.0",
50
50
  "sinon": "^13.0.2"
51
51
  },
52
52
  "web-types": [
53
53
  "web-types.json",
54
54
  "web-types.lit.json"
55
55
  ],
56
- "gitHead": "da54950b9f8c14c6451ede0d426e16a489c7fb9b"
56
+ "gitHead": "9ca6f3ca220a777e8eea181a1f5717e39a732240"
57
57
  }
@@ -14,6 +14,11 @@ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mix
14
14
  */
15
15
  export type CheckboxGroupInvalidChangedEvent = CustomEvent<{ value: boolean }>;
16
16
 
17
+ /**
18
+ * Fired when the `dirty` property changes.
19
+ */
20
+ export type CheckboxGroupDirtyChangedEvent = CustomEvent<{ value: boolean }>;
21
+
17
22
  /**
18
23
  * Fired when the `value` property changes.
19
24
  */
@@ -27,6 +32,8 @@ export type CheckboxGroupValidatedEvent = CustomEvent<{ valid: boolean }>;
27
32
  export interface CheckboxGroupCustomEventMap {
28
33
  'invalid-changed': CheckboxGroupInvalidChangedEvent;
29
34
 
35
+ 'dirty-changed': CheckboxGroupDirtyChangedEvent;
36
+
30
37
  'value-changed': CheckboxGroupValueChangedEvent;
31
38
 
32
39
  validated: CheckboxGroupValidatedEvent;
@@ -73,6 +80,7 @@ export interface CheckboxGroupEventMap extends HTMLElementEventMap, CheckboxGrou
73
80
  * See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.
74
81
  *
75
82
  * @fires {CustomEvent} invalid-changed - Fired when the `invalid` property changes.
83
+ * @fires {CustomEvent} dirty-changed - Fired when the `dirty` property changes.
76
84
  * @fires {CustomEvent} value-changed - Fired when the `value` property changes.
77
85
  * @fires {CustomEvent} validated - Fired whenever the field is validated.
78
86
  */
@@ -85,6 +93,15 @@ declare class CheckboxGroup extends FieldMixin(FocusMixin(DisabledMixin(ElementM
85
93
  */
86
94
  value: string[];
87
95
 
96
+ /**
97
+ * Whether the field is dirty.
98
+ *
99
+ * The field is automatically marked as dirty once the user triggers
100
+ * a `change` event. Additionally, the field can be manually marked
101
+ * as dirty by setting the property to `true`.
102
+ */
103
+ dirty: boolean;
104
+
88
105
  addEventListener<K extends keyof CheckboxGroupEventMap>(
89
106
  type: K,
90
107
  listener: (this: CheckboxGroup, ev: CheckboxGroupEventMap[K]) => void,
@@ -3,12 +3,13 @@
3
3
  * Copyright (c) 2018 - 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 { FlattenedNodesObserver } from '@polymer/polymer/lib/utils/flattened-nodes-observer.js';
7
6
  import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
8
7
  import { DisabledMixin } from '@vaadin/a11y-base/src/disabled-mixin.js';
9
8
  import { FocusMixin } from '@vaadin/a11y-base/src/focus-mixin.js';
10
9
  import { Checkbox } from '@vaadin/checkbox/src/vaadin-checkbox.js';
10
+ import { defineCustomElement } from '@vaadin/component-base/src/define.js';
11
11
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
12
+ import { SlotObserver } from '@vaadin/component-base/src/slot-observer.js';
12
13
  import { TooltipController } from '@vaadin/component-base/src/tooltip-controller.js';
13
14
  import { FieldMixin } from '@vaadin/field-base/src/field-mixin.js';
14
15
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
@@ -55,6 +56,7 @@ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mix
55
56
  * @fires {CustomEvent} value-changed - Fired when the `value` property changes.
56
57
  * @fires {CustomEvent} validated - Fired whenever the field is validated.
57
58
  *
59
+ * @customElement
58
60
  * @extends HTMLElement
59
61
  * @mixes ThemableMixin
60
62
  * @mixes DisabledMixin
@@ -139,6 +141,19 @@ class CheckboxGroup extends FieldMixin(FocusMixin(DisabledMixin(ElementMixin(The
139
141
  notify: true,
140
142
  observer: '__valueChanged',
141
143
  },
144
+
145
+ /**
146
+ * Whether the field is dirty.
147
+ *
148
+ * The field is automatically marked as dirty once the user triggers
149
+ * a `change` event. Additionally, the field can be manually marked
150
+ * as dirty by setting the property to `true`.
151
+ */
152
+ dirty: {
153
+ type: Boolean,
154
+ value: false,
155
+ notify: true,
156
+ },
142
157
  };
143
158
  }
144
159
 
@@ -147,7 +162,21 @@ class CheckboxGroup extends FieldMixin(FocusMixin(DisabledMixin(ElementMixin(The
147
162
 
148
163
  this.__registerCheckbox = this.__registerCheckbox.bind(this);
149
164
  this.__unregisterCheckbox = this.__unregisterCheckbox.bind(this);
165
+ this.__onCheckboxChange = this.__onCheckboxChange.bind(this);
150
166
  this.__onCheckboxCheckedChanged = this.__onCheckboxCheckedChanged.bind(this);
167
+
168
+ this._tooltipController = new TooltipController(this);
169
+ this._tooltipController.addEventListener('tooltip-changed', (event) => {
170
+ const tooltip = event.detail.node;
171
+ if (tooltip && tooltip.isConnected) {
172
+ // Tooltip element has been added to the DOM
173
+ const inputs = this.__checkboxes.map((checkbox) => checkbox.inputElement);
174
+ this._tooltipController.setAriaTarget(inputs);
175
+ } else {
176
+ // Tooltip element is no longer connected
177
+ this._tooltipController.setAriaTarget([]);
178
+ }
179
+ });
151
180
  }
152
181
 
153
182
  /**
@@ -169,17 +198,20 @@ class CheckboxGroup extends FieldMixin(FocusMixin(DisabledMixin(ElementMixin(The
169
198
  // See https://github.com/vaadin/vaadin-web-components/issues/94
170
199
  this.setAttribute('role', 'group');
171
200
 
172
- this._observer = new FlattenedNodesObserver(this, ({ addedNodes, removedNodes }) => {
201
+ const slot = this.shadowRoot.querySelector('slot:not([name])');
202
+ this._observer = new SlotObserver(slot, ({ addedNodes, removedNodes }) => {
173
203
  const addedCheckboxes = this.__filterCheckboxes(addedNodes);
174
204
  const removedCheckboxes = this.__filterCheckboxes(removedNodes);
175
205
 
176
206
  addedCheckboxes.forEach(this.__registerCheckbox);
177
207
  removedCheckboxes.forEach(this.__unregisterCheckbox);
178
208
 
209
+ const inputs = this.__checkboxes.map((checkbox) => checkbox.inputElement);
210
+ this._tooltipController.setAriaTarget(inputs);
211
+
179
212
  this.__warnOfCheckboxesWithoutValue(addedCheckboxes);
180
213
  });
181
214
 
182
- this._tooltipController = new TooltipController(this);
183
215
  this.addController(this._tooltipController);
184
216
  }
185
217
 
@@ -226,6 +258,7 @@ class CheckboxGroup extends FieldMixin(FocusMixin(DisabledMixin(ElementMixin(The
226
258
  * @private
227
259
  */
228
260
  __registerCheckbox(checkbox) {
261
+ checkbox.addEventListener('change', this.__onCheckboxChange);
229
262
  checkbox.addEventListener('checked-changed', this.__onCheckboxCheckedChanged);
230
263
 
231
264
  if (this.disabled) {
@@ -246,6 +279,7 @@ class CheckboxGroup extends FieldMixin(FocusMixin(DisabledMixin(ElementMixin(The
246
279
  * @private
247
280
  */
248
281
  __unregisterCheckbox(checkbox) {
282
+ checkbox.removeEventListener('change', this.__onCheckboxChange);
249
283
  checkbox.removeEventListener('checked-changed', this.__onCheckboxCheckedChanged);
250
284
 
251
285
  if (checkbox.checked) {
@@ -299,6 +333,11 @@ class CheckboxGroup extends FieldMixin(FocusMixin(DisabledMixin(ElementMixin(The
299
333
  }
300
334
  }
301
335
 
336
+ /** @private */
337
+ __onCheckboxChange() {
338
+ this.dirty = true;
339
+ }
340
+
302
341
  /**
303
342
  * @param {!CustomEvent} event
304
343
  * @private
@@ -367,6 +406,6 @@ class CheckboxGroup extends FieldMixin(FocusMixin(DisabledMixin(ElementMixin(The
367
406
  }
368
407
  }
369
408
 
370
- customElements.define(CheckboxGroup.is, CheckboxGroup);
409
+ defineCustomElement(CheckboxGroup);
371
410
 
372
411
  export { CheckboxGroup };
package/web-types.json ADDED
@@ -0,0 +1,258 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/web-types",
3
+ "name": "@vaadin/checkbox-group",
4
+ "version": "24.3.0-alpha1",
5
+ "description-markup": "markdown",
6
+ "contributions": {
7
+ "html": {
8
+ "elements": [
9
+ {
10
+ "name": "vaadin-checkbox-group",
11
+ "description": "`<vaadin-checkbox-group>` is a web component that allows the user to choose several items from a group of binary choices.\n\n```html\n<vaadin-checkbox-group label=\"Export data\">\n <vaadin-checkbox value=\"0\" label=\"Order ID\"></vaadin-checkbox>\n <vaadin-checkbox value=\"1\" label=\"Product name\"></vaadin-checkbox>\n <vaadin-checkbox value=\"2\" label=\"Customer\"></vaadin-checkbox>\n <vaadin-checkbox value=\"3\" label=\"Status\"></vaadin-checkbox>\n</vaadin-checkbox-group>\n```\n\n### Styling\n\nThe following shadow DOM parts are available for styling:\n\nPart name | Description\n---------------------|----------------\n`label` | The slotted label element wrapper\n`group-field` | The checkbox elements wrapper\n`helper-text` | The slotted helper text element wrapper\n`error-message` | The slotted error message element wrapper\n`required-indicator` | The `required` state indicator element\n\nThe following state attributes are available for styling:\n\nAttribute | Description | Part name\n--------------------|-------------------------------------------|------------\n`disabled` | Set when the element is disabled | :host\n`invalid` | Set when the element is invalid | :host\n`focused` | Set when the element is focused | :host\n`has-label` | Set when the element has a label | :host\n`has-value` | Set when the element has a value | :host\n`has-helper` | Set when the element has helper text | :host\n`has-error-message` | Set when the element has an error message | :host\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.",
12
+ "attributes": [
13
+ {
14
+ "name": "disabled",
15
+ "description": "If true, the user cannot interact with this element.",
16
+ "value": {
17
+ "type": [
18
+ "boolean",
19
+ "null",
20
+ "undefined"
21
+ ]
22
+ }
23
+ },
24
+ {
25
+ "name": "label",
26
+ "description": "The label text for the input node.\nWhen no light dom defined via [slot=label], this value will be used.",
27
+ "value": {
28
+ "type": [
29
+ "string",
30
+ "null",
31
+ "undefined"
32
+ ]
33
+ }
34
+ },
35
+ {
36
+ "name": "invalid",
37
+ "description": "Set to true when the field is invalid.",
38
+ "value": {
39
+ "type": [
40
+ "boolean",
41
+ "null",
42
+ "undefined"
43
+ ]
44
+ }
45
+ },
46
+ {
47
+ "name": "required",
48
+ "description": "Specifies that the user must fill in a value.",
49
+ "value": {
50
+ "type": [
51
+ "boolean",
52
+ "null",
53
+ "undefined"
54
+ ]
55
+ }
56
+ },
57
+ {
58
+ "name": "error-message",
59
+ "description": "Error to show when the field is invalid.",
60
+ "value": {
61
+ "type": [
62
+ "string",
63
+ "null",
64
+ "undefined"
65
+ ]
66
+ }
67
+ },
68
+ {
69
+ "name": "helper-text",
70
+ "description": "String used for the helper text.",
71
+ "value": {
72
+ "type": [
73
+ "string",
74
+ "null",
75
+ "undefined"
76
+ ]
77
+ }
78
+ },
79
+ {
80
+ "name": "accessible-name",
81
+ "description": "String used to label the component to screen reader users.",
82
+ "value": {
83
+ "type": [
84
+ "string",
85
+ "null",
86
+ "undefined"
87
+ ]
88
+ }
89
+ },
90
+ {
91
+ "name": "accessible-name-ref",
92
+ "description": "Id of the element used as label of the component to screen reader users.",
93
+ "value": {
94
+ "type": [
95
+ "string",
96
+ "null",
97
+ "undefined"
98
+ ]
99
+ }
100
+ },
101
+ {
102
+ "name": "dirty",
103
+ "description": "Whether the field is dirty.\n\nThe field is automatically marked as dirty once the user triggers\na `change` event. Additionally, the field can be manually marked\nas dirty by setting the property to `true`.",
104
+ "value": {
105
+ "type": [
106
+ "boolean",
107
+ "null",
108
+ "undefined"
109
+ ]
110
+ }
111
+ },
112
+ {
113
+ "name": "theme",
114
+ "description": "The theme variants to apply to the component.",
115
+ "value": {
116
+ "type": [
117
+ "string",
118
+ "null",
119
+ "undefined"
120
+ ]
121
+ }
122
+ }
123
+ ],
124
+ "js": {
125
+ "properties": [
126
+ {
127
+ "name": "disabled",
128
+ "description": "If true, the user cannot interact with this element.",
129
+ "value": {
130
+ "type": [
131
+ "boolean",
132
+ "null",
133
+ "undefined"
134
+ ]
135
+ }
136
+ },
137
+ {
138
+ "name": "label",
139
+ "description": "The label text for the input node.\nWhen no light dom defined via [slot=label], this value will be used.",
140
+ "value": {
141
+ "type": [
142
+ "string",
143
+ "null",
144
+ "undefined"
145
+ ]
146
+ }
147
+ },
148
+ {
149
+ "name": "invalid",
150
+ "description": "Set to true when the field is invalid.",
151
+ "value": {
152
+ "type": [
153
+ "boolean",
154
+ "null",
155
+ "undefined"
156
+ ]
157
+ }
158
+ },
159
+ {
160
+ "name": "required",
161
+ "description": "Specifies that the user must fill in a value.",
162
+ "value": {
163
+ "type": [
164
+ "boolean",
165
+ "null",
166
+ "undefined"
167
+ ]
168
+ }
169
+ },
170
+ {
171
+ "name": "errorMessage",
172
+ "description": "Error to show when the field is invalid.",
173
+ "value": {
174
+ "type": [
175
+ "string",
176
+ "null",
177
+ "undefined"
178
+ ]
179
+ }
180
+ },
181
+ {
182
+ "name": "helperText",
183
+ "description": "String used for the helper text.",
184
+ "value": {
185
+ "type": [
186
+ "string",
187
+ "null",
188
+ "undefined"
189
+ ]
190
+ }
191
+ },
192
+ {
193
+ "name": "accessibleName",
194
+ "description": "String used to label the component to screen reader users.",
195
+ "value": {
196
+ "type": [
197
+ "string",
198
+ "null",
199
+ "undefined"
200
+ ]
201
+ }
202
+ },
203
+ {
204
+ "name": "accessibleNameRef",
205
+ "description": "Id of the element used as label of the component to screen reader users.",
206
+ "value": {
207
+ "type": [
208
+ "string",
209
+ "null",
210
+ "undefined"
211
+ ]
212
+ }
213
+ },
214
+ {
215
+ "name": "value",
216
+ "description": "An array containing values of the currently checked checkboxes.\n\nThe array is immutable so toggling checkboxes always results in\ncreating a new array.",
217
+ "value": {
218
+ "type": [
219
+ "Array.<string>"
220
+ ]
221
+ }
222
+ },
223
+ {
224
+ "name": "dirty",
225
+ "description": "Whether the field is dirty.\n\nThe field is automatically marked as dirty once the user triggers\na `change` event. Additionally, the field can be manually marked\nas dirty by setting the property to `true`.",
226
+ "value": {
227
+ "type": [
228
+ "boolean",
229
+ "null",
230
+ "undefined"
231
+ ]
232
+ }
233
+ }
234
+ ],
235
+ "events": [
236
+ {
237
+ "name": "validated",
238
+ "description": "Fired whenever the field is validated."
239
+ },
240
+ {
241
+ "name": "value-changed",
242
+ "description": "Fired when the `value` property changes."
243
+ },
244
+ {
245
+ "name": "dirty-changed",
246
+ "description": "Fired when the `dirty` property changes."
247
+ },
248
+ {
249
+ "name": "invalid-changed",
250
+ "description": "Fired when the `invalid` property changes."
251
+ }
252
+ ]
253
+ }
254
+ }
255
+ ]
256
+ }
257
+ }
258
+ }
@@ -0,0 +1,125 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/web-types",
3
+ "name": "@vaadin/checkbox-group",
4
+ "version": "24.3.0-alpha1",
5
+ "description-markup": "markdown",
6
+ "framework": "lit",
7
+ "framework-config": {
8
+ "enable-when": {
9
+ "node-packages": [
10
+ "lit"
11
+ ]
12
+ }
13
+ },
14
+ "contributions": {
15
+ "html": {
16
+ "elements": [
17
+ {
18
+ "name": "vaadin-checkbox-group",
19
+ "description": "`<vaadin-checkbox-group>` is a web component that allows the user to choose several items from a group of binary choices.\n\n```html\n<vaadin-checkbox-group label=\"Export data\">\n <vaadin-checkbox value=\"0\" label=\"Order ID\"></vaadin-checkbox>\n <vaadin-checkbox value=\"1\" label=\"Product name\"></vaadin-checkbox>\n <vaadin-checkbox value=\"2\" label=\"Customer\"></vaadin-checkbox>\n <vaadin-checkbox value=\"3\" label=\"Status\"></vaadin-checkbox>\n</vaadin-checkbox-group>\n```\n\n### Styling\n\nThe following shadow DOM parts are available for styling:\n\nPart name | Description\n---------------------|----------------\n`label` | The slotted label element wrapper\n`group-field` | The checkbox elements wrapper\n`helper-text` | The slotted helper text element wrapper\n`error-message` | The slotted error message element wrapper\n`required-indicator` | The `required` state indicator element\n\nThe following state attributes are available for styling:\n\nAttribute | Description | Part name\n--------------------|-------------------------------------------|------------\n`disabled` | Set when the element is disabled | :host\n`invalid` | Set when the element is invalid | :host\n`focused` | Set when the element is focused | :host\n`has-label` | Set when the element has a label | :host\n`has-value` | Set when the element has a value | :host\n`has-helper` | Set when the element has helper text | :host\n`has-error-message` | Set when the element has an error message | :host\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.",
20
+ "extension": true,
21
+ "attributes": [
22
+ {
23
+ "name": "?disabled",
24
+ "description": "If true, the user cannot interact with this element.",
25
+ "value": {
26
+ "kind": "expression"
27
+ }
28
+ },
29
+ {
30
+ "name": "?invalid",
31
+ "description": "Set to true when the field is invalid.",
32
+ "value": {
33
+ "kind": "expression"
34
+ }
35
+ },
36
+ {
37
+ "name": "?required",
38
+ "description": "Specifies that the user must fill in a value.",
39
+ "value": {
40
+ "kind": "expression"
41
+ }
42
+ },
43
+ {
44
+ "name": "?dirty",
45
+ "description": "Whether the field is dirty.\n\nThe field is automatically marked as dirty once the user triggers\na `change` event. Additionally, the field can be manually marked\nas dirty by setting the property to `true`.",
46
+ "value": {
47
+ "kind": "expression"
48
+ }
49
+ },
50
+ {
51
+ "name": ".label",
52
+ "description": "The label text for the input node.\nWhen no light dom defined via [slot=label], this value will be used.",
53
+ "value": {
54
+ "kind": "expression"
55
+ }
56
+ },
57
+ {
58
+ "name": ".errorMessage",
59
+ "description": "Error to show when the field is invalid.",
60
+ "value": {
61
+ "kind": "expression"
62
+ }
63
+ },
64
+ {
65
+ "name": ".helperText",
66
+ "description": "String used for the helper text.",
67
+ "value": {
68
+ "kind": "expression"
69
+ }
70
+ },
71
+ {
72
+ "name": ".accessibleName",
73
+ "description": "String used to label the component to screen reader users.",
74
+ "value": {
75
+ "kind": "expression"
76
+ }
77
+ },
78
+ {
79
+ "name": ".accessibleNameRef",
80
+ "description": "Id of the element used as label of the component to screen reader users.",
81
+ "value": {
82
+ "kind": "expression"
83
+ }
84
+ },
85
+ {
86
+ "name": ".value",
87
+ "description": "An array containing values of the currently checked checkboxes.\n\nThe array is immutable so toggling checkboxes always results in\ncreating a new array.",
88
+ "value": {
89
+ "kind": "expression"
90
+ }
91
+ },
92
+ {
93
+ "name": "@validated",
94
+ "description": "Fired whenever the field is validated.",
95
+ "value": {
96
+ "kind": "expression"
97
+ }
98
+ },
99
+ {
100
+ "name": "@value-changed",
101
+ "description": "Fired when the `value` property changes.",
102
+ "value": {
103
+ "kind": "expression"
104
+ }
105
+ },
106
+ {
107
+ "name": "@dirty-changed",
108
+ "description": "Fired when the `dirty` property changes.",
109
+ "value": {
110
+ "kind": "expression"
111
+ }
112
+ },
113
+ {
114
+ "name": "@invalid-changed",
115
+ "description": "Fired when the `invalid` property changes.",
116
+ "value": {
117
+ "kind": "expression"
118
+ }
119
+ }
120
+ ]
121
+ }
122
+ ]
123
+ }
124
+ }
125
+ }