Skip to content

Commit 578de55

Browse files
authored
feat: export Source (#212)
* feat: export Source Re NEO-54 * fix: source can return undefined
1 parent fc83b8b commit 578de55

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

src/autocomplete/use-autocomplete.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import { useKeys } from './use-keys';
88
import { search, normalize, notify, useNotify, EMPTY } from './util';
99
import { usePromise } from '@neovici/cosmoz-utils/hooks/use-promise';
1010

11-
type Source<I> = (opts: {
11+
export type Source<I> = (opts: {
1212
query?: string;
1313
active?: boolean;
14-
}) => PromiseLike<I[]>;
14+
}) => PromiseLike<I[]> | undefined;
1515

1616
interface Base<I> {
1717
value?: I | I[];
@@ -188,7 +188,7 @@ export const useAutocomplete = <I>({
188188
[meta],
189189
),
190190
// whenever there is a query, override defaultIndex to 0, so the first result gets selected
191-
defaultIndex: (query !== undefined && query?.length > 0) ? 0 : defaultIndex,
191+
defaultIndex: query !== undefined && query?.length > 0 ? 0 : defaultIndex,
192192
};
193193
};
194194

src/autocomplete/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const search = <I>(
3838
return matches.sort((a, b) => a.index - b.index).map(({ item }) => item);
3939
};
4040

41-
export const normalize = <I>(source: I[] | false | null) => {
41+
export const normalize = <I>(source: I[] | false | null | undefined) => {
4242
if (source === false || source == null) return [];
4343
return source;
4444
};

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
import './autocomplete/';
2+
export type { Source } from './autocomplete/use-autocomplete';

0 commit comments

Comments
 (0)