@neovici/cosmoz-autocomplete 13.1.1 → 13.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -24,5 +24,5 @@ export interface Props<I> extends Base<I> {
|
|
|
24
24
|
type AProps<I> = Omit<Props<I>, keyof RProps<I>> & RProps<I> & {
|
|
25
25
|
onInputRef?: (el?: Element) => void;
|
|
26
26
|
};
|
|
27
|
-
declare const autocomplete: <I>(props: AProps<I>) => import("lit-html").TemplateResult<1>, Autocomplete: <I>(props: Props<I>) => import("lit-html").TemplateResult<1>, observedAttributes: readonly ["disabled", "invalid", "no-label-float", "always-float-label", "text-property", "value-property", "limit", "min", "show-single", "preserve-order", "keep-opened", "keep-query", "default-index", "external-search", "item-height", "item-limit", "wrap"];
|
|
27
|
+
declare const autocomplete: <I>(props: AProps<I>) => import("lit-html").TemplateResult<1>, Autocomplete: <I>(props: Props<I>) => import("lit-html").TemplateResult<1>, observedAttributes: readonly ["disabled", "invalid", "no-label-float", "always-float-label", "text-property", "value-property", "limit", "min", "show-single", "preserve-order", "keep-opened", "keep-query", "default-index", "external-search", "item-height", "item-limit", "wrap", "lazy-open"];
|
|
28
28
|
export { Autocomplete, autocomplete, observedAttributes, style };
|
|
@@ -26,8 +26,9 @@ export interface Props<I> extends Base<I> {
|
|
|
26
26
|
preserveOrder?: boolean;
|
|
27
27
|
defaultIndex?: number;
|
|
28
28
|
externalSearch?: boolean;
|
|
29
|
+
lazyOpen?: boolean;
|
|
29
30
|
}
|
|
30
|
-
export declare const useAutocomplete: <I>({ value: _value, text, onChange: _onChange, onText: _onText, onSelect, limit, min, source, textProperty, textual: _textual, valueProperty, keepOpened, keepQuery, preserveOrder, defaultIndex, externalSearch, disabled, }: Props<I>) => {
|
|
31
|
+
export declare const useAutocomplete: <I>({ value: _value, text, onChange: _onChange, onText: _onText, onSelect, limit, min, source, textProperty, textual: _textual, valueProperty, keepOpened, keepQuery, preserveOrder, defaultIndex, externalSearch, disabled, lazyOpen, }: Props<I>) => {
|
|
31
32
|
opened: boolean;
|
|
32
33
|
query: string | undefined;
|
|
33
34
|
textual: (i: I) => string;
|
|
@@ -11,13 +11,15 @@ const useNotify = (host, fn, name) => useCallback((val) => {
|
|
|
11
11
|
fn?.(val);
|
|
12
12
|
host.dispatchEvent(new CustomEvent(name, { detail: val }));
|
|
13
13
|
}, [fn]);
|
|
14
|
-
export const useAutocomplete = ({ value: _value, text, onChange: _onChange, onText: _onText, onSelect, limit, min, source, textProperty, textual: _textual, valueProperty, keepOpened, keepQuery, preserveOrder, defaultIndex, externalSearch, disabled, }) => {
|
|
14
|
+
export const useAutocomplete = ({ value: _value, text, onChange: _onChange, onText: _onText, onSelect, limit, min, source, textProperty, textual: _textual, valueProperty, keepOpened, keepQuery, preserveOrder, defaultIndex, externalSearch, disabled, lazyOpen, }) => {
|
|
15
15
|
const textual = useMemo(() => (_textual ?? strProp)(textProperty), [_textual, textProperty]), host = useHost(), [opened, setOpened] = useProperty('opened', false), empty = !text, query = useMemo(() => text?.trim(), [text]), onText = useNotify(host, _onText, 'text'), onChange = useCallback((val) => {
|
|
16
16
|
_onChange?.(val, () => setOpened(false));
|
|
17
17
|
notify(host, 'value', val);
|
|
18
|
-
}, [_onChange]), [options, setOptions] = useState([]), source$ = useMemo(() =>
|
|
19
|
-
?
|
|
20
|
-
:
|
|
18
|
+
}, [_onChange]), [options, setOptions] = useState([]), belowMinLength = Boolean(lazyOpen && !query), source$ = useMemo(() => belowMinLength
|
|
19
|
+
? Promise.resolve([])
|
|
20
|
+
: Promise.resolve(typeof source === 'function'
|
|
21
|
+
? source({ query, active: opened })
|
|
22
|
+
: source).then(normalize), [source, opened, query, belowMinLength]), value = useMemo(() => array(_value), [_value]);
|
|
21
23
|
useEffect(() => source$.then(setOptions), [source$]);
|
|
22
24
|
// Backspace to deselect last chip (when input is empty and multi-select)
|
|
23
25
|
useActivity({
|
|
@@ -62,6 +64,8 @@ export const useAutocomplete = ({ value: _value, text, onChange: _onChange, onTe
|
|
|
62
64
|
items: useMemo(() => {
|
|
63
65
|
if (!opened)
|
|
64
66
|
return EMPTY;
|
|
67
|
+
if (belowMinLength)
|
|
68
|
+
return EMPTY;
|
|
65
69
|
const items = preserveOrder
|
|
66
70
|
? options
|
|
67
71
|
: [...value, ...without(value, prop(valueProperty))(options)];
|
|
@@ -76,6 +80,7 @@ export const useAutocomplete = ({ value: _value, text, onChange: _onChange, onTe
|
|
|
76
80
|
preserveOrder,
|
|
77
81
|
valueProperty,
|
|
78
82
|
externalSearch,
|
|
83
|
+
belowMinLength,
|
|
79
84
|
]),
|
|
80
85
|
onToggle: useCallback((e) => {
|
|
81
86
|
if (disabled)
|