1
1
import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js" ;
2
2
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js" ;
3
+ import ResizeHandler from "@ui5/webcomponents-base/dist/delegate/ResizeHandler.js" ;
3
4
import Integer from "@ui5/webcomponents-base/dist/types/Integer.js" ;
4
5
import { fetchI18nBundle , getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js" ;
5
6
import { getFeature } from "@ui5/webcomponents-base/dist/FeaturesRegistry.js" ;
6
7
import { isIE } from "@ui5/webcomponents-base/dist/Device.js" ;
7
8
import ValueState from "@ui5/webcomponents-base/dist/types/ValueState.js" ;
8
9
9
10
import TextAreaTemplate from "./generated/templates/TextAreaTemplate.lit.js" ;
10
- import { TEXTAREA_CHARACTERS_LEFT , TEXTAREA_CHARACTERS_EXCEEDED } from "./generated/i18n/i18n-defaults.js" ;
11
+ import TextAreaPopoverTemplate from "./generated/templates/TextAreaPopoverTemplate.lit.js" ;
12
+
13
+ import {
14
+ VALUE_STATE_INFORMATION ,
15
+ VALUE_STATE_ERROR ,
16
+ VALUE_STATE_WARNING ,
17
+ TEXTAREA_CHARACTERS_LEFT ,
18
+ TEXTAREA_CHARACTERS_EXCEEDED ,
19
+ } from "./generated/i18n/i18n-defaults.js" ;
11
20
12
21
// Styles
13
22
import styles from "./generated/themes/TextArea.css.js" ;
23
+ import valueStateMessageStyles from "./generated/themes/ValueStateMessage.css.js" ;
14
24
15
25
/**
16
26
* @public
17
27
*/
18
28
const metadata = {
19
29
tag : "ui5-textarea" ,
30
+ managedSlots : true ,
20
31
properties : /** @lends sap.ui.webcomponents.main.TextArea.prototype */ {
21
32
/**
22
33
* Defines the value of the Web Component.
@@ -210,15 +221,49 @@ const metadata = {
210
221
type : Boolean ,
211
222
} ,
212
223
224
+ /**
225
+ * @private
226
+ */
213
227
_mirrorText : {
214
228
type : Object ,
215
229
multiple : true ,
216
230
defaultValue : "" ,
217
231
} ,
232
+
233
+ /**
234
+ * @private
235
+ */
218
236
_maxHeight : {
219
237
type : String ,
220
238
noAttribute : true ,
221
239
} ,
240
+
241
+ /**
242
+ * @private
243
+ */
244
+ _width : {
245
+ type : Integer ,
246
+ } ,
247
+ } ,
248
+ slots : /** @lends sap.ui.webcomponents.main.TextArea.prototype */ {
249
+
250
+ /**
251
+ * Defines the value state message that will be displayed as pop up under the <code>ui5-textarea</code>.
252
+ *
253
+ * <br><br>
254
+ * <b>Note:</b> If not specified, a default text (in the respective language) will be displayed.
255
+ *
256
+ * <br><br>
257
+ * <b>Note:</b> The <code>valueStateMessage</code> would be displayed if the <code>ui5-textarea</code> has
258
+ * <code>valueState</code> of type <code>Information</code>, <code>Warning</code> or <code>Error</code>.
259
+ * @type {HTMLElement[] }
260
+ * @since 1.0.0-rc.7
261
+ * @slot
262
+ * @public
263
+ */
264
+ valueStateMessage : {
265
+ type : HTMLElement ,
266
+ } ,
222
267
} ,
223
268
events : /** @lends sap.ui.webcomponents.main.TextArea.prototype */ {
224
269
/**
@@ -282,12 +327,31 @@ class TextArea extends UI5Element {
282
327
return TextAreaTemplate ;
283
328
}
284
329
330
+ static get staticAreaTemplate ( ) {
331
+ return TextAreaPopoverTemplate ;
332
+ }
333
+
334
+ static get staticAreaStyles ( ) {
335
+ return valueStateMessageStyles ;
336
+ }
337
+
285
338
constructor ( ) {
286
339
super ( ) ;
287
340
341
+ this . _firstRendering = true ;
342
+ this . _openValueStateMsgPopover = false ;
343
+ this . _fnOnResize = this . _onResize . bind ( this ) ;
288
344
this . i18nBundle = getI18nBundle ( "@ui5/webcomponents" ) ;
289
345
}
290
346
347
+ onEnterDOM ( ) {
348
+ ResizeHandler . register ( this , this . _fnOnResize ) ;
349
+ }
350
+
351
+ onExitDOM ( ) {
352
+ ResizeHandler . deregister ( this , this . _fnOnResize ) ;
353
+ }
354
+
291
355
onBeforeRendering ( ) {
292
356
this . _exceededTextProps = this . _calcExceededText ( ) ;
293
357
this . _mirrorText = this . _tokenizeText ( this . value ) ;
@@ -307,6 +371,11 @@ class TextArea extends UI5Element {
307
371
}
308
372
}
309
373
374
+ onAfterRendering ( ) {
375
+ this . toggleValueStateMessage ( this . openValueStateMsgPopover ) ;
376
+ this . _firstRendering = false ;
377
+ }
378
+
310
379
getInputDomRef ( ) {
311
380
return this . getDomRef ( ) . querySelector ( "textarea" ) ;
312
381
}
@@ -321,10 +390,12 @@ class TextArea extends UI5Element {
321
390
322
391
_onfocusin ( ) {
323
392
this . focused = true ;
393
+ this . _openValueStateMsgPopover = true ;
324
394
}
325
395
326
396
_onfocusout ( ) {
327
397
this . focused = false ;
398
+ this . _openValueStateMsgPopover = false ;
328
399
}
329
400
330
401
_onchange ( ) {
@@ -355,6 +426,35 @@ class TextArea extends UI5Element {
355
426
this . fireEvent ( "value-changed" ) ;
356
427
}
357
428
429
+ _onResize ( ) {
430
+ if ( this . displayValueStateMessage ) {
431
+ this . _width = this . offsetWidth ;
432
+ }
433
+ }
434
+
435
+ toggleValueStateMessage ( toggle ) {
436
+ if ( toggle ) {
437
+ this . openPopover ( ) ;
438
+ } else {
439
+ this . closePopover ( ) ;
440
+ }
441
+ }
442
+
443
+ async openPopover ( ) {
444
+ this . popover = await this . _getPopover ( ) ;
445
+ this . popover && this . popover . openBy ( this . shadowRoot . querySelector ( ".ui5-textarea-inner" ) ) ;
446
+ }
447
+
448
+ async closePopover ( ) {
449
+ this . popover = await this . _getPopover ( ) ;
450
+ this . popover && this . popover . close ( ) ;
451
+ }
452
+
453
+ async _getPopover ( ) {
454
+ const staticAreaItem = await this . getStaticAreaItemDomRef ( ) ;
455
+ return staticAreaItem . querySelector ( "ui5-popover" ) ;
456
+ }
457
+
358
458
_tokenizeText ( value ) {
359
459
const tokenizedText = value . replace ( / & / gm, "&" ) . replace ( / " / gm, """ ) . replace ( / " / gm, "'" ) . replace ( / < / gm, "<" )
360
460
. replace ( / > / gm, ">" )
@@ -402,6 +502,16 @@ class TextArea extends UI5Element {
402
502
} ;
403
503
}
404
504
505
+ get classes ( ) {
506
+ return {
507
+ valueStateMsg : {
508
+ "ui5-valuestatemessage--error" : this . valueState === ValueState . Error ,
509
+ "ui5-valuestatemessage--warning" : this . valueState === ValueState . Warning || this . exceeding ,
510
+ "ui5-valuestatemessage--information" : this . valueState === ValueState . Information ,
511
+ } ,
512
+ } ;
513
+ }
514
+
405
515
get styles ( ) {
406
516
const lineHeight = 1.4 * 16 ;
407
517
@@ -417,6 +527,9 @@ class TextArea extends UI5Element {
417
527
"height" : ( this . showExceededText ? "calc(100% - 26px)" : "100%" ) ,
418
528
"max-height" : ( this . _maxHeight ) ,
419
529
} ,
530
+ valueStateMsgPopover : {
531
+ "max-width" : `${ this . _width } px` ,
532
+ } ,
420
533
} ;
421
534
}
422
535
@@ -432,6 +545,44 @@ class TextArea extends UI5Element {
432
545
return this . valueState === "Error" ? "true" : undefined ;
433
546
}
434
547
548
+ get openValueStateMsgPopover ( ) {
549
+ return ! this . _firstRendering && this . _openValueStateMsgPopover && this . displayValueStateMessage ;
550
+ }
551
+
552
+ get displayValueStateMessage ( ) {
553
+ return ! ! this . valueStateMessage . length || this . exceeding || ( this . valueState !== ValueState . Success && this . valueState !== ValueState . None ) ;
554
+ }
555
+
556
+ get displayDefaultValueStateMessage ( ) {
557
+ if ( this . valueStateMessage . length ) {
558
+ return false ;
559
+ }
560
+
561
+ return this . exceeding || ( this . valueState !== ValueState . Success && this . valueState !== ValueState . None ) ;
562
+ }
563
+
564
+ get valueStateMessageText ( ) {
565
+ return this . valueStateMessage . map ( x => x . cloneNode ( true ) ) ;
566
+ }
567
+
568
+ get valueStateText ( ) {
569
+ if ( this . valueState !== ValueState . Error && this . exceeding ) {
570
+ return this . valueStateTextMappings ( ) [ ValueState . Warning ] ;
571
+ }
572
+
573
+ return this . valueStateTextMappings ( ) [ this . valueState ] ;
574
+ }
575
+
576
+ valueStateTextMappings ( ) {
577
+ const i18nBundle = this . i18nBundle ;
578
+
579
+ return {
580
+ "Information" : i18nBundle . getText ( VALUE_STATE_INFORMATION ) ,
581
+ "Error" : i18nBundle . getText ( VALUE_STATE_ERROR ) ,
582
+ "Warning" : i18nBundle . getText ( VALUE_STATE_WARNING ) ,
583
+ } ;
584
+ }
585
+
435
586
static async onDefine ( ) {
436
587
await fetchI18nBundle ( "@ui5/webcomponents" ) ;
437
588
}
0 commit comments