@vaadin/vaadin-text-field 2.8.4 → 2.9.1

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.4",
13
+ "version": "2.9.1",
14
14
  "main": "vaadin-text-field.js",
15
15
  "author": "Vaadin Ltd",
16
16
  "license": "Apache-2.0",
@@ -25,8 +25,6 @@
25
25
  "theme"
26
26
  ],
27
27
  "resolutions": {
28
- "es-abstract": "1.17.6",
29
- "@types/doctrine": "0.0.3",
30
28
  "inherits": "2.0.3",
31
29
  "samsam": "1.1.3",
32
30
  "supports-color": "3.1.2",
@@ -40,10 +38,9 @@
40
38
  "@vaadin/vaadin-material-styles": "^1.3.2",
41
39
  "@vaadin/vaadin-element-mixin": "^2.4.1"
42
40
  },
43
- "scripts": {
44
- "generate-typings": "gen-typescript-declarations --outDir . --verify"
45
- },
46
41
  "devDependencies": {
42
+ "@web-padawan/gen-typescript-declarations": "^1.6.2",
43
+ "web-component-tester": "6.9.2",
47
44
  "@polymer/iron-component-page": "^4.0.0",
48
45
  "@polymer/iron-form": "^3.0.0",
49
46
  "@polymer/iron-test-helpers": "^3.0.0",
@@ -51,5 +48,9 @@
51
48
  "wct-browser-legacy": "^1.0.1",
52
49
  "@vaadin/vaadin-demo-helpers": "^3.0.0",
53
50
  "@vaadin/vaadin-button": "^2.1.0"
51
+ },
52
+ "scripts": {
53
+ "generate-typings": "gen-typescript-declarations --outDir . --verify",
54
+ "test": "wct --npm"
54
55
  }
55
56
  }
@@ -63,7 +63,7 @@ class EmailFieldElement extends TextFieldElement {
63
63
  }
64
64
 
65
65
  static get version() {
66
- return '2.8.4';
66
+ return '2.9.1';
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.4';
35
+ return '2.9.1';
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.4';
108
+ return '2.9.1';
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.4';
79
+ return '2.9.1';
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,13 +110,18 @@ 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">
116
121
 
117
122
  <label part="label" on-click="focus" id="[[_labelId]]">[[label]]</label>
118
123
 
119
- <div part="input-field" id="[[_inputId]]">
124
+ <div part="input-field" id="[[_inputId]]" on-scroll="__scrollPositionUpdated">
120
125
 
121
126
  <slot name="prefix"></slot>
122
127
 
@@ -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.4';
152
+ return '2.9.1';
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,25 @@ 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);
178
+
179
+ this._inputField = this.root.querySelector('[part=input-field]');
180
+ // Wheel scrolling results in async scroll events. Preventing the wheel
181
+ // event, scrolling manually and then synchronously updating the scroll position CSS variable
182
+ // allows us to avoid some jumpy behavior that would occur on wheel otherwise.
183
+ this._inputField.addEventListener('wheel', (e) => {
184
+ e.preventDefault();
185
+ this._inputField.scrollTop += e.deltaY;
186
+ this.__scrollPositionUpdated();
187
+ });
188
+
189
+ this.__scrollPositionUpdated();
190
+ }
191
+
192
+ /** @private */
193
+ __scrollPositionUpdated() {
194
+ this.updateStyles({
195
+ '--_text-area-vertical-scroll-position': this._inputField.scrollTop + 'px',
196
+ });
162
197
  }
163
198
 
164
199
  /** @private */
@@ -187,18 +222,25 @@ class TextAreaElement extends
187
222
  const scrollTop = inputField.scrollTop;
188
223
  const input = this.inputElement;
189
224
 
190
- const inputWidth = getComputedStyle(input).width;
191
-
192
- const valueLength = this.value ? this.value.length : 0;
193
225
  // Only clear the height when the content shortens to minimize scrollbar flickering.
226
+ const valueLength = this.value ? this.value.length : 0;
227
+
194
228
  if (this._oldValueLength >= valueLength) {
229
+ const inputFieldHeight = getComputedStyle(inputField).height;
230
+ const inputWidth = getComputedStyle(input).width;
231
+
232
+ // Temporarily fix the height of the wrapping input field container to prevent changing the browsers scroll
233
+ // position while resetting the textareas height. If the textarea had a large height, then removing its height
234
+ // will reset its height to the default of two rows. That might reduce the height of the page, and the
235
+ // browser might adjust the scroll position before we can restore the measured height of the textarea.
236
+ inputField.style.display = 'block';
237
+ inputField.style.height = inputFieldHeight;
238
+
195
239
  // Fix the input element width so its scroll height isn't affected by host's disappearing scrollbars
196
240
  input.style.maxWidth = inputWidth;
241
+
242
+ // Clear the height of the textarea to allow measuring a reduced scroll height
197
243
  input.style.height = 'auto';
198
- // Avoid a jumpy Safari rendering issue
199
- if (this.__safari) {
200
- inputField.style.display = 'block';
201
- }
202
244
  }
203
245
  this._oldValueLength = valueLength;
204
246
 
@@ -210,11 +252,39 @@ class TextAreaElement extends
210
252
  // Restore
211
253
  input.style.removeProperty('max-width');
212
254
  inputField.style.removeProperty('display');
255
+ inputField.style.removeProperty('height');
213
256
  inputField.scrollTop = scrollTop;
214
257
 
215
258
  this._dispatchIronResizeEventIfNeeded('InputHeight', inputHeight);
216
259
  }
217
260
 
261
+ /**
262
+ * Returns true if the current textarea value satisfies all constraints (if any).
263
+ * @return {boolean}
264
+ */
265
+ checkValidity() {
266
+ if (!super.checkValidity()) {
267
+ return false;
268
+ }
269
+
270
+ // Native <textarea> does not support pattern attribute, so we have a custom logic
271
+ // according to WHATWG spec for <input>, with tests inspired by web-platform-tests
272
+ // https://html.spec.whatwg.org/multipage/input.html#the-pattern-attribute
273
+
274
+ if (!this.pattern || !this.inputElement.value) {
275
+ // Mark as valid if there is no pattern, or the value is empty
276
+ return true;
277
+ }
278
+
279
+ try {
280
+ const match = this.inputElement.value.match(this.pattern);
281
+ return match ? match[0] === match.input : false;
282
+ } catch (_) {
283
+ // If the pattern can not be compiled, then report as valid
284
+ return true;
285
+ }
286
+ }
287
+
218
288
  /**
219
289
  * Fired when the text-area height changes.
220
290
  *
@@ -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.4';
119
+ return '2.9.1';
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
 
@@ -20,6 +20,11 @@ const $_documentContainer = html`<dom-module id="material-text-area" theme-for="
20
20
  white-space: pre-wrap; /* override \`nowrap\` from <vaadin-text-field> */
21
21
  align-self: stretch; /* override \`baseline\` from <vaadin-text-field> */
22
22
  }
23
+
24
+ [part='input-field']::before,
25
+ [part='input-field']::after {
26
+ bottom: calc(var(--_text-area-vertical-scroll-position) * -1);
27
+ }
23
28
  </style>
24
29
  </template>
25
30
  </dom-module>`;