sveltacular 0.0.20 → 0.0.21
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.
|
@@ -11,6 +11,7 @@ export let size = "full";
|
|
|
11
11
|
export let disabled = false;
|
|
12
12
|
export let required = false;
|
|
13
13
|
export let searchable = false;
|
|
14
|
+
export let search = void 0;
|
|
14
15
|
const getText = () => items.find((item) => item.value == value)?.name || "";
|
|
15
16
|
const onSelect = (e) => {
|
|
16
17
|
value = e.detail.value;
|
|
@@ -52,10 +53,19 @@ const onInputKeyPress = (e) => {
|
|
|
52
53
|
triggerSearch();
|
|
53
54
|
}
|
|
54
55
|
};
|
|
55
|
-
const triggerSearch = debounce(() => {
|
|
56
|
+
const triggerSearch = debounce(async () => {
|
|
56
57
|
dispatch("search", searchText);
|
|
58
|
+
if (search) {
|
|
59
|
+
items = await search(searchText);
|
|
60
|
+
text = getText();
|
|
61
|
+
}
|
|
57
62
|
}, 300);
|
|
58
63
|
const dispatch = createEventDispatcher();
|
|
64
|
+
const updateText = async () => {
|
|
65
|
+
const textBox = document.getElementById(id);
|
|
66
|
+
if (document.activeElement != textBox)
|
|
67
|
+
text = getText();
|
|
68
|
+
};
|
|
59
69
|
const id = uniqueId();
|
|
60
70
|
let text = getText();
|
|
61
71
|
let open = false;
|
|
@@ -65,7 +75,8 @@ $:
|
|
|
65
75
|
$:
|
|
66
76
|
filteredItems = searchText ? items.map((item, index) => ({ ...item, index })).filter((item) => item.name.toLowerCase().includes(searchText.toLowerCase())) : items.map((item, index) => ({ ...item, index }));
|
|
67
77
|
$:
|
|
68
|
-
items && (
|
|
78
|
+
items && updateText();
|
|
79
|
+
triggerSearch();
|
|
69
80
|
</script>
|
|
70
81
|
|
|
71
82
|
<FormField {size}>
|