From c41f839a6af62bcd090e7ce7c89f67395b54cb2a Mon Sep 17 00:00:00 2001 From: Flo2410 Date: Thu, 8 Feb 2024 19:54:12 +0000 Subject: [PATCH] Added tab complete to search box. --- src/components/widgets/search/search.jsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/components/widgets/search/search.jsx b/src/components/widgets/search/search.jsx index 21c933d2..2a05b1b2 100644 --- a/src/components/widgets/search/search.jsx +++ b/src/components/widgets/search/search.jsx @@ -121,8 +121,19 @@ export default function Search({ options }) { const handleSearchKeyDown = (event) => { if (event.key === "Tab") { - // TODO: add actual tab complete event.preventDefault(); + + const list = document.getElementById("comboboxOptions").getElementsByTagName("li"); + if (list.length === 0) { + return; + } + + for (let i = 0; i < list.length; i += 1) { + const item = list.item(i); + if (item.getAttribute("data-headlessui-state") === "active") { + setQuery(item.textContent); + } + } } }; @@ -233,7 +244,10 @@ export default function Search({ options }) { {searchSuggestions[1]?.length > 0 && ( - +
{searchSuggestions[1].map((suggestion) => (