File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -76,4 +76,36 @@ describe("Behaviour", () => {
7676 cy . get ( "[ui5-shellbar-search]" )
7777 . should ( "have.prop" , "open" , true ) ;
7878 } ) ;
79+
80+ it ( "should collapse and focus the button when Enter is pressed without value" , ( ) => {
81+ cy . mount (
82+ < ShellBarSearch />
83+ ) ;
84+
85+ // Initially expanded
86+ cy . get ( "[ui5-shellbar-search]" )
87+ . should ( "have.prop" , "collapsed" , false ) ;
88+
89+ // Focus the input
90+ cy . get ( "[ui5-shellbar-search]" )
91+ . shadow ( )
92+ . find ( "input" )
93+ . realClick ( ) ;
94+
95+ // Press Enter without value
96+ cy . get ( "[ui5-shellbar-search]" )
97+ . shadow ( )
98+ . find ( "input" )
99+ . realPress ( "Enter" ) ;
100+
101+ // Should be collapsed
102+ cy . get ( "[ui5-shellbar-search]" )
103+ . should ( "have.prop" , "collapsed" , true ) ;
104+
105+ // Focus should be on the search button
106+ cy . get ( "[ui5-shellbar-search]" )
107+ . shadow ( )
108+ . find ( "[ui5-button]" )
109+ . should ( "have.focus" ) ;
110+ } ) ;
79111} ) ;
Original file line number Diff line number Diff line change @@ -53,6 +53,18 @@ class ShellBarSearch extends Search {
5353 }
5454 }
5555
56+ _handleEnter ( ) {
57+ if ( ! this . value && ! this . collapsed ) {
58+ this . collapsed = true ;
59+
60+ setTimeout ( ( ) => {
61+ this . focus ( ) ;
62+ } , 0 ) ;
63+ } else {
64+ super . _handleEnter ( ) ;
65+ }
66+ }
67+
5668 _onFocusOutSearch ( e : FocusEvent ) {
5769 if ( isPhone ( ) ) {
5870 return ;
You can’t perform that action at this time.
0 commit comments