Skip to content

Commit

Permalink
docs: filter url by search query (#731)
Browse files Browse the repository at this point in the history
  • Loading branch information
korki43 committed Mar 26, 2023
1 parent 213e8a6 commit 3b27adc
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion docs/assets/js/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
(function () {
'use strict'

new List('icons-body', {
const searchInput = document.querySelector('#icons-body #search')
const query = new URLSearchParams(window.location.search).get('q')
const iconList = new List('icons-body', {
searchDelay: 250,
valueNames: [
'name', {
Expand All @@ -14,4 +16,23 @@
}
]
})

if (query) {
document.querySelector('#content').scrollIntoView()
searchInput.value = query
iconList.search(query)
}

iconList.on('searchComplete', () => {
const searchTerm = searchInput.value
const newUrl = new URL(window.location)

if (searchTerm.length > 0) {
newUrl.searchParams.set('q', searchTerm)
} else {
newUrl.searchParams.delete('q')
}

window.history.replaceState(null, null, newUrl)
})
})()

0 comments on commit 3b27adc

Please sign in to comment.