@onsvisual/svelte-components 0.1.100 → 0.1.101

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.
@@ -16,12 +16,14 @@ export default class AccessibleSelect extends SvelteComponentTyped<{
16
16
  minLength?: number;
17
17
  loadOptions?: Function;
18
18
  scriptUrl?: string;
19
+ clearInput?: () => Promise<void>;
19
20
  }, {
20
- change: CustomEvent<any>;
21
21
  clear: CustomEvent<any>;
22
+ change: CustomEvent<any>;
22
23
  } & {
23
24
  [evt: string]: CustomEvent<any>;
24
25
  }, {}> {
26
+ get clearInput(): () => Promise<void>;
25
27
  }
26
28
  export type AccessibleSelectProps = typeof __propDef.props;
27
29
  export type AccessibleSelectEvents = typeof __propDef.events;
@@ -43,10 +45,11 @@ declare const __propDef: {
43
45
  minLength?: number;
44
46
  loadOptions?: Function;
45
47
  scriptUrl?: string;
48
+ clearInput?: () => Promise<void>;
46
49
  };
47
50
  events: {
48
- change: CustomEvent<any>;
49
51
  clear: CustomEvent<any>;
52
+ change: CustomEvent<any>;
50
53
  } & {
51
54
  [evt: string]: CustomEvent<any>;
52
55
  };
@@ -1,4 +1,6 @@
1
1
  <script>
2
+ // @ts-nocheck
3
+
2
4
  import { onMount, createEventDispatcher } from "svelte";
3
5
 
4
6
  const dispatch = createEventDispatcher();
@@ -88,6 +90,22 @@
88
90
  export let scriptUrl =
89
91
  "https://cdn.ons.gov.uk/vendor/accessible-autocomplete/3.0.1/accessible-autocomplete.min.js";
90
92
 
93
+ // This clearing method is a bit of a hack, but no better options available at present
94
+ // https://github.com/alphagov/accessible-autocomplete/issues/390
95
+ /**
96
+ * Call this function externally to clear the input
97
+ * @type {function}
98
+ */
99
+ export async function clearInput() {
100
+ hideMenu = true;
101
+ inputElement.value = "";
102
+ await sleep(110);
103
+ inputElement.focus({ preventScroll: true });
104
+ inputElement.blur();
105
+ hideMenu = false;
106
+ dispatch("clear", value);
107
+ }
108
+
91
109
  function inputValueTemplate(result) {
92
110
  return result && result[labelKey];
93
111
  }
@@ -124,18 +142,6 @@
124
142
  if (!e.target.value) select(null);
125
143
  }
126
144
 
127
- // This clearing method is a bit of a hack, but no better options available at present
128
- // https://github.com/alphagov/accessible-autocomplete/issues/390
129
- async function clearInput() {
130
- hideMenu = true;
131
- inputElement.value = "";
132
- await sleep(110);
133
- inputElement.focus({ preventScroll: true });
134
- inputElement.blur();
135
- hideMenu = false;
136
- dispatch("clear", value);
137
- }
138
-
139
145
  function handleScriptLoad() {
140
146
  if (!scriptLoaded && window?.accessibleAutocomplete) {
141
147
  accessibleAutocomplete = window.accessibleAutocomplete;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onsvisual/svelte-components",
3
- "version": "0.1.100",
3
+ "version": "0.1.101",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "homepage": "https://onsvisual.github.io/svelte-components",