Skip to content

Commit 8a6fd2f

Browse files
committed
add clear search button
1 parent 9891f52 commit 8a6fd2f

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

components/search-hieroglyphs/SearchHieroglyphs.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ class SearchHieroglyphs extends HTMLElement {
99
this.db = hieroglyphDb
1010

1111
this.innerHTML = `
12-
<div class="results-info"></div>
13-
<div class="results">
14-
</div>
12+
<div class="results-info"></div>
13+
<div class="results"></div>
1514
`
1615

1716
this.listen()
@@ -31,9 +30,12 @@ class SearchHieroglyphs extends HTMLElement {
3130

3231
renderResultsInfo(query={}, results=this.db.hieroglyphs){
3332
if(Object.entries(query).length > 0){
34-
let queryInfo = document.createElement('div')
35-
queryInfo.textContent = `Your search for "${this.stringifyQuery(query)}" had ${results.length} result${results.length !== 1 ? 's' : ''}.`
36-
this.querySelector('.results-info').append(queryInfo)
33+
this.querySelector('.results-info')
34+
.innerHTML = `Your search for "${this.stringifyQuery(query)}" had ${results.length} result${results.length !== 1 ? 's' : ''}. `
35+
36+
this.querySelector('.results-info')
37+
.insertAdjacentHTML('beforeend', `<button class=clear-results-button>Clear</button>`)
38+
3739
}
3840
}
3941

@@ -63,9 +65,15 @@ class SearchHieroglyphs extends HTMLElement {
6365
}
6466

6567
listen(){
68+
this.addEventListener('click', clickEvent => {
69+
if(clickEvent.target.matches('.clear-results-button')){
70+
this.renderResults()
71+
}
72+
})
73+
6674
this.addEventListener('hieroglyph-clicked', hieroglyphClickedEvent => {
6775
let hieroglyph = hieroglyphClickedEvent.detail
68-
console.log(hieroglyph)
76+
this.search(`hieroglyph:${hieroglyph.hieroglyph}`)
6977
})
7078

7179
this.addEventListener('category-clicked', categoryClickedEvent => {

index.html

-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
<header>
1313

1414
<h1><span class=hieroglyph>𓏞</span>&nbsp;glyphical</h1>
15-
<!-- <svg viewBox="0 0 96 18">
16-
<text x="0" y="15"><tspan>𓏞</tspan> hieroglyphical</text>
17-
</svg> -->
1815

1916
<form id="main-search">
2017
<input type="search" autocapitalize=off placeholder="𓃦 Search" spellcheck="false">

0 commit comments

Comments
 (0)