Skip to content

Commit b6bf3a3

Browse files
committed
hide results after result selected in search
1 parent 1b7a1bd commit b6bf3a3

3 files changed

Lines changed: 37 additions & 3 deletions

File tree

jekyll-tipue-search/assets/tipuesearch/css/tipuesearch-component.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,13 @@
4141
}
4242

4343
/* TITLE */
44+
.tipue_search_content_title {
45+
width: 100%;
46+
}
47+
4448
.tipue_search_content_title a {
4549
color: black;
50+
display: block;
4651
padding-left: 2em;
4752
}
4853

jekyll-tipue-search/assets/tipuesearch/tipuesearch.min.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,5 +620,20 @@ function getTipueSearch(start, replace, set, searchResults, searchInputId, tipue
620620
description.classList.toggle('search_content_drop');
621621
});
622622
})
623+
624+
const results = shadow.querySelectorAll('.tipue_search_content_title');
625+
const searchResultsBox = shadow.getElementById('search-results');
626+
const searchInput = shadow.getElementById('search-input');
627+
results.forEach(result => {
628+
result.addEventListener('click', () => {
629+
// Remove input value
630+
searchInput.value = "";
631+
const input = searchInput.value;
632+
// Make search call
633+
$(searchInput).tipuesearch(input, searchInput, searchResultsBox, 'web-component');
634+
// Hide search results
635+
searchResultsBox.style.display = 'none';
636+
})
637+
})
623638
}
624639
}

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,15 @@ function createComponent(html) {
104104
const input = searchInput.value;
105105
// Make search call
106106
$(searchInput).tipuesearch(input, searchInput, searchResults, 'web-component');
107-
// Get dropdown search results
107+
// Get search results
108+
const results = shadow.querySelectorAll('.tipue_search_content_title');
109+
results.forEach(result => {
110+
result.addEventListener('click', this.handleResultClick.bind(this));
111+
})
112+
// Get dropdowns from search results
108113
const accordions = shadow.querySelectorAll('.cordion');
109114
accordions.forEach(accordion => {
110-
accordion.addEventListener('click', this.handleResultsDropdown.bind(this));
115+
accordion.addEventListener('click', this.handleResultDropdown.bind(this));
111116
})
112117
});
113118

@@ -141,7 +146,7 @@ function createComponent(html) {
141146
}
142147

143148
// Handle search result dropdown interaction
144-
handleResultsDropdown(event) {
149+
handleResultDropdown(event) {
145150
const button = event.target;
146151
const parent = button.parentElement;
147152
const grandparent = parent.parentElement;
@@ -161,6 +166,15 @@ function createComponent(html) {
161166
description.classList.toggle('search_content_drop');
162167
}
163168

169+
// Clear search after result is clicked
170+
handleResultClick() {
171+
const component = document.querySelector('nav-header');
172+
const shadow = component.shadowRoot;
173+
const searchResults = shadow.getElementById('search-results');
174+
const searchInput = shadow.getElementById('search-input');
175+
this.clearSearch(searchInput, searchResults);
176+
}
177+
164178
// Clear search
165179
clearSearch(searchInput, searchResults) {
166180
// Remove input value

0 commit comments

Comments
 (0)