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 { isIE , isPhone } from "@ui5/webcomponents-base/dist/Device.js" ;
4
5
import ValueState from "@ui5/webcomponents-base/dist/types/ValueState.js" ;
5
6
import { getFeature } from "@ui5/webcomponents-base/dist/FeaturesRegistry.js" ;
@@ -13,12 +14,14 @@ import Integer from "@ui5/webcomponents-base/dist/types/Integer.js";
13
14
import { fetchI18nBundle , getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js" ;
14
15
import "@ui5/webcomponents-icons/dist/icons/decline.js" ;
15
16
import InputType from "./types/InputType.js" ;
17
+ import Popover from "./Popover.js" ;
16
18
// Templates
17
19
import InputTemplate from "./generated/templates/InputTemplate.lit.js" ;
18
20
import InputPopoverTemplate from "./generated/templates/InputPopoverTemplate.lit.js" ;
19
21
20
22
import {
21
23
VALUE_STATE_SUCCESS ,
24
+ VALUE_STATE_INFORMATION ,
22
25
VALUE_STATE_ERROR ,
23
26
VALUE_STATE_WARNING ,
24
27
INPUT_SUGGESTIONS ,
@@ -28,6 +31,7 @@ import {
28
31
// Styles
29
32
import styles from "./generated/themes/Input.css.js" ;
30
33
import ResponsivePopoverCommonCss from "./generated/themes/ResponsivePopoverCommon.css.js" ;
34
+ import ValueStateMessageCss from "./generated/themes/ValueStateMessage.css.js" ;
31
35
32
36
/**
33
37
* @public
@@ -87,6 +91,19 @@ const metadata = {
87
91
formSupport : {
88
92
type : HTMLElement ,
89
93
} ,
94
+
95
+ /**
96
+ * The slot is used in order to display a valueStateMessage.
97
+ * <br><br>
98
+ * <b>Note:</b> The valueStateMessage would be displayed only if the <code>ui5-input</code> has
99
+ * a valueState of type <code>Information</code>, <code>Warning</code> or <code>Error</code>.
100
+ * @type {HTMLElement[] }
101
+ * @slot
102
+ * @public
103
+ */
104
+ valueStateMessage : {
105
+ type : HTMLElement ,
106
+ } ,
90
107
} ,
91
108
properties : /** @lends sap.ui.webcomponents.main.Input.prototype */ {
92
109
@@ -248,6 +265,15 @@ const metadata = {
248
265
_wrapperAccInfo : {
249
266
type : Object ,
250
267
} ,
268
+
269
+ _inputWidth : {
270
+ type : Integer ,
271
+ } ,
272
+
273
+ _isPopoverOpen : {
274
+ type : Boolean ,
275
+ noAttribute : true ,
276
+ } ,
251
277
} ,
252
278
events : /** @lends sap.ui.webcomponents.main.Input.prototype */ {
253
279
/**
@@ -350,7 +376,7 @@ class Input extends UI5Element {
350
376
}
351
377
352
378
static get staticAreaStyles ( ) {
353
- return ResponsivePopoverCommonCss ;
379
+ return [ ResponsivePopoverCommonCss , ValueStateMessageCss ] ;
354
380
}
355
381
356
382
constructor ( ) {
@@ -383,6 +409,16 @@ class Input extends UI5Element {
383
409
this . suggestionsTexts = [ ] ;
384
410
385
411
this . i18nBundle = getI18nBundle ( "@ui5/webcomponents" ) ;
412
+
413
+ this . _handleResizeBound = this . _handleResize . bind ( this ) ;
414
+ }
415
+
416
+ onEnterDOM ( ) {
417
+ ResizeHandler . register ( this , this . _handleResizeBound ) ;
418
+ }
419
+
420
+ onExitDOM ( ) {
421
+ ResizeHandler . deregister ( this , this . _handleResizeBound ) ;
386
422
}
387
423
388
424
onBeforeRendering ( ) {
@@ -412,6 +448,10 @@ class Input extends UI5Element {
412
448
}
413
449
}
414
450
451
+ if ( ! this . firstRendering && ! this . Suggestions && this . hasValueStateMessage ) {
452
+ this . toggle ( this . shouldDisplayOnlyValueStateMessage ) ;
453
+ }
454
+
415
455
this . firstRendering = false ;
416
456
}
417
457
@@ -477,6 +517,10 @@ class Input extends UI5Element {
477
517
return ;
478
518
}
479
519
520
+ if ( this . popover ) {
521
+ this . popover . close ( false , false , true ) ;
522
+ }
523
+
480
524
this . previousValue = "" ;
481
525
this . focused = false ; // invalidating property
482
526
}
@@ -513,6 +557,12 @@ class Input extends UI5Element {
513
557
}
514
558
}
515
559
560
+ _handleResize ( ) {
561
+ if ( this . hasValueStateMessage ) {
562
+ this . _inputWidth = this . offsetWidth ;
563
+ }
564
+ }
565
+
516
566
_closeRespPopover ( ) {
517
567
this . Suggestions . close ( ) ;
518
568
}
@@ -531,6 +581,41 @@ class Input extends UI5Element {
531
581
}
532
582
}
533
583
584
+ toggle ( isToggled ) {
585
+ if ( isToggled ) {
586
+ this . openPopover ( ) ;
587
+ } else {
588
+ this . closePopover ( ) ;
589
+ }
590
+ }
591
+
592
+ /**
593
+ * Checks if the popover is open.
594
+ * @returns {Boolean } true if the popover is open, false otherwise
595
+ * @public
596
+ */
597
+ isOpen ( ) {
598
+ return ! ! this . _isPopoverOpen ;
599
+ }
600
+
601
+ async openPopover ( ) {
602
+ this . _isPopoverOpen = true ;
603
+ this . popover = await this . _getPopover ( ) ;
604
+ this . popover . openBy ( this ) ;
605
+ }
606
+
607
+ closePopover ( ) {
608
+ if ( this . isOpen ( ) ) {
609
+ this . _isPopoverOpen = false ;
610
+ this . popover . close ( ) ;
611
+ }
612
+ }
613
+
614
+ async _getPopover ( ) {
615
+ const staticAreaItem = await this . getStaticAreaItemDomRef ( ) ;
616
+ return staticAreaItem . querySelector ( "ui5-popover" ) ;
617
+ }
618
+
534
619
enableSuggestions ( ) {
535
620
if ( this . Suggestions ) {
536
621
return ;
@@ -655,6 +740,7 @@ class Input extends UI5Element {
655
740
656
741
return {
657
742
"Success" : i18nBundle . getText ( VALUE_STATE_SUCCESS ) ,
743
+ "Information" : i18nBundle . getText ( VALUE_STATE_INFORMATION ) ,
658
744
"Error" : i18nBundle . getText ( VALUE_STATE_ERROR ) ,
659
745
"Warning" : i18nBundle . getText ( VALUE_STATE_WARNING ) ,
660
746
} ;
@@ -699,10 +785,52 @@ class Input extends UI5Element {
699
785
} ;
700
786
}
701
787
788
+ get classes ( ) {
789
+ return {
790
+ popoverValueState : {
791
+ "ui5-input-valuestatemessage-root" : true ,
792
+ "ui5-input-valuestatemessage-success" : this . valueState === ValueState . Success ,
793
+ "ui5-input-valuestatemessage-error" : this . valueState === ValueState . Error ,
794
+ "ui5-input-valuestatemessage-warning" : this . valueState === ValueState . Warning ,
795
+ "ui5-input-valuestatemessage-information" : this . valueState === ValueState . Information ,
796
+ } ,
797
+ } ;
798
+ }
799
+
800
+ get styles ( ) {
801
+ return {
802
+ root : {
803
+ "min-height" : "1rem" ,
804
+ "box-shadow" : "none" ,
805
+ } ,
806
+ header : {
807
+ "width" : `${ this . _inputWidth } px` ,
808
+ } ,
809
+ } ;
810
+ }
811
+
812
+ get valueStateMessageText ( ) {
813
+ const valueStateMessage = this . valueStateMessage . map ( x => x . cloneNode ( true ) ) ;
814
+
815
+ return valueStateMessage ;
816
+ }
817
+
818
+ get shouldDisplayOnlyValueStateMessage ( ) {
819
+ return this . hasValueStateMessage && ! this . suggestionItems . length && this . focused ;
820
+ }
821
+
822
+ get shouldDisplayDefaultValueStateMessage ( ) {
823
+ return ! this . valueStateMessage . length && this . hasValueStateMessage ;
824
+ }
825
+
702
826
get hasValueState ( ) {
703
827
return this . valueState !== ValueState . None ;
704
828
}
705
829
830
+ get hasValueStateMessage ( ) {
831
+ return this . hasValueState && this . valueState !== ValueState . Success ;
832
+ }
833
+
706
834
get valueStateText ( ) {
707
835
return this . valueStateTextMappings ( ) [ this . valueState ] ;
708
836
}
@@ -712,7 +840,10 @@ class Input extends UI5Element {
712
840
}
713
841
714
842
static async onDefine ( ) {
715
- await fetchI18nBundle ( "@ui5/webcomponents" ) ;
843
+ await Promise . all ( [
844
+ Popover . define ( ) ,
845
+ fetchI18nBundle ( "@ui5/webcomponents" ) ,
846
+ ] ) ;
716
847
}
717
848
}
718
849
0 commit comments