@vaadin/field-base 23.2.0-alpha2 → 23.2.0-alpha3

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/field-base",
3
- "version": "23.2.0-alpha2",
3
+ "version": "23.2.0-alpha3",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -32,7 +32,7 @@
32
32
  "dependencies": {
33
33
  "@open-wc/dedupe-mixin": "^1.3.0",
34
34
  "@polymer/polymer": "^3.0.0",
35
- "@vaadin/component-base": "23.2.0-alpha2",
35
+ "@vaadin/component-base": "23.2.0-alpha3",
36
36
  "lit": "^2.0.0"
37
37
  },
38
38
  "devDependencies": {
@@ -40,5 +40,5 @@
40
40
  "@vaadin/testing-helpers": "^0.3.2",
41
41
  "sinon": "^13.0.2"
42
42
  },
43
- "gitHead": "c9b8113d0fa9a602f8b9cb915c1826355af2e8df"
43
+ "gitHead": "06e5875be93ca50da2846dafc65a8531010c0576"
44
44
  }
@@ -3,10 +3,10 @@
3
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
- import { Constructor } from '@open-wc/dedupe-mixin';
7
- import { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
8
- import { DelegateStateMixinClass } from './delegate-state-mixin.js';
9
- import { InputMixinClass } from './input-mixin.js';
6
+ import type { Constructor } from '@open-wc/dedupe-mixin';
7
+ import type { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
8
+ import type { DelegateStateMixinClass } from './delegate-state-mixin.js';
9
+ import type { InputMixinClass } from './input-mixin.js';
10
10
 
11
11
  /**
12
12
  * A mixin to manage the checked state.
@@ -3,10 +3,10 @@
3
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
- import { Constructor } from '@open-wc/dedupe-mixin';
7
- import { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
8
- import { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js';
9
- import { TabindexMixinClass } from '@vaadin/component-base/src/tabindex-mixin.js';
6
+ import type { Constructor } from '@open-wc/dedupe-mixin';
7
+ import type { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
8
+ import type { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js';
9
+ import type { TabindexMixinClass } from '@vaadin/component-base/src/tabindex-mixin.js';
10
10
 
11
11
  /**
12
12
  * A mixin to forward focus to an element in the light DOM.
@@ -3,7 +3,7 @@
3
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
- import { Constructor } from '@open-wc/dedupe-mixin';
6
+ import type { Constructor } from '@open-wc/dedupe-mixin';
7
7
 
8
8
  /**
9
9
  * A mixin to delegate properties and attributes to a target element.
@@ -3,10 +3,10 @@
3
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
- import { Constructor } from '@open-wc/dedupe-mixin';
7
- import { ControllerMixinClass } from '@vaadin/component-base/src/controller-mixin.js';
8
- import { LabelMixinClass } from './label-mixin.js';
9
- import { ValidateMixinClass } from './validate-mixin.js';
6
+ import type { Constructor } from '@open-wc/dedupe-mixin';
7
+ import type { ControllerMixinClass } from '@vaadin/component-base/src/controller-mixin.js';
8
+ import type { LabelMixinClass } from './label-mixin.js';
9
+ import type { ValidateMixinClass } from './validate-mixin.js';
10
10
 
11
11
  /**
12
12
  * A mixin to provide common field logic: label, error message and helper text.
@@ -3,11 +3,11 @@
3
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
- import { Constructor } from '@open-wc/dedupe-mixin';
7
- import { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
8
- import { DelegateStateMixinClass } from './delegate-state-mixin.js';
9
- import { InputMixinClass } from './input-mixin.js';
10
- import { ValidateMixinClass } from './validate-mixin.js';
6
+ import type { Constructor } from '@open-wc/dedupe-mixin';
7
+ import type { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
8
+ import type { DelegateStateMixinClass } from './delegate-state-mixin.js';
9
+ import type { InputMixinClass } from './input-mixin.js';
10
+ import type { ValidateMixinClass } from './validate-mixin.js';
11
11
 
12
12
  /**
13
13
  * A mixin to combine multiple input validation constraints.
@@ -88,7 +88,7 @@ export const InputConstraintsMixin = dedupingMixin(
88
88
  if (this._hasValidConstraints(constraints)) {
89
89
  this.validate();
90
90
  } else {
91
- this.invalid = false;
91
+ this._setInvalid(false);
92
92
  }
93
93
  }
94
94
 
@@ -3,18 +3,18 @@
3
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
- import { Constructor } from '@open-wc/dedupe-mixin';
7
- import { ControllerMixinClass } from '@vaadin/component-base/src/controller-mixin.js';
8
- import { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
9
- import { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js';
10
- import { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js';
11
- import { DelegateFocusMixinClass } from './delegate-focus-mixin.js';
12
- import { DelegateStateMixinClass } from './delegate-state-mixin.js';
13
- import { FieldMixinClass } from './field-mixin.js';
14
- import { InputConstraintsMixinClass } from './input-constraints-mixin.js';
15
- import { InputMixinClass } from './input-mixin.js';
16
- import { LabelMixinClass } from './label-mixin.js';
17
- import { ValidateMixinClass } from './validate-mixin.js';
6
+ import type { Constructor } from '@open-wc/dedupe-mixin';
7
+ import type { ControllerMixinClass } from '@vaadin/component-base/src/controller-mixin.js';
8
+ import type { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
9
+ import type { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js';
10
+ import type { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js';
11
+ import type { DelegateFocusMixinClass } from './delegate-focus-mixin.js';
12
+ import type { DelegateStateMixinClass } from './delegate-state-mixin.js';
13
+ import type { FieldMixinClass } from './field-mixin.js';
14
+ import type { InputConstraintsMixinClass } from './input-constraints-mixin.js';
15
+ import type { InputMixinClass } from './input-mixin.js';
16
+ import type { LabelMixinClass } from './label-mixin.js';
17
+ import type { ValidateMixinClass } from './validate-mixin.js';
18
18
 
19
19
  /**
20
20
  * A mixin to provide shared logic for the editable form input controls.
@@ -3,19 +3,19 @@
3
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
- import { Constructor } from '@open-wc/dedupe-mixin';
7
- import { ControllerMixinClass } from '@vaadin/component-base/src/controller-mixin.js';
8
- import { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
9
- import { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js';
10
- import { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js';
11
- import { DelegateFocusMixinClass } from './delegate-focus-mixin.js';
12
- import { DelegateStateMixinClass } from './delegate-state-mixin.js';
13
- import { FieldMixinClass } from './field-mixin.js';
14
- import { InputConstraintsMixinClass } from './input-constraints-mixin.js';
15
- import { InputControlMixinClass } from './input-control-mixin.js';
16
- import { InputMixinClass } from './input-mixin.js';
17
- import { LabelMixinClass } from './label-mixin.js';
18
- import { ValidateMixinClass } from './validate-mixin.js';
6
+ import type { Constructor } from '@open-wc/dedupe-mixin';
7
+ import type { ControllerMixinClass } from '@vaadin/component-base/src/controller-mixin.js';
8
+ import type { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
9
+ import type { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js';
10
+ import type { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js';
11
+ import type { DelegateFocusMixinClass } from './delegate-focus-mixin.js';
12
+ import type { DelegateStateMixinClass } from './delegate-state-mixin.js';
13
+ import type { FieldMixinClass } from './field-mixin.js';
14
+ import type { InputConstraintsMixinClass } from './input-constraints-mixin.js';
15
+ import type { InputControlMixinClass } from './input-control-mixin.js';
16
+ import type { InputMixinClass } from './input-mixin.js';
17
+ import type { LabelMixinClass } from './label-mixin.js';
18
+ import type { ValidateMixinClass } from './validate-mixin.js';
19
19
 
20
20
  /**
21
21
  * A mixin to provide logic for vaadin-text-field and related components.
@@ -3,7 +3,7 @@
3
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
- import { Constructor } from '@open-wc/dedupe-mixin';
6
+ import type { Constructor } from '@open-wc/dedupe-mixin';
7
7
 
8
8
  /**
9
9
  * A mixin to store the reference to an input element
@@ -3,8 +3,8 @@
3
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
- import { Constructor } from '@open-wc/dedupe-mixin';
7
- import { LabelController } from './label-controller.js';
6
+ import type { Constructor } from '@open-wc/dedupe-mixin';
7
+ import type { LabelController } from './label-controller.js';
8
8
 
9
9
  /**
10
10
  * A mixin to provide label via corresponding property or named slot.
@@ -3,7 +3,7 @@
3
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
- import { ReactiveController } from 'lit';
6
+ import type { ReactiveController } from 'lit';
7
7
 
8
8
  /**
9
9
  * A controller for linking a `<label>` element with an `<input>` element.
@@ -3,12 +3,12 @@
3
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
- import { Constructor } from '@open-wc/dedupe-mixin';
7
- import { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
8
- import { DelegateStateMixinClass } from './delegate-state-mixin.js';
9
- import { InputConstraintsMixinClass } from './input-constraints-mixin.js';
10
- import { InputMixinClass } from './input-mixin.js';
11
- import { ValidateMixinClass } from './validate-mixin.js';
6
+ import type { Constructor } from '@open-wc/dedupe-mixin';
7
+ import type { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
8
+ import type { DelegateStateMixinClass } from './delegate-state-mixin.js';
9
+ import type { InputConstraintsMixinClass } from './input-constraints-mixin.js';
10
+ import type { InputMixinClass } from './input-mixin.js';
11
+ import type { ValidateMixinClass } from './validate-mixin.js';
12
12
 
13
13
  /**
14
14
  * A mixin to provide `pattern` and `preventInvalidInput` properties.
@@ -3,12 +3,12 @@
3
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
- import { Constructor } from '@open-wc/dedupe-mixin';
7
- import { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
8
- import { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js';
9
- import { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js';
10
- import { TabindexMixinClass } from '@vaadin/component-base/src/tabindex-mixin.js';
11
- import { DelegateFocusMixinClass } from './delegate-focus-mixin.js';
6
+ import type { Constructor } from '@open-wc/dedupe-mixin';
7
+ import type { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
8
+ import type { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js';
9
+ import type { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js';
10
+ import type { TabindexMixinClass } from '@vaadin/component-base/src/tabindex-mixin.js';
11
+ import type { DelegateFocusMixinClass } from './delegate-focus-mixin.js';
12
12
 
13
13
  /**
14
14
  * A mixin to forward focus to an element in the shadow DOM.
@@ -3,7 +3,7 @@
3
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
- import { Constructor } from '@open-wc/dedupe-mixin';
6
+ import type { Constructor } from '@open-wc/dedupe-mixin';
7
7
 
8
8
  /**
9
9
  * Mixin to insert styles into the outer scope to handle slotted components.
@@ -3,7 +3,7 @@
3
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
- import { ReactiveController } from 'lit';
6
+ import type { ReactiveController } from 'lit';
7
7
 
8
8
  export class SlotTargetController implements ReactiveController {
9
9
  /**
@@ -3,6 +3,6 @@
3
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
- import { CSSResult } from 'lit';
6
+ import type { CSSResult } from 'lit';
7
7
 
8
8
  export const clearButton: CSSResult;
@@ -3,6 +3,6 @@
3
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
- import { CSSResult } from 'lit';
6
+ import type { CSSResult } from 'lit';
7
7
 
8
8
  export const fieldShared: CSSResult;
@@ -3,6 +3,6 @@
3
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
- import { CSSResult } from 'lit';
6
+ import type { CSSResult } from 'lit';
7
7
 
8
8
  export const inputFieldContainer: CSSResult;
@@ -3,6 +3,6 @@
3
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
- import { CSSResult } from 'lit';
6
+ import type { CSSResult } from 'lit';
7
7
 
8
8
  export const inputFieldShared: CSSResult;
@@ -3,7 +3,7 @@
3
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
- import { Constructor } from '@open-wc/dedupe-mixin';
6
+ import type { Constructor } from '@open-wc/dedupe-mixin';
7
7
 
8
8
  /**
9
9
  * A mixin to provide required state and validation logic.
@@ -30,4 +30,12 @@ export declare class ValidateMixinClass {
30
30
  * Returns true if the field value satisfies all constraints (if any).
31
31
  */
32
32
  checkValidity(): boolean;
33
+
34
+ /**
35
+ * Fired whenever the field is validated.
36
+ *
37
+ * @event validated
38
+ * @param {Object} detail
39
+ * @param {boolean} detail.valid the result of the validation.
40
+ */
33
41
  }
@@ -36,12 +36,17 @@ export const ValidateMixin = dedupingMixin(
36
36
  }
37
37
 
38
38
  /**
39
- * Returns true if field is valid, and sets `invalid` based on the field validity.
39
+ * Validates the field and sets the `invalid` property based on the result.
40
+ *
41
+ * The method fires a `validated` event with the result of the validation.
40
42
  *
41
43
  * @return {boolean} True if the value is valid.
42
44
  */
43
45
  validate() {
44
- return !(this.invalid = !this.checkValidity());
46
+ const isValid = this.checkValidity();
47
+ this._setInvalid(!isValid);
48
+ this.dispatchEvent(new CustomEvent('validated', { detail: { valid: isValid } }));
49
+ return isValid;
45
50
  }
46
51
 
47
52
  /**
@@ -52,5 +57,34 @@ export const ValidateMixin = dedupingMixin(
52
57
  checkValidity() {
53
58
  return !this.required || !!this.value;
54
59
  }
60
+
61
+ /**
62
+ * @param {boolean} invalid
63
+ * @protected
64
+ */
65
+ _setInvalid(invalid) {
66
+ if (this._shouldSetInvalid(invalid)) {
67
+ this.invalid = invalid;
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Override this method to define whether the given `invalid` state should be set.
73
+ *
74
+ * @param {boolean} _invalid
75
+ * @return {boolean}
76
+ * @protected
77
+ */
78
+ _shouldSetInvalid(_invalid) {
79
+ return true;
80
+ }
81
+
82
+ /**
83
+ * Fired whenever the field is validated.
84
+ *
85
+ * @event validated
86
+ * @param {Object} detail
87
+ * @param {boolean} detail.valid the result of the validation.
88
+ */
55
89
  },
56
90
  );
@@ -3,7 +3,7 @@
3
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
- import { ReactiveController } from 'lit';
6
+ import type { ReactiveController } from 'lit';
7
7
 
8
8
  /**
9
9
  * A controller which prevents the virtual keyboard from showing up on mobile devices