@onsvisual/svelte-components 1.0.31 → 1.0.33

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.
@@ -8,6 +8,11 @@
8
8
  * @type {string|null}
9
9
  */
10
10
  export let id = null;
11
+ /**
12
+ * Name for the <select> element
13
+ * @type {string|null}
14
+ */
15
+ export let name = id;
11
16
  /**
12
17
  * A label to describe the <select> element (expected for accessibility)
13
18
  * @type {string|null}
@@ -46,7 +51,7 @@
46
51
  {/if}
47
52
  <select
48
53
  {id}
49
- name={id}
54
+ {name}
50
55
  class="ons-input ons-input--select"
51
56
  bind:value
52
57
  on:change={(e) => dispatch("change", e)}
@@ -5,6 +5,7 @@ export default class Dropdown extends SvelteComponentTyped<{
5
5
  cls?: string | null | undefined;
6
6
  id?: string | null | undefined;
7
7
  label?: string | null | undefined;
8
+ name?: string | null | undefined;
8
9
  value?: object | null | undefined;
9
10
  hideLabel?: boolean | undefined;
10
11
  placeholder?: string | undefined;
@@ -24,6 +25,7 @@ declare const __propDef: {
24
25
  cls?: string | null | undefined;
25
26
  id?: string | null | undefined;
26
27
  label?: string | null | undefined;
28
+ name?: string | null | undefined;
27
29
  value?: object | null | undefined;
28
30
  hideLabel?: boolean | undefined;
29
31
  placeholder?: string | undefined;
@@ -8,6 +8,11 @@
8
8
  * @type {string|null}
9
9
  */
10
10
  export let id = null;
11
+ /**
12
+ * Name attribute for &lt;input&gt; element
13
+ * @type {string|null}
14
+ */
15
+ export let name = id;
11
16
  /**
12
17
  * A prop to bind to for the entered value
13
18
  * @type {string|null}
@@ -103,6 +108,7 @@
103
108
  <input
104
109
  type="text"
105
110
  {id}
111
+ {name}
106
112
  bind:value
107
113
  maxlength={charLimit}
108
114
  pattern={pattern ? pattern : numeric ? "[0-9]*" : null}
@@ -129,6 +135,7 @@
129
135
  <input
130
136
  type="text"
131
137
  {id}
138
+ {name}
132
139
  bind:value
133
140
  pattern={pattern ? pattern : numeric ? "[0-9]*" : null}
134
141
  inputmode={numeric ? "numeric" : null}
@@ -7,6 +7,7 @@ export default class Input extends SvelteComponentTyped<{
7
7
  width?: number | undefined;
8
8
  label?: string | undefined;
9
9
  pattern?: string | null | undefined;
10
+ name?: string | null | undefined;
10
11
  error?: boolean | undefined;
11
12
  numeric?: boolean | undefined;
12
13
  value?: string | null | undefined;
@@ -34,6 +35,7 @@ declare const __propDef: {
34
35
  width?: number | undefined;
35
36
  label?: string | undefined;
36
37
  pattern?: string | null | undefined;
38
+ name?: string | null | undefined;
37
39
  error?: boolean | undefined;
38
40
  numeric?: boolean | undefined;
39
41
  value?: string | null | undefined;
@@ -24,7 +24,7 @@
24
24
  */
25
25
  export let item = { id, label, description };
26
26
  /**
27
- * ID for radio group (required)
27
+ * ID/name for radio group (required)
28
28
  * @type {string}
29
29
  */
30
30
  export let groupId;
@@ -12,10 +12,10 @@
12
12
  */
13
13
  export let hideTitle = false;
14
14
  /**
15
- * Unique ID for radio group (required)
15
+ * Unique ID/name for radio group (required)
16
16
  * @type {string}
17
17
  */
18
- export let id = "name";
18
+ export let id = "radios";
19
19
  /**
20
20
  * Descriptive "how to" label for inputs
21
21
  * @type {string|null}
@@ -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));
@@ -14,10 +16,15 @@
14
16
  let hideMenu = false;
15
17
 
16
18
  /**
17
- * Unique id for the element
19
+ * Unique id for the HTML element
18
20
  * @type {string}
19
21
  */
20
22
  export let id = "autocomplete";
23
+ /**
24
+ * Name for the HTML element
25
+ * @type {string}
26
+ */
27
+ export let name = id;
21
28
  /**
22
29
  * The mode can be either "default" or "search"
23
30
  * @type {"default"|"search"}
@@ -68,6 +75,11 @@
68
75
  * @type {string|null}
69
76
  */
70
77
  export let groupKey = null;
78
+ /**
79
+ * When using SSR or pre-rendering, this option will render a text input or dropdown before the page is hydrated (allows for progressive enhancement).
80
+ * @type {boolean}
81
+ */
82
+ export let renderFallback = false;
71
83
  /**
72
84
  * Optional: Minimum query length to return results
73
85
  * @type {number}
@@ -92,23 +104,22 @@
92
104
  */
93
105
  export let scriptUrl =
94
106
  "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
107
  /**
99
108
  * Call this function externally to clear the input
100
109
  * @type {function}
101
110
  */
102
- export async function clearInput() {
111
+ export let clearInput = async () => {
103
112
  await setInputValue(null);
104
113
  dispatch("clear", null);
105
- }
114
+ };
106
115
  /**
107
116
  * Optional: Set an additional CSS class for the component
108
117
  * @type {string|null}
109
118
  */
110
119
  export let cls = null;
111
120
 
121
+ // This method is a bit of a hack, but no better options available at present
122
+ // https://github.com/alphagov/accessible-autocomplete/issues/390
112
123
  async function setInputValue(textValue) {
113
124
  hideMenu = true;
114
125
  inputElement.value = textValue || "";
@@ -167,7 +178,7 @@
167
178
  accessibleAutocomplete({
168
179
  element,
169
180
  id,
170
- name: `${id}-input`,
181
+ name,
171
182
  source: loadOptions,
172
183
  autoselect: true,
173
184
  onConfirm: select,
@@ -204,35 +215,48 @@
204
215
  <script src={scriptUrl} on:load={handleScriptLoad}></script>
205
216
  </svelte:head>
206
217
 
207
- <div class="ons-field {cls}">
208
- {#if label}<label for={id} class="ons-label" class:ons-u-vh={hideLabel}>{label}</label>{/if}
209
- <div class="ons-autocomplete-wrapper">
210
- {#if scriptLoaded}
211
- <div
212
- id="{id}-container"
213
- class="ons-autocomplete"
214
- class:hide-menu={hideMenu}
215
- use:initAutocomplete
216
- ></div>
217
- {#if clearable && !autoClear && value}
218
- <button
219
- type="reset"
220
- title="Clear selection"
221
- aria-label="Clear selection"
222
- on:click={clearInput}
223
- class="ons-autocomplete-clear"
224
- >
225
- <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" viewBox="0 0 14 14" width="18">
226
- <path
227
- fill="currentColor"
228
- 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"
229
- ></path>
230
- </svg>
231
- </button>
218
+ {#if renderFallback && !scriptLoaded}
219
+ {#if mode === "search"}
220
+ <Input {id} {name} {label} {hideLabel} value={value?.[labelKey]} />
221
+ {:else}
222
+ <Dropdown {id} {name} {options} {label} {hideLabel} {placeholder} {value} />
223
+ {/if}
224
+ {:else}
225
+ <div class="ons-field {cls}">
226
+ {#if label}<label for={id} class="ons-label" class:ons-u-vh={hideLabel}>{label}</label>{/if}
227
+ <div class="ons-autocomplete-wrapper">
228
+ {#if scriptLoaded}
229
+ <div
230
+ id="{id}-container"
231
+ class="ons-autocomplete"
232
+ class:hide-menu={hideMenu}
233
+ use:initAutocomplete
234
+ ></div>
235
+ {#if clearable && !autoClear && value}
236
+ <button
237
+ type="reset"
238
+ title="Clear selection"
239
+ aria-label="Clear selection"
240
+ on:click={clearInput}
241
+ class="ons-autocomplete-clear"
242
+ >
243
+ <svg
244
+ xmlns="http://www.w3.org/2000/svg"
245
+ aria-hidden="true"
246
+ viewBox="0 0 14 14"
247
+ width="18"
248
+ >
249
+ <path
250
+ fill="currentColor"
251
+ 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"
252
+ ></path>
253
+ </svg>
254
+ </button>
255
+ {/if}
232
256
  {/if}
233
- {/if}
257
+ </div>
234
258
  </div>
235
- </div>
259
+ {/if}
236
260
 
237
261
  <style>
238
262
  .ons-autocomplete-wrapper {
@@ -5,6 +5,7 @@ export default class Select extends SvelteComponentTyped<{
5
5
  cls?: string | null | undefined;
6
6
  id?: string | undefined;
7
7
  label?: string | undefined;
8
+ name?: string | undefined;
8
9
  mode?: "default" | "search" | undefined;
9
10
  value?: object | undefined;
10
11
  hideLabel?: boolean | undefined;
@@ -14,17 +15,17 @@ export default class Select extends SvelteComponentTyped<{
14
15
  autoClear?: boolean | undefined;
15
16
  labelKey?: string | undefined;
16
17
  groupKey?: string | null | undefined;
18
+ renderFallback?: boolean | undefined;
17
19
  minLength?: number | undefined;
18
20
  loadOptions?: Function | undefined;
19
21
  scriptUrl?: string | undefined;
20
- clearInput?: (() => Promise<void>) | undefined;
22
+ clearInput?: Function | undefined;
21
23
  }, {
22
24
  clear: CustomEvent<any>;
23
25
  change: CustomEvent<any>;
24
26
  } & {
25
27
  [evt: string]: CustomEvent<any>;
26
28
  }, {}> {
27
- get clearInput(): () => Promise<void>;
28
29
  }
29
30
  export type SelectProps = typeof __propDef.props;
30
31
  export type SelectEvents = typeof __propDef.events;
@@ -35,6 +36,7 @@ declare const __propDef: {
35
36
  cls?: string | null | undefined;
36
37
  id?: string | undefined;
37
38
  label?: string | undefined;
39
+ name?: string | undefined;
38
40
  mode?: "default" | "search" | undefined;
39
41
  value?: object | undefined;
40
42
  hideLabel?: boolean | undefined;
@@ -44,10 +46,11 @@ declare const __propDef: {
44
46
  autoClear?: boolean | undefined;
45
47
  labelKey?: string | undefined;
46
48
  groupKey?: string | null | undefined;
49
+ renderFallback?: boolean | undefined;
47
50
  minLength?: number | undefined;
48
51
  loadOptions?: Function | undefined;
49
52
  scriptUrl?: string | undefined;
50
- clearInput?: (() => Promise<void>) | undefined;
53
+ clearInput?: Function | undefined;
51
54
  };
52
55
  events: {
53
56
  clear: CustomEvent<any>;
@@ -8,6 +8,11 @@
8
8
  * @type {string|null}
9
9
  */
10
10
  export let id = null;
11
+ /**
12
+ * Name for &lt;textarea&gt; element
13
+ * @type {string|null}
14
+ */
15
+ export let name = id;
11
16
  /**
12
17
  * A prop to bind to for the entered value
13
18
  * @type {string|null}
@@ -68,11 +73,11 @@
68
73
  {/if}
69
74
  <textarea
70
75
  {id}
76
+ {name}
71
77
  bind:value
72
78
  class="ons-input ons-input--textarea {Number.isInteger(width) ? `ons-input--w-${width}` : null}"
73
79
  class:ons-js-char-limit-input={charLimit}
74
80
  class:ons-input--limit-reached={remaining === 0}
75
- name={id}
76
81
  {rows}
77
82
  maxlength={charLimit}
78
83
  data-char-limit-ref="{id}-lim"
@@ -6,6 +6,7 @@ export default class Textarea extends SvelteComponentTyped<{
6
6
  id?: string | null | undefined;
7
7
  width?: number | undefined;
8
8
  label?: string | undefined;
9
+ name?: string | null | undefined;
9
10
  value?: string | null | undefined;
10
11
  description?: string | null | undefined;
11
12
  hideLabel?: boolean | undefined;
@@ -25,6 +26,7 @@ declare const __propDef: {
25
26
  id?: string | null | undefined;
26
27
  width?: number | undefined;
27
28
  label?: string | undefined;
29
+ name?: string | null | undefined;
28
30
  value?: string | null | undefined;
29
31
  description?: string | null | undefined;
30
32
  hideLabel?: boolean | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onsvisual/svelte-components",
3
- "version": "1.0.31",
3
+ "version": "1.0.33",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "npm run build:package && npm run build:docs",