add support for multiterm search

This commit is contained in:
Hugo Bidois 2022-07-01 18:51:48 +02:00 committed by GitHub
parent c194763386
commit 6519daeaef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -34,7 +34,7 @@ document.addEventListener('DOMContentLoaded', () => {
let matchCount = 0;
rec.forEach(el => {
const recipeName = el.textContent.toLowerCase()
const isMatch = recipeName.includes(searchText)
const isMatch = searchText.split(' ').every(term => recipeName.includes(term))
el.hidden = !isMatch
el.classList.toggle('matched-recipe', isMatch && searchText.length !== 0);