@vaadin/vaadin-text-field 2.8.3 → 2.9.0

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/README.md CHANGED
@@ -1,19 +1,18 @@
1
- [![npm version](https://badge.fury.io/js/%40vaadin%2Fvaadin-text-field.svg)](https://badge.fury.io/js/%40vaadin%2Fvaadin-text-field)
2
- [![Published on webcomponents.org](https://img.shields.io/badge/webcomponents.org-published-blue.svg)](https://www.webcomponents.org/element/vaadin/vaadin-text-field)
3
- [![Build Status](https://travis-ci.org/vaadin/vaadin-text-field.svg?branch=master)](https://travis-ci.org/vaadin/vaadin-text-field)
4
- [![Coverage Status](https://coveralls.io/repos/github/vaadin/vaadin-text-field/badge.svg?branch=master)](https://coveralls.io/github/vaadin/vaadin-text-field?branch=master)
5
- [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/vaadin/web-components?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
1
+ # <vaadin-text-field>
6
2
 
7
- [![Published on Vaadin Directory](https://img.shields.io/badge/Vaadin%20Directory-published-00b4f0.svg)](https://vaadin.com/directory/component/vaadinvaadin-text-field)
8
- [![Stars on vaadin.com/directory](https://img.shields.io/vaadin-directory/star/vaadinvaadin-text-field.svg)](https://vaadin.com/directory/component/vaadinvaadin-text-field)
3
+ > ⚠️ Starting from Vaadin 20, the source code and issues for this component are migrated to the [`vaadin/web-components`](https://github.com/vaadin/web-components/tree/master/packages/vaadin-text-field) monorepository.
4
+ > This repository contains the source code and releases of `<vaadin-text-field>` for the Vaadin versions 10 to 19.
9
5
 
10
- # &lt;vaadin-text-field&gt;
6
+ [&lt;vaadin-text-field&gt;](https://vaadin.com/components/vaadin-text-field) is a themable Web Component providing input controls in forms, part of the [Vaadin components](https://vaadin.com/components).
11
7
 
12
8
  [Live Demo ↗](https://vaadin.com/components/vaadin-text-field/html-examples)
13
9
  |
14
10
  [API documentation ↗](https://vaadin.com/components/vaadin-text-field/html-api)
15
11
 
16
- [&lt;vaadin-text-field&gt;](https://vaadin.com/components/vaadin-text-field) is a themable Web Component providing input controls in forms, part of the [Vaadin components](https://vaadin.com/components).
12
+ [![npm version](https://badge.fury.io/js/%40vaadin%2Fvaadin-text-field.svg)](https://badge.fury.io/js/%40vaadin%2Fvaadin-text-field)
13
+ [![Published on webcomponents.org](https://img.shields.io/badge/webcomponents.org-published-blue.svg)](https://www.webcomponents.org/element/vaadin/vaadin-text-field)
14
+ [![Published on Vaadin Directory](https://img.shields.io/badge/Vaadin%20Directory-published-00b4f0.svg)](https://vaadin.com/directory/component/vaadinvaadin-text-field)
15
+ [![Discord](https://img.shields.io/discord/732335336448852018?label=discord)](https://discord.gg/PHmkCKC)
17
16
 
18
17
  <!--
19
18
  ```
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "repository": "vaadin/vaadin-text-field",
11
11
  "homepage": "https://vaadin.com/components",
12
12
  "name": "@vaadin/vaadin-text-field",
13
- "version": "2.8.3",
13
+ "version": "2.9.0",
14
14
  "main": "vaadin-text-field.js",
15
15
  "author": "Vaadin Ltd",
16
16
  "license": "Apache-2.0",
@@ -41,9 +41,9 @@
41
41
  "@vaadin/vaadin-element-mixin": "^2.4.1"
42
42
  },
43
43
  "scripts": {
44
- "generate-typings": "gen-typescript-declarations --outDir . --verify"
45
- },
46
- "devDependencies": {
44
+ "generate-typings": "gen-typescript-declarations --outDir . --verify"
45
+ },
46
+ "devDependencies": {
47
47
  "@polymer/iron-component-page": "^4.0.0",
48
48
  "@polymer/iron-form": "^3.0.0",
49
49
  "@polymer/iron-test-helpers": "^3.0.0",
@@ -63,7 +63,7 @@ class EmailFieldElement extends TextFieldElement {
63
63
  }
64
64
 
65
65
  static get version() {
66
- return '2.8.3';
66
+ return '2.9.0';
67
67
  }
68
68
 
69
69
  static get template() {
@@ -32,7 +32,7 @@ class IntegerFieldElement extends NumberFieldElement {
32
32
  }
33
33
 
34
34
  static get version() {
35
- return '2.8.3';
35
+ return '2.9.0';
36
36
  }
37
37
 
38
38
  static get properties() {
@@ -105,7 +105,7 @@ class NumberFieldElement extends TextFieldElement {
105
105
  }
106
106
 
107
107
  static get version() {
108
- return '2.8.3';
108
+ return '2.9.0';
109
109
  }
110
110
 
111
111
  static get properties() {
@@ -76,7 +76,7 @@ class PasswordFieldElement extends TextFieldElement {
76
76
  }
77
77
 
78
78
  static get version() {
79
- return '2.8.3';
79
+ return '2.9.0';
80
80
  }
81
81
 
82
82
  static get properties() {
@@ -79,7 +79,18 @@ declare class TextAreaElement extends
79
79
  ThemableMixin(
80
80
  PolymerElement)))) {
81
81
  readonly _slottedTagName: string;
82
+
83
+ /**
84
+ * A regular expression that the value is checked against.
85
+ * The pattern must match the entire value, not just some subset.
86
+ */
87
+ pattern: string|null|undefined;
82
88
  ready(): void;
89
+
90
+ /**
91
+ * Returns true if the current textarea value satisfies all constraints (if any).
92
+ */
93
+ checkValidity(): boolean;
83
94
  }
84
95
 
85
96
  declare global {
@@ -110,6 +110,11 @@ class TextAreaElement extends
110
110
  :host {
111
111
  animation: 1ms vaadin-text-area-appear;
112
112
  }
113
+
114
+ /* Workaround https://bugzilla.mozilla.org/show_bug.cgi?id=1739079 */
115
+ :host([disabled]) [part='value'] {
116
+ user-select: none;
117
+ }
113
118
  </style>
114
119
 
115
120
  <div class="vaadin-text-area-container">
@@ -129,7 +134,7 @@ class TextAreaElement extends
129
134
 
130
135
  </div>
131
136
 
132
- <div part="helper-text" on-click="focus" id="[[_helperTextId]]">
137
+ <div part="helper-text" id="[[_helperTextId]]">
133
138
  <slot name="helper">[[helperText]]</slot>
134
139
  </div>
135
140
 
@@ -144,7 +149,19 @@ class TextAreaElement extends
144
149
  }
145
150
 
146
151
  static get version() {
147
- return '2.8.3';
152
+ return '2.9.0';
153
+ }
154
+
155
+ static get properties() {
156
+ return {
157
+ /**
158
+ * A regular expression that the value is checked against.
159
+ * The pattern must match the entire value, not just some subset.
160
+ */
161
+ pattern: {
162
+ type: String
163
+ }
164
+ };
148
165
  }
149
166
 
150
167
  static get observers() {
@@ -158,7 +175,6 @@ class TextAreaElement extends
158
175
  super.ready();
159
176
  this._updateHeight();
160
177
  this.addEventListener('animationend', this._onAnimationEnd);
161
- this.__safari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
162
178
  }
163
179
 
164
180
  /** @private */
@@ -187,18 +203,25 @@ class TextAreaElement extends
187
203
  const scrollTop = inputField.scrollTop;
188
204
  const input = this.inputElement;
189
205
 
190
- const inputWidth = getComputedStyle(input).width;
191
-
192
- const valueLength = this.value ? this.value.length : 0;
193
206
  // Only clear the height when the content shortens to minimize scrollbar flickering.
207
+ const valueLength = this.value ? this.value.length : 0;
208
+
194
209
  if (this._oldValueLength >= valueLength) {
210
+ const inputFieldHeight = getComputedStyle(inputField).height;
211
+ const inputWidth = getComputedStyle(input).width;
212
+
213
+ // Temporarily fix the height of the wrapping input field container to prevent changing the browsers scroll
214
+ // position while resetting the textareas height. If the textarea had a large height, then removing its height
215
+ // will reset its height to the default of two rows. That might reduce the height of the page, and the
216
+ // browser might adjust the scroll position before we can restore the measured height of the textarea.
217
+ inputField.style.display = 'block';
218
+ inputField.style.height = inputFieldHeight;
219
+
195
220
  // Fix the input element width so its scroll height isn't affected by host's disappearing scrollbars
196
221
  input.style.maxWidth = inputWidth;
222
+
223
+ // Clear the height of the textarea to allow measuring a reduced scroll height
197
224
  input.style.height = 'auto';
198
- // Avoid a jumpy Safari rendering issue
199
- if (this.__safari) {
200
- inputField.style.display = 'block';
201
- }
202
225
  }
203
226
  this._oldValueLength = valueLength;
204
227
 
@@ -210,11 +233,39 @@ class TextAreaElement extends
210
233
  // Restore
211
234
  input.style.removeProperty('max-width');
212
235
  inputField.style.removeProperty('display');
236
+ inputField.style.removeProperty('height');
213
237
  inputField.scrollTop = scrollTop;
214
238
 
215
239
  this._dispatchIronResizeEventIfNeeded('InputHeight', inputHeight);
216
240
  }
217
241
 
242
+ /**
243
+ * Returns true if the current textarea value satisfies all constraints (if any).
244
+ * @return {boolean}
245
+ */
246
+ checkValidity() {
247
+ if (!super.checkValidity()) {
248
+ return false;
249
+ }
250
+
251
+ // Native <textarea> does not support pattern attribute, so we have a custom logic
252
+ // according to WHATWG spec for <input>, with tests inspired by web-platform-tests
253
+ // https://html.spec.whatwg.org/multipage/input.html#the-pattern-attribute
254
+
255
+ if (!this.pattern || !this.inputElement.value) {
256
+ // Mark as valid if there is no pattern, or the value is empty
257
+ return true;
258
+ }
259
+
260
+ try {
261
+ const match = this.inputElement.value.match(this.pattern);
262
+ return match ? match[0] === match.input : false;
263
+ } catch (_) {
264
+ // If the pattern can not be compiled, then report as valid
265
+ return true;
266
+ }
267
+ }
268
+
218
269
  /**
219
270
  * Fired when the text-area height changes.
220
271
  *
@@ -884,7 +884,7 @@ export const TextFieldMixin = subclass => class VaadinTextFieldMixin extends sub
884
884
  if (this[previousSizePropertyName] !== undefined
885
885
  && this[previousSizePropertyName] !== value) {
886
886
  this.dispatchEvent(
887
- new CustomEvent('iron-resize', {bubbles: true})
887
+ new CustomEvent('iron-resize', {bubbles: true, composed: true})
888
888
  );
889
889
  }
890
890
 
@@ -101,7 +101,7 @@ class TextFieldElement extends
101
101
 
102
102
  </div>
103
103
 
104
- <div part="helper-text" on-click="focus" id="[[_helperTextId]]">
104
+ <div part="helper-text" id="[[_helperTextId]]">
105
105
  <slot name="helper">[[helperText]]</slot>
106
106
  </div>
107
107
 
@@ -116,7 +116,7 @@ class TextFieldElement extends
116
116
  }
117
117
 
118
118
  static get version() {
119
- return '2.8.3';
119
+ return '2.9.0';
120
120
  }
121
121
 
122
122
  static get properties() {
@@ -29,12 +29,12 @@ const $_documentContainer = html`<dom-module id="lumo-text-area" theme-for="vaad
29
29
  border: none;
30
30
  }
31
31
 
32
- :host(:hover:not([readonly]):not([focused])) [part="input-field"] {
32
+ :host(:hover:not([readonly]):not([focused]):not([invalid])) [part="input-field"] {
33
33
  background-color: var(--lumo-contrast-20pct);
34
34
  }
35
35
 
36
36
  @media (pointer: coarse) {
37
- :host(:hover:not([readonly]):not([focused])) [part="input-field"] {
37
+ :host(:hover:not([readonly]):not([focused]):not([invalid])) [part="input-field"] {
38
38
  background-color: var(--lumo-contrast-10pct);
39
39
  }
40
40