Skip to content

Commit f17570f

Browse files
committed
hide clear icon for search until input added
1 parent 642591a commit f17570f

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

web-components/nav-header/nav-header.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ form div > img {
8282

8383
#clear-icon {
8484
cursor: pointer;
85+
display: none;
8586
}
8687

8788
.logo {

web-components/nav-header/nav-header.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)