1717{ {!
1818 @template core/search_input_navbar_inline
1919
20- Inline navbar search input for desktop. Always visible, no collapse or toggle.
20+ Navbar search input using the inline field design. The field is always
21+ visible on desktop. On small screens only a toggle button is shown and
22+ the field expands across the navbar, with a close button inside the field.
2123
2224 Example context (json):
2325 {
3436 }
3537}}
3638<div id =" searchinput-navbar" class =" search-input-inline" >
39+ <button type =" button"
40+ class =" nav-link icon-no-margin search-toggle"
41+ data-action =" opensearch"
42+ aria-expanded =" false"
43+ aria-controls =" searchform-navbar-inline"
44+ title =" { { #str} } togglesearch { { /str} } " >
45+ { {#pix} } a/search, core { {/pix} }
46+ <span class =" visually-hidden" >{ {#str} } togglesearch { {/str} }</span >
47+ </button >
3748 <form role =" search"
49+ id =" searchform-navbar-inline"
3850 { { #grouplabel} } aria-label =" { { { grouplabel } } } " { { /grouplabel} }
3951 autocomplete =" off"
4052 action =" { { { action } } } "
5769 name =" { { { inputname } } } "
5870 data-region =" input"
5971 autocomplete =" off" >
72+ <button type =" button"
73+ class =" search-close d-md-none"
74+ data-action =" closesearch" >
75+ { {#pix} } e/cancel, core { {/pix} }
76+ <span class =" visually-hidden" >{ {#str} } closebuttontitle { {/str} }</span >
77+ </button >
6078 </div >
6179 </form >
6280</div >
@@ -66,11 +84,26 @@ require([], function() {
6684 const wrapper = document.getElementById(' searchinput-navbar' );
6785 const form = wrapper.querySelector(' .searchform-navbar' );
6886 const input = wrapper.querySelector(' [data-region="input"]' );
87+ const opensearch = wrapper.querySelector(' [data-action="opensearch"]' );
88+ const closesearch = wrapper.querySelector(' [data-action="closesearch"]' );
6989
7090 form.addEventListener(' submit' , (e) => {
7191 if (input.value.trim() === ' ' ) {
7292 e.preventDefault();
7393 }
7494 });
95+
96+ opensearch.addEventListener('click', () => {
97+ wrapper.classList.add(' expanded' );
98+ opensearch.setAttribute(' aria-expanded' , ' true' );
99+ input.focus();
100+ } );
101+
102+ closesearch.addEventListener('click', () => {
103+ wrapper.classList.remove(' expanded' );
104+ opensearch.setAttribute(' aria-expanded' , ' false' );
105+ input.value = ' ' ;
106+ opensearch.focus();
107+ } );
75108});
76109{ {/js} }
0 commit comments