@@ -75,7 +75,18 @@ function createComponent(html) {
7575 searchResults . style . display = 'block' ;
7676 } )
7777 // On blur of search
78- searchInput . addEventListener ( 'blur' , ( ) => { searchBar . classList . remove ( 'search-bar-focused' ) } ) ;
78+ searchInput . addEventListener ( 'blur' , ( ) => {
79+ searchBar . classList . remove ( 'search-bar-focused' ) ;
80+ } )
81+ // On input of search
82+ searchInput . addEventListener ( 'input' , ( ) => {
83+ // Display clear search button if input is added
84+ if ( searchInput . value . length > 0 ) {
85+ clearIcon . style . display = 'block' ;
86+ } else {
87+ clearIcon . style . display = 'none' ;
88+ }
89+ } )
7990
8091 // Clear search
8192 clearIcon . addEventListener ( 'click' , ( ) => { this . clearSearch ( ) } ) ;
@@ -112,19 +123,17 @@ function createComponent(html) {
112123 const menuItems = dropdownMenu . querySelectorAll ( 'a' ) ;
113124
114125 // Update checked state of menuToggle
115- var checkedState = menuToggle . checked ? false : true ;
126+ let checkedState = menuToggle . checked ? false : true ;
116127 menuToggle . checked = checkedState ;
117128 // Update display of dropdown menu based on checked state
118129 if ( checkedState ) {
119130 dropdownMenu . classList . add ( 'show-menu' ) ;
120- // dropdownMenu.style.maxHeight = '60em';
121131 // Make menu items focusable
122132 for ( let i = 0 ; i < menuItems . length ; i ++ ) {
123133 menuItems [ i ] . tabIndex = '0' ;
124134 }
125135 } else {
126136 dropdownMenu . classList . remove ( 'show-menu' ) ;
127- // dropdownMenu.style.maxHeight = '0em';
128137 // Make menu items non-focusable
129138 for ( let i = 0 ; i < menuItems . length ; i ++ ) {
130139 menuItems [ i ] . tabIndex = '-1' ;
@@ -140,8 +149,8 @@ function createComponent(html) {
140149 const button = event . target ;
141150 const parent = button . parentElement ;
142151 const grandparent = parent . parentElement ;
143- var arrow ;
144- var description ;
152+ let arrow ;
153+ let description ;
145154
146155 // Check if user clicked on button - assign variables
147156 if ( button . classList . contains ( 'cordion' ) ) {
@@ -163,6 +172,7 @@ function createComponent(html) {
163172 const shadow = component . shadowRoot ;
164173 const searchResults = shadow . getElementById ( 'search-results' ) ;
165174 const searchInput = shadow . getElementById ( 'search-input' ) ;
175+ const clearIcon = shadow . getElementById ( 'clear-icon' ) ;
166176
167177 // Remove input value
168178 searchInput . value = "" ;
@@ -171,6 +181,8 @@ function createComponent(html) {
171181 $ ( searchInput ) . tipuesearch ( input , searchInput , searchResults , 'web-component' ) ;
172182 // Hide search results
173183 searchResults . style . display = 'none' ;
184+ // Hide clear search button
185+ clearIcon . style . display = 'none' ;
174186 }
175187 }
176188
0 commit comments