From 25715f712f1356e12adc90acecba4acb7a45155d Mon Sep 17 00:00:00 2001 From: Brian Krausz Date: Fri, 17 Jan 2025 00:31:56 -0800 Subject: [PATCH] Preserve integration category filter on noop keyup (#36844) --- source/integrations/index.html | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/source/integrations/index.html b/source/integrations/index.html index 24ffeaeccbe..908979ca990 100644 --- a/source/integrations/index.html +++ b/source/integrations/index.html @@ -67,7 +67,7 @@ regenerate: false {%- assign category_name = cat -%} {%- endif -%} {%- endfor -%} - {%- endif -%} + {%- endif -%} {%- assign components_count = components_count | plus: 1 -%} {%- endif -%} {%- endfor -%} @@ -98,7 +98,7 @@ regenerate: false {%- assign category_name = cat -%} {%- endif -%} {%- endfor -%} - {%- endif -%} + {%- endif -%} {%- assign components_count = components_count | plus: 1 -%} {%- endif -%} {%- endfor -%} @@ -208,7 +208,7 @@ allComponents.pop(); // remove placeholder element at the end if (hash.indexOf(SEARCH_PREFIX) === 0) { // search through title and category search = decodeURIComponent(hash).substring(SEARCH_PREFIX.length).toLowerCase(); - filter = comp => + filter = comp => comp.search.indexOf(search) !== -1 || comp.cat.find((c) => c.includes("#")) != undefined; @@ -309,17 +309,19 @@ allComponents.pop(); // remove placeholder element at the end }; // update view by search text + let lastSearchText = ''; searchInputEl.addEventListener('keyup', debounce(() => { const text = searchInputEl.value // sanitize input .replace(/[(\?|\&\{\}\(\))]/gi, '') .trim(); - - let newHash = typeof text === "string" && text.length >= 1 - ? SEARCH_PREFIX + text - : '#all'; - // Only apply filter if hash has changed - if (newHash !== window.location.hash) { + + // Only apply filter if value has changed + if (lastSearchText !== text) { + lastSearchText = text; + const newHash = typeof text === "string" && text.length >= 1 + ? SEARCH_PREFIX + text + : '#all'; history.pushState('', '', newHash); applyFilter(); }