@onsvisual/svelte-components 1.0.21 → 1.0.23
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.
|
@@ -26,8 +26,10 @@
|
|
|
26
26
|
</div>
|
|
27
27
|
{/snippet}
|
|
28
28
|
|
|
29
|
+
<Story name="Default" args={{ id: "default", label: "Select an option", options }} {template} />
|
|
30
|
+
|
|
29
31
|
<Story
|
|
30
|
-
name="
|
|
32
|
+
name="Pre-selected value"
|
|
31
33
|
args={{ id: "default", value: options[0], label: "Select an option", options }}
|
|
32
34
|
{template}
|
|
33
35
|
/>
|
|
@@ -100,13 +100,8 @@
|
|
|
100
100
|
* @type {function}
|
|
101
101
|
*/
|
|
102
102
|
export async function clearInput() {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
await sleep(110);
|
|
106
|
-
inputElement.focus({ preventScroll: true });
|
|
107
|
-
inputElement.blur();
|
|
108
|
-
hideMenu = false;
|
|
109
|
-
dispatch("clear", value);
|
|
103
|
+
await setInputValue(null);
|
|
104
|
+
dispatch("clear", null);
|
|
110
105
|
}
|
|
111
106
|
/**
|
|
112
107
|
* Optional: Set an additional CSS class for the component
|
|
@@ -114,6 +109,15 @@
|
|
|
114
109
|
*/
|
|
115
110
|
export let cls = null;
|
|
116
111
|
|
|
112
|
+
async function setInputValue(textValue) {
|
|
113
|
+
hideMenu = true;
|
|
114
|
+
inputElement.value = textValue || "";
|
|
115
|
+
await sleep(110);
|
|
116
|
+
inputElement.focus({ preventScroll: true });
|
|
117
|
+
inputElement.blur();
|
|
118
|
+
hideMenu = false;
|
|
119
|
+
}
|
|
120
|
+
|
|
117
121
|
function inputValueTemplate(result) {
|
|
118
122
|
return result && result[labelKey];
|
|
119
123
|
}
|
|
@@ -138,11 +142,13 @@
|
|
|
138
142
|
}
|
|
139
143
|
|
|
140
144
|
async function select(option) {
|
|
141
|
-
value
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
145
|
+
if (option && value !== option) {
|
|
146
|
+
value = option;
|
|
147
|
+
dispatch("change", value);
|
|
148
|
+
if (value && autoClear) {
|
|
149
|
+
await sleep(0);
|
|
150
|
+
clearInput();
|
|
151
|
+
}
|
|
146
152
|
}
|
|
147
153
|
}
|
|
148
154
|
|
|
@@ -163,7 +169,6 @@
|
|
|
163
169
|
id,
|
|
164
170
|
name: `${id}-input`,
|
|
165
171
|
source: loadOptions,
|
|
166
|
-
defaultValue: value?.[labelKey] || "",
|
|
167
172
|
autoselect: true,
|
|
168
173
|
onConfirm: select,
|
|
169
174
|
confirmOnBlur: false,
|
|
@@ -177,10 +182,21 @@
|
|
|
177
182
|
suggestion: suggestionTemplate
|
|
178
183
|
}
|
|
179
184
|
});
|
|
180
|
-
inputElement =
|
|
185
|
+
inputElement = element.querySelector(`#${id}`);
|
|
186
|
+
setInputValue(value?.[labelKey] || "");
|
|
181
187
|
inputElement.addEventListener("blur", inputChange);
|
|
182
188
|
}
|
|
183
189
|
|
|
190
|
+
// In case input value is updated from outside component
|
|
191
|
+
function bindInputValue(value) {
|
|
192
|
+
if (inputElement) {
|
|
193
|
+
const textValue = value?.[labelKey];
|
|
194
|
+
if (textValue && inputElement.value !== textValue) setInputValue(textValue);
|
|
195
|
+
else if (!value && inputElement.value) setInputValue("");
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
$: bindInputValue(value);
|
|
199
|
+
|
|
184
200
|
onMount(handleScriptLoad);
|
|
185
201
|
</script>
|
|
186
202
|
|
|
@@ -33,20 +33,18 @@
|
|
|
33
33
|
</script>
|
|
34
34
|
|
|
35
35
|
<div {id} class="ons-accordion {cls}" bind:this={el}>
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
<button
|
|
37
|
+
type="button"
|
|
38
|
+
class="ons-btn ons-accordion__toggle-all ons-u-mb-s ons-u-d-no ons-btn--secondary ons-btn--small"
|
|
39
|
+
class:hide-toggle={!showToggle}
|
|
40
|
+
data-close-all="Hide all"
|
|
41
|
+
data-group={id}
|
|
42
|
+
bind:this={buttonEl}
|
|
43
|
+
>
|
|
44
|
+
<span class="ons-btn__inner ons-accordion__toggle-all-inner"
|
|
45
|
+
><span class="ons-btn__text">Show all</span></span
|
|
44
46
|
>
|
|
45
|
-
|
|
46
|
-
><span class="ons-btn__text">Show all</span></span
|
|
47
|
-
>
|
|
48
|
-
</button>
|
|
49
|
-
{/if}
|
|
47
|
+
</button>
|
|
50
48
|
<slot />
|
|
51
49
|
</div>
|
|
52
50
|
|