@vaadin/checkbox-group 24.2.0-alpha1 → 24.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/checkbox-group",
3
- "version": "24.2.0-alpha1",
3
+ "version": "24.2.0-alpha10",
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-alpha1",
40
- "@vaadin/checkbox": "24.2.0-alpha1",
41
- "@vaadin/component-base": "24.2.0-alpha1",
42
- "@vaadin/field-base": "24.2.0-alpha1",
43
- "@vaadin/vaadin-lumo-styles": "24.2.0-alpha1",
44
- "@vaadin/vaadin-material-styles": "24.2.0-alpha1",
45
- "@vaadin/vaadin-themable-mixin": "24.2.0-alpha1"
39
+ "@vaadin/a11y-base": "24.2.0-alpha10",
40
+ "@vaadin/checkbox": "24.2.0-alpha10",
41
+ "@vaadin/component-base": "24.2.0-alpha10",
42
+ "@vaadin/field-base": "24.2.0-alpha10",
43
+ "@vaadin/vaadin-lumo-styles": "24.2.0-alpha10",
44
+ "@vaadin/vaadin-material-styles": "24.2.0-alpha10",
45
+ "@vaadin/vaadin-themable-mixin": "24.2.0-alpha10"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@esm-bundle/chai": "^4.3.4",
49
- "@vaadin/testing-helpers": "^0.4.2",
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": "0dbb118320203ab6c0c07450a3e718815367589f"
56
+ "gitHead": "ca16b5f88b00ae05fb6d7c7e9874525048e389f0"
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,12 @@
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';
11
10
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
11
+ import { SlotObserver } from '@vaadin/component-base/src/slot-observer.js';
12
12
  import { TooltipController } from '@vaadin/component-base/src/tooltip-controller.js';
13
13
  import { FieldMixin } from '@vaadin/field-base/src/field-mixin.js';
14
14
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
@@ -90,6 +90,11 @@ class CheckboxGroup extends FieldMixin(FocusMixin(DisabledMixin(ElementMixin(The
90
90
  width: 100%;
91
91
  }
92
92
 
93
+ [part='group-field'] {
94
+ display: flex;
95
+ flex-wrap: wrap;
96
+ }
97
+
93
98
  :host(:not([has-label])) [part='label'] {
94
99
  display: none;
95
100
  }
@@ -134,6 +139,19 @@ class CheckboxGroup extends FieldMixin(FocusMixin(DisabledMixin(ElementMixin(The
134
139
  notify: true,
135
140
  observer: '__valueChanged',
136
141
  },
142
+
143
+ /**
144
+ * Whether the field is dirty.
145
+ *
146
+ * The field is automatically marked as dirty once the user triggers
147
+ * a `change` event. Additionally, the field can be manually marked
148
+ * as dirty by setting the property to `true`.
149
+ */
150
+ dirty: {
151
+ type: Boolean,
152
+ value: false,
153
+ notify: true,
154
+ },
137
155
  };
138
156
  }
139
157
 
@@ -142,6 +160,7 @@ class CheckboxGroup extends FieldMixin(FocusMixin(DisabledMixin(ElementMixin(The
142
160
 
143
161
  this.__registerCheckbox = this.__registerCheckbox.bind(this);
144
162
  this.__unregisterCheckbox = this.__unregisterCheckbox.bind(this);
163
+ this.__onCheckboxChange = this.__onCheckboxChange.bind(this);
145
164
  this.__onCheckboxCheckedChanged = this.__onCheckboxCheckedChanged.bind(this);
146
165
  }
147
166
 
@@ -164,7 +183,8 @@ class CheckboxGroup extends FieldMixin(FocusMixin(DisabledMixin(ElementMixin(The
164
183
  // See https://github.com/vaadin/vaadin-web-components/issues/94
165
184
  this.setAttribute('role', 'group');
166
185
 
167
- this._observer = new FlattenedNodesObserver(this, ({ addedNodes, removedNodes }) => {
186
+ const slot = this.shadowRoot.querySelector('slot:not([name])');
187
+ this._observer = new SlotObserver(slot, ({ addedNodes, removedNodes }) => {
168
188
  const addedCheckboxes = this.__filterCheckboxes(addedNodes);
169
189
  const removedCheckboxes = this.__filterCheckboxes(removedNodes);
170
190
 
@@ -221,6 +241,7 @@ class CheckboxGroup extends FieldMixin(FocusMixin(DisabledMixin(ElementMixin(The
221
241
  * @private
222
242
  */
223
243
  __registerCheckbox(checkbox) {
244
+ checkbox.addEventListener('change', this.__onCheckboxChange);
224
245
  checkbox.addEventListener('checked-changed', this.__onCheckboxCheckedChanged);
225
246
 
226
247
  if (this.disabled) {
@@ -241,6 +262,7 @@ class CheckboxGroup extends FieldMixin(FocusMixin(DisabledMixin(ElementMixin(The
241
262
  * @private
242
263
  */
243
264
  __unregisterCheckbox(checkbox) {
265
+ checkbox.removeEventListener('change', this.__onCheckboxChange);
244
266
  checkbox.removeEventListener('checked-changed', this.__onCheckboxCheckedChanged);
245
267
 
246
268
  if (checkbox.checked) {
@@ -294,6 +316,11 @@ class CheckboxGroup extends FieldMixin(FocusMixin(DisabledMixin(ElementMixin(The
294
316
  }
295
317
  }
296
318
 
319
+ /** @private */
320
+ __onCheckboxChange() {
321
+ this.dirty = true;
322
+ }
323
+
297
324
  /**
298
325
  * @param {!CustomEvent} event
299
326
  * @private
@@ -354,7 +381,9 @@ class CheckboxGroup extends FieldMixin(FocusMixin(DisabledMixin(ElementMixin(The
354
381
  _setFocused(focused) {
355
382
  super._setFocused(focused);
356
383
 
357
- if (!focused) {
384
+ // Do not validate when focusout is caused by document
385
+ // losing focus, which happens on browser tab switch.
386
+ if (!focused && document.hasFocus()) {
358
387
  this.validate();
359
388
  }
360
389
  }
@@ -27,7 +27,6 @@ const checkboxGroup = css`
27
27
  }
28
28
 
29
29
  :host([theme~='vertical']) [part='group-field'] {
30
- display: flex;
31
30
  flex-direction: column;
32
31
  }
33
32
 
@@ -27,7 +27,6 @@ const checkboxGroup = css`
27
27
  }
28
28
 
29
29
  :host([theme~='vertical']) [part='group-field'] {
30
- display: flex;
31
30
  flex-direction: column;
32
31
  }
33
32
 
package/web-types.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/checkbox-group",
4
- "version": "24.2.0-alpha1",
4
+ "version": "24.2.0-alpha10",
5
5
  "description-markup": "markdown",
6
6
  "contributions": {
7
7
  "html": {
@@ -98,6 +98,17 @@
98
98
  ]
99
99
  }
100
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
+ },
101
112
  {
102
113
  "name": "theme",
103
114
  "description": "The theme variants to apply to the component.",
@@ -208,6 +219,17 @@
208
219
  "Array.<string>"
209
220
  ]
210
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
+ }
211
233
  }
212
234
  ],
213
235
  "events": [
@@ -219,6 +241,10 @@
219
241
  "name": "value-changed",
220
242
  "description": "Fired when the `value` property changes."
221
243
  },
244
+ {
245
+ "name": "dirty-changed",
246
+ "description": "Fired when the `dirty` property changes."
247
+ },
222
248
  {
223
249
  "name": "invalid-changed",
224
250
  "description": "Fired when the `invalid` property changes."
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/checkbox-group",
4
- "version": "24.2.0-alpha1",
4
+ "version": "24.2.0-alpha10",
5
5
  "description-markup": "markdown",
6
6
  "framework": "lit",
7
7
  "framework-config": {
@@ -40,6 +40,13 @@
40
40
  "kind": "expression"
41
41
  }
42
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
+ },
43
50
  {
44
51
  "name": ".label",
45
52
  "description": "The label text for the input node.\nWhen no light dom defined via [slot=label], this value will be used.",
@@ -96,6 +103,13 @@
96
103
  "kind": "expression"
97
104
  }
98
105
  },
106
+ {
107
+ "name": "@dirty-changed",
108
+ "description": "Fired when the `dirty` property changes.",
109
+ "value": {
110
+ "kind": "expression"
111
+ }
112
+ },
99
113
  {
100
114
  "name": "@invalid-changed",
101
115
  "description": "Fired when the `invalid` property changes.",