aboutsummaryrefslogtreecommitdiff
path: root/src/composable/fuzzySearch.ts
diff options
context:
space:
mode:
authorGravatar Corentin THOMASSET <corentin.thomasset74@gmail.com> 2023-08-07 17:30:00 +0200
committerGravatar GitHub <noreply@github.com> 2023-08-07 15:30:00 +0000
commitdfa1ba85548508e680f68200ea521be95c3eafe0 (patch)
treec166b635e5eb006806bd40a88252d90735be9ca4 /src/composable/fuzzySearch.ts
parent6498c9b0fa0427d567506dbd4a6e87d227b138d4 (diff)
downloadit-tools-dfa1ba85548508e680f68200ea521be95c3eafe0.tar.gz
it-tools-dfa1ba85548508e680f68200ea521be95c3eafe0.tar.zst
it-tools-dfa1ba85548508e680f68200ea521be95c3eafe0.zip
feat(ui): added c-select in the ui lib (#550)
* feat(ui): added c-select in the ui lib * refactor(ui): switched n-select to c-select
Diffstat (limited to 'src/composable/fuzzySearch.ts')
-rw-r--r--src/composable/fuzzySearch.ts13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/composable/fuzzySearch.ts b/src/composable/fuzzySearch.ts
index 66480f7..00794fd 100644
--- a/src/composable/fuzzySearch.ts
+++ b/src/composable/fuzzySearch.ts
@@ -11,12 +11,19 @@ function useFuzzySearch<Data>({
}: {
search: MaybeRef<string>
data: Data[]
- options?: Fuse.IFuseOptions<Data>
+ options?: Fuse.IFuseOptions<Data> & { filterEmpty?: boolean }
}) {
const fuse = new Fuse(data, options);
+ const filterEmpty = options.filterEmpty ?? true;
- const searchResult = computed(() => {
- return fuse.search(get(search)).map(({ item }) => item);
+ const searchResult = computed<Data[]>(() => {
+ const query = get(search);
+
+ if (!filterEmpty && query === '') {
+ return data;
+ }
+
+ return fuse.search(query).map(({ item }) => item);
});
return { searchResult };