@neovici/cosmoz-autocomplete 10.7.1 → 10.7.2
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.
|
@@ -27,12 +27,11 @@ const middleware = [
|
|
|
27
27
|
}),
|
|
28
28
|
...defaultMiddleware,
|
|
29
29
|
];
|
|
30
|
-
const shouldShowDropdown = ({ active,
|
|
30
|
+
const shouldShowDropdown = ({ active, isSingle, showSingle, }) => {
|
|
31
31
|
if (!active)
|
|
32
32
|
return false;
|
|
33
|
-
const hasResultsOrQuery = loading || items.length > 0 || (text != null && text.length > 0);
|
|
34
33
|
const disallowedSingle = isSingle && !showSingle;
|
|
35
|
-
return
|
|
34
|
+
return !disallowedSingle;
|
|
36
35
|
};
|
|
37
36
|
const autocomplete = (props) => {
|
|
38
37
|
const { active, invalid, errorMessage, label, placeholder, disabled, noLabelFloat, alwaysFloatLabel, textual, text, onText, onFocus, onClick, onDeselect, value, limit, min, showSingle, items, source$, placement, loading, } = props, host = useHost(), isOne = limit == 1, // eslint-disable-line eqeqeq
|
|
@@ -52,6 +51,7 @@ const autocomplete = (props) => {
|
|
|
52
51
|
useImperativeApi({
|
|
53
52
|
focus: () => host.shadowRoot?.querySelector('#input')?.focus(),
|
|
54
53
|
}, []);
|
|
54
|
+
const hasResultsOrQuery = loading || items.length > 0 || (text != null && text.length > 0);
|
|
55
55
|
return html `<cosmoz-input
|
|
56
56
|
id="input"
|
|
57
57
|
part="input"
|
|
@@ -86,9 +86,6 @@ const autocomplete = (props) => {
|
|
|
86
86
|
|
|
87
87
|
${when(shouldShowDropdown({
|
|
88
88
|
active,
|
|
89
|
-
loading,
|
|
90
|
-
items,
|
|
91
|
-
text,
|
|
92
89
|
isSingle,
|
|
93
90
|
showSingle,
|
|
94
91
|
}), () => listbox({
|
|
@@ -96,7 +93,12 @@ const autocomplete = (props) => {
|
|
|
96
93
|
items,
|
|
97
94
|
multi: !isOne,
|
|
98
95
|
setFloating,
|
|
99
|
-
styles
|
|
96
|
+
styles: {
|
|
97
|
+
...styles,
|
|
98
|
+
// WORKAROUND: hide the listbox if there are no results, don't remove it from DOM
|
|
99
|
+
// TODO: revert https://github.com/Neovici/cosmoz-autocomplete/pull/206 after https://github.com/pionjs/pion/issues/64 is fixed
|
|
100
|
+
display: hasResultsOrQuery ? undefined : 'none',
|
|
101
|
+
},
|
|
100
102
|
}, when(loading, () => html `<cosmoz-autocomplete-skeleton-span></cosmoz-autocomplete-skeleton-span>`, () => when(text != null && text.length > 0 && items.length === 0, () => html `<slot name="no-result"></slot>`))))}`;
|
|
101
103
|
}, Autocomplete = (props) => {
|
|
102
104
|
const thru = {
|