@vaadin/text-area 22.0.0-rc1 → 23.0.0-alpha2

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/text-area",
3
- "version": "22.0.0-rc1",
3
+ "version": "23.0.0-alpha2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -32,17 +32,17 @@
32
32
  ],
33
33
  "dependencies": {
34
34
  "@polymer/polymer": "^3.0.0",
35
- "@vaadin/component-base": "22.0.0-rc1",
36
- "@vaadin/field-base": "22.0.0-rc1",
37
- "@vaadin/input-container": "22.0.0-rc1",
38
- "@vaadin/vaadin-lumo-styles": "22.0.0-rc1",
39
- "@vaadin/vaadin-material-styles": "22.0.0-rc1",
40
- "@vaadin/vaadin-themable-mixin": "22.0.0-rc1"
35
+ "@vaadin/component-base": "23.0.0-alpha2",
36
+ "@vaadin/field-base": "23.0.0-alpha2",
37
+ "@vaadin/input-container": "23.0.0-alpha2",
38
+ "@vaadin/vaadin-lumo-styles": "23.0.0-alpha2",
39
+ "@vaadin/vaadin-material-styles": "23.0.0-alpha2",
40
+ "@vaadin/vaadin-themable-mixin": "23.0.0-alpha2"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@esm-bundle/chai": "^4.3.4",
44
44
  "@vaadin/testing-helpers": "^0.3.2",
45
45
  "sinon": "^9.2.1"
46
46
  },
47
- "gitHead": "7b6f44bcd2c0fd415028ace666feeb0fedb1d540"
47
+ "gitHead": "070f586dead02ca41b66717820c647f48bf1665f"
48
48
  }
@@ -5,8 +5,16 @@
5
5
  */
6
6
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
7
7
  import { InputFieldMixin } from '@vaadin/field-base/src/input-field-mixin.js';
8
+ import { PatternMixin } from '@vaadin/field-base/src/pattern-mixin.js';
8
9
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
9
10
 
11
+ /**
12
+ * Fired when the user commits a value change.
13
+ */
14
+ export type TextAreaChangeEvent = Event & {
15
+ target: TextArea;
16
+ };
17
+
10
18
  /**
11
19
  * Fired when the `invalid` property changes.
12
20
  */
@@ -23,7 +31,9 @@ export interface TextAreaCustomEventMap {
23
31
  'value-changed': TextAreaValueChangedEvent;
24
32
  }
25
33
 
26
- export interface TextAreaEventMap extends HTMLElementEventMap, TextAreaCustomEventMap {}
34
+ export interface TextAreaEventMap extends HTMLElementEventMap, TextAreaCustomEventMap {
35
+ change: TextAreaChangeEvent;
36
+ }
27
37
 
28
38
  /**
29
39
  * `<vaadin-text-area>` is a web component for multi-line text input.
@@ -66,7 +76,7 @@ export interface TextAreaEventMap extends HTMLElementEventMap, TextAreaCustomEve
66
76
  * @fires {CustomEvent} invalid-changed - Fired when the `invalid` property changes.
67
77
  * @fires {CustomEvent} value-changed - Fired when the `value` property changes.
68
78
  */
69
- declare class TextArea extends InputFieldMixin(ThemableMixin(ElementMixin(HTMLElement))) {
79
+ declare class TextArea extends PatternMixin(InputFieldMixin(ThemableMixin(ElementMixin(HTMLElement)))) {
70
80
  /**
71
81
  * Maximum number of characters (in Unicode code points) that the user can enter.
72
82
  */
@@ -8,6 +8,7 @@ import { html, PolymerElement } from '@polymer/polymer';
8
8
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
9
9
  import { InputFieldMixin } from '@vaadin/field-base/src/input-field-mixin.js';
10
10
  import { LabelledInputController } from '@vaadin/field-base/src/labelled-input-controller.js';
11
+ import { PatternMixin } from '@vaadin/field-base/src/pattern-mixin.js';
11
12
  import { inputFieldShared } from '@vaadin/field-base/src/styles/input-field-shared-styles.js';
12
13
  import { TextAreaController } from '@vaadin/field-base/src/text-area-controller.js';
13
14
  import { registerStyles, ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
@@ -56,9 +57,10 @@ registerStyles('vaadin-text-area', inputFieldShared, { moduleId: 'vaadin-text-ar
56
57
  * @extends HTMLElement
57
58
  * @mixes InputFieldMixin
58
59
  * @mixes ElementMixin
60
+ * @mixes PatternMixin
59
61
  * @mixes ThemableMixin
60
62
  */
61
- export class TextArea extends InputFieldMixin(ThemableMixin(ElementMixin(PolymerElement))) {
63
+ export class TextArea extends PatternMixin(InputFieldMixin(ThemableMixin(ElementMixin(PolymerElement)))) {
62
64
  static get is() {
63
65
  return 'vaadin-text-area';
64
66
  }
@@ -279,6 +281,33 @@ export class TextArea extends InputFieldMixin(ThemableMixin(ElementMixin(Polymer
279
281
 
280
282
  this._dispatchIronResizeEventIfNeeded('InputHeight', inputHeight);
281
283
  }
284
+
285
+ /**
286
+ * Returns true if the current textarea value satisfies all constraints (if any).
287
+ * @return {boolean}
288
+ */
289
+ checkValidity() {
290
+ if (!super.checkValidity()) {
291
+ return false;
292
+ }
293
+
294
+ // Native <textarea> does not support pattern attribute, so we have a custom logic
295
+ // according to WHATWG spec for <input>, with tests inspired by web-platform-tests
296
+ // https://html.spec.whatwg.org/multipage/input.html#the-pattern-attribute
297
+
298
+ if (!this.pattern || !this.inputElement.value) {
299
+ // Mark as valid if there is no pattern, or the value is empty
300
+ return true;
301
+ }
302
+
303
+ try {
304
+ const match = this.inputElement.value.match(this.pattern);
305
+ return match ? match[0] === match.input : false;
306
+ } catch (_) {
307
+ // If the pattern can not be compiled, then report as valid
308
+ return true;
309
+ }
310
+ }
282
311
  }
283
312
 
284
313
  customElements.define(TextArea.is, TextArea);