@onsvisual/svelte-components 1.0.31 → 1.0.32
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.
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
// @ts-nocheck
|
|
3
3
|
|
|
4
4
|
import { onMount, createEventDispatcher } from "svelte";
|
|
5
|
+
import Dropdown from "../Dropdown/Dropdown.svelte";
|
|
6
|
+
import Input from "../Input/Input.svelte";
|
|
5
7
|
|
|
6
8
|
const dispatch = createEventDispatcher();
|
|
7
9
|
const sleep = (ms = 1000) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -68,6 +70,11 @@
|
|
|
68
70
|
* @type {string|null}
|
|
69
71
|
*/
|
|
70
72
|
export let groupKey = null;
|
|
73
|
+
/**
|
|
74
|
+
* When using SSR or pre-rendering, this option will render a text input or dropdown before the page is hydrated (allows for progressive enhancement).
|
|
75
|
+
* @type {boolean}
|
|
76
|
+
*/
|
|
77
|
+
export let renderFallback = false;
|
|
71
78
|
/**
|
|
72
79
|
* Optional: Minimum query length to return results
|
|
73
80
|
* @type {number}
|
|
@@ -92,23 +99,22 @@
|
|
|
92
99
|
*/
|
|
93
100
|
export let scriptUrl =
|
|
94
101
|
"https://cdn.ons.gov.uk/vendor/accessible-autocomplete/3.0.1/accessible-autocomplete.min.js";
|
|
95
|
-
|
|
96
|
-
// This clearing method is a bit of a hack, but no better options available at present
|
|
97
|
-
// https://github.com/alphagov/accessible-autocomplete/issues/390
|
|
98
102
|
/**
|
|
99
103
|
* Call this function externally to clear the input
|
|
100
104
|
* @type {function}
|
|
101
105
|
*/
|
|
102
|
-
export async
|
|
106
|
+
export let clearInput = async () => {
|
|
103
107
|
await setInputValue(null);
|
|
104
108
|
dispatch("clear", null);
|
|
105
|
-
}
|
|
109
|
+
};
|
|
106
110
|
/**
|
|
107
111
|
* Optional: Set an additional CSS class for the component
|
|
108
112
|
* @type {string|null}
|
|
109
113
|
*/
|
|
110
114
|
export let cls = null;
|
|
111
115
|
|
|
116
|
+
// This method is a bit of a hack, but no better options available at present
|
|
117
|
+
// https://github.com/alphagov/accessible-autocomplete/issues/390
|
|
112
118
|
async function setInputValue(textValue) {
|
|
113
119
|
hideMenu = true;
|
|
114
120
|
inputElement.value = textValue || "";
|
|
@@ -204,35 +210,48 @@
|
|
|
204
210
|
<script src={scriptUrl} on:load={handleScriptLoad}></script>
|
|
205
211
|
</svelte:head>
|
|
206
212
|
|
|
207
|
-
|
|
208
|
-
{#if
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
{#if
|
|
218
|
-
<
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
<
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
213
|
+
{#if renderFallback && !scriptLoaded}
|
|
214
|
+
{#if mode === "search"}
|
|
215
|
+
<Input {id} {label} {hideLabel} value={value?.[labelKey]} />
|
|
216
|
+
{:else}
|
|
217
|
+
<Dropdown {id} {options} {label} {hideLabel} {placeholder} {value} />
|
|
218
|
+
{/if}
|
|
219
|
+
{:else}
|
|
220
|
+
<div class="ons-field {cls}">
|
|
221
|
+
{#if label}<label for={id} class="ons-label" class:ons-u-vh={hideLabel}>{label}</label>{/if}
|
|
222
|
+
<div class="ons-autocomplete-wrapper">
|
|
223
|
+
{#if scriptLoaded}
|
|
224
|
+
<div
|
|
225
|
+
id="{id}-container"
|
|
226
|
+
class="ons-autocomplete"
|
|
227
|
+
class:hide-menu={hideMenu}
|
|
228
|
+
use:initAutocomplete
|
|
229
|
+
></div>
|
|
230
|
+
{#if clearable && !autoClear && value}
|
|
231
|
+
<button
|
|
232
|
+
type="reset"
|
|
233
|
+
title="Clear selection"
|
|
234
|
+
aria-label="Clear selection"
|
|
235
|
+
on:click={clearInput}
|
|
236
|
+
class="ons-autocomplete-clear"
|
|
237
|
+
>
|
|
238
|
+
<svg
|
|
239
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
240
|
+
aria-hidden="true"
|
|
241
|
+
viewBox="0 0 14 14"
|
|
242
|
+
width="18"
|
|
243
|
+
>
|
|
244
|
+
<path
|
|
245
|
+
fill="currentColor"
|
|
246
|
+
d="M13.6 1 l -0.71 -0.71 a 0.5 0.5 0 0 0 -0.71 0 l -5.25 5.25 l -5.25 -5.25 a 0.51 0.51 0 0 0 -0.71 0 l -0.71 0.71 a 0.5 0.5 0 0 0 0 0.71 l 5.25 5.25 l -5.25 5.25 a 0.5 0.5 0 0 0 0 0.71 l 0.71 0.71 a 0.5 0.5 0 0 0 0.71 0 l 5.25 -5.25 l 5.25 5.25 a 0.5 0.5 0 0 0 0.71 0 l 0.71 -0.71 a 0.5 0.5 0 0 0 0 -0.71 l -5.25 -5.25 l 5.25 -5.25 a 0.5 0.5 0 0 0 0 -0.71Z"
|
|
247
|
+
></path>
|
|
248
|
+
</svg>
|
|
249
|
+
</button>
|
|
250
|
+
{/if}
|
|
232
251
|
{/if}
|
|
233
|
-
|
|
252
|
+
</div>
|
|
234
253
|
</div>
|
|
235
|
-
|
|
254
|
+
{/if}
|
|
236
255
|
|
|
237
256
|
<style>
|
|
238
257
|
.ons-autocomplete-wrapper {
|
|
@@ -14,17 +14,17 @@ export default class Select extends SvelteComponentTyped<{
|
|
|
14
14
|
autoClear?: boolean | undefined;
|
|
15
15
|
labelKey?: string | undefined;
|
|
16
16
|
groupKey?: string | null | undefined;
|
|
17
|
+
renderFallback?: boolean | undefined;
|
|
17
18
|
minLength?: number | undefined;
|
|
18
19
|
loadOptions?: Function | undefined;
|
|
19
20
|
scriptUrl?: string | undefined;
|
|
20
|
-
clearInput?:
|
|
21
|
+
clearInput?: Function | undefined;
|
|
21
22
|
}, {
|
|
22
23
|
clear: CustomEvent<any>;
|
|
23
24
|
change: CustomEvent<any>;
|
|
24
25
|
} & {
|
|
25
26
|
[evt: string]: CustomEvent<any>;
|
|
26
27
|
}, {}> {
|
|
27
|
-
get clearInput(): () => Promise<void>;
|
|
28
28
|
}
|
|
29
29
|
export type SelectProps = typeof __propDef.props;
|
|
30
30
|
export type SelectEvents = typeof __propDef.events;
|
|
@@ -44,10 +44,11 @@ declare const __propDef: {
|
|
|
44
44
|
autoClear?: boolean | undefined;
|
|
45
45
|
labelKey?: string | undefined;
|
|
46
46
|
groupKey?: string | null | undefined;
|
|
47
|
+
renderFallback?: boolean | undefined;
|
|
47
48
|
minLength?: number | undefined;
|
|
48
49
|
loadOptions?: Function | undefined;
|
|
49
50
|
scriptUrl?: string | undefined;
|
|
50
|
-
clearInput?:
|
|
51
|
+
clearInput?: Function | undefined;
|
|
51
52
|
};
|
|
52
53
|
events: {
|
|
53
54
|
clear: CustomEvent<any>;
|