@@ -25,7 +25,7 @@ import Icon from "@ui5/webcomponents/dist/Icon.js";
25
25
import type Input from "@ui5/webcomponents/dist/Input.js" ;
26
26
import type { IButton } from "@ui5/webcomponents/dist/Button.js" ;
27
27
import type I18nBundle from "@ui5/webcomponents-base/dist/i18nBundle.js" ;
28
- import { isDesktop } from "@ui5/webcomponents-base/dist/Device.js" ;
28
+ import { isDesktop , isPhone } from "@ui5/webcomponents-base/dist/Device.js" ;
29
29
import search from "@ui5/webcomponents-icons/dist/search.js" ;
30
30
import da from "@ui5/webcomponents-icons/dist/da.js" ;
31
31
import bell from "@ui5/webcomponents-icons/dist/bell.js" ;
@@ -368,6 +368,16 @@ class ShellBar extends UI5Element {
368
368
@property ( { type : Boolean } )
369
369
showProductSwitch = false ;
370
370
371
+ /**
372
+ * Defines, if the Search Field would be displayed when there is a valid `searchField` slot.
373
+ *
374
+ * **Note:** By default the Search Field is not displayed.
375
+ * @default false
376
+ * @public
377
+ */
378
+ @property ( { type : Boolean } )
379
+ showSearchField = false ;
380
+
371
381
/**
372
382
* Defines additional accessibility attributes on different areas of the component.
373
383
*
@@ -541,7 +551,9 @@ class ShellBar extends UI5Element {
541
551
_autoRestoreSearchField = false ;
542
552
543
553
_headerPress : ( ) => void ;
544
- _showSearchField = false ;
554
+ onSearchOpen : ( ) => void ;
555
+ onSearchClose : ( ) => void ;
556
+ onSearch : ( ) => void ;
545
557
546
558
static get FIORI_3_BREAKPOINTS ( ) {
547
559
return [
@@ -585,6 +597,24 @@ class ShellBar extends UI5Element {
585
597
}
586
598
} ;
587
599
600
+ this . onSearchOpen = ( ) => {
601
+ if ( isPhone ( ) ) {
602
+ this . setSearchState ( true ) ;
603
+ }
604
+ } ;
605
+
606
+ this . onSearchClose = ( ) => {
607
+ if ( isPhone ( ) ) {
608
+ this . setSearchState ( false ) ;
609
+ }
610
+ } ;
611
+
612
+ this . onSearch = ( ) => {
613
+ if ( ! isPhone ( ) && ! this . search ?. value ) {
614
+ this . setSearchState ( ! this . showSearchField ) ;
615
+ }
616
+ } ;
617
+
588
618
this . _handleResize = throttle ( ( ) => {
589
619
this . menuPopover = this . _getMenuPopover ( ) ;
590
620
this . overflowPopover = this . _getOverflowPopover ( ) ;
@@ -764,35 +794,30 @@ class ShellBar extends UI5Element {
764
794
} ) ;
765
795
766
796
this . _observeContentItems ( ) ;
767
- }
768
797
769
- /**
770
- * Defines, if the Search Field would be displayed when there is a valid `searchField` slot.
771
- *
772
- * **Note:** By default the Search Field is not displayed.
773
- * @default false
774
- * @public
775
- */
776
- @property ( { type : Boolean } )
777
- set showSearchField ( value : boolean ) {
778
- if ( isSelfCollapsibleSearch ( this . search ) ) {
779
- this . search . collapsed = ! value ;
798
+ // search field shouldn't be expanded initially in full width mode
799
+ if ( this . showFullWidthSearch && this . _isInitialRendering ) {
800
+ this . setSearchState ( false ) ;
801
+ this . _autoRestoreSearchField = true ;
780
802
}
781
- this . _showSearchField = value ;
782
- }
783
803
784
- get showSearchField ( ) : boolean {
785
804
if ( isSelfCollapsibleSearch ( this . search ) ) {
786
- return ! this . search . collapsed ;
805
+ if ( isPhone ( ) ) {
806
+ this . search . open = this . showSearchField ;
807
+ } else {
808
+ this . search . collapsed = ! this . showSearchField ;
809
+ }
787
810
}
788
- return this . _showSearchField ;
789
811
}
790
812
791
813
/**
792
814
* Use this method to change the state of the search filed according to internal logic.
793
815
* An event is fired to notify the change.
794
816
*/
795
817
async setSearchState ( expanded : boolean ) {
818
+ if ( expanded === this . showSearchField ) {
819
+ return ;
820
+ }
796
821
this . showSearchField = expanded ;
797
822
await renderFinished ( ) ;
798
823
this . fireDecoratorEvent ( "search-field-toggle" , { expanded } ) ;
@@ -907,6 +932,13 @@ class ShellBar extends UI5Element {
907
932
908
933
onEnterDOM ( ) {
909
934
ResizeHandler . register ( this , this . _handleResize ) ;
935
+
936
+ if ( isSelfCollapsibleSearch ( this . search ) ) {
937
+ this . search . addEventListener ( "ui5-open" , this . onSearchOpen ) ;
938
+ this . search . addEventListener ( "ui5-close" , this . onSearchClose ) ;
939
+ this . search . addEventListener ( "ui5-search" , this . onSearch ) ;
940
+ }
941
+
910
942
if ( isDesktop ( ) ) {
911
943
this . setAttribute ( "desktop" , "" ) ;
912
944
}
@@ -916,6 +948,12 @@ class ShellBar extends UI5Element {
916
948
this . contentItemsObserver . disconnect ( ) ;
917
949
this . _observableContent = [ ] ;
918
950
ResizeHandler . deregister ( this , this . _handleResize ) ;
951
+
952
+ if ( isSelfCollapsibleSearch ( this . search ) ) {
953
+ this . search . removeEventListener ( "ui5-open" , this . onSearchOpen ) ;
954
+ this . search . removeEventListener ( "ui5-close" , this . onSearchClose ) ;
955
+ this . search . removeEventListener ( "ui5-search" , this . onSearch ) ;
956
+ }
919
957
}
920
958
921
959
_handleSearchIconPress ( ) {
@@ -1636,11 +1674,12 @@ class ShellBar extends UI5Element {
1636
1674
1637
1675
interface IShellBarSelfCollapsibleSearch {
1638
1676
collapsed : boolean ;
1677
+ open : boolean ;
1639
1678
}
1640
1679
1641
1680
const isSelfCollapsibleSearch = ( searchField : any ) : searchField is IShellBarSelfCollapsibleSearch => {
1642
1681
if ( searchField ) {
1643
- return "collapsed" in searchField ;
1682
+ return "collapsed" in searchField && "open" in searchField ;
1644
1683
}
1645
1684
return false ;
1646
1685
} ;
0 commit comments