@onsvisual/svelte-components 0.0.34 → 0.0.36

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.
@@ -13,6 +13,7 @@ export default class Select extends SvelteComponentTyped<{
13
13
  multiple?: boolean;
14
14
  maxSelected?: number;
15
15
  clearable?: boolean;
16
+ autoClear?: boolean;
16
17
  idKey?: string;
17
18
  labelKey?: string;
18
19
  colors?: any[];
@@ -21,10 +22,10 @@ export default class Select extends SvelteComponentTyped<{
21
22
  floatingConfig?: any;
22
23
  }, {
23
24
  input: CustomEvent<any>;
24
- change: CustomEvent<any>;
25
25
  focus: CustomEvent<any>;
26
26
  blur: CustomEvent<any>;
27
27
  clear: CustomEvent<any>;
28
+ change: CustomEvent<any>;
28
29
  } & {
29
30
  [evt: string]: CustomEvent<any>;
30
31
  }, {}> {
@@ -46,6 +47,7 @@ declare const __propDef: {
46
47
  multiple?: boolean;
47
48
  maxSelected?: number;
48
49
  clearable?: boolean;
50
+ autoClear?: boolean;
49
51
  idKey?: string;
50
52
  labelKey?: string;
51
53
  colors?: any[];
@@ -55,10 +57,10 @@ declare const __propDef: {
55
57
  };
56
58
  events: {
57
59
  input: CustomEvent<any>;
58
- change: CustomEvent<any>;
59
60
  focus: CustomEvent<any>;
60
61
  blur: CustomEvent<any>;
61
62
  clear: CustomEvent<any>;
63
+ change: CustomEvent<any>;
62
64
  } & {
63
65
  [evt: string]: CustomEvent<any>;
64
66
  };
@@ -8,3 +8,4 @@ export function formatDate(str: any, locale?: string, opts?: {
8
8
  export function commas(num: any): string;
9
9
  export function ascending(a: any, b: any): number;
10
10
  export function descending(a: any, b: any): number;
11
+ export function sleep(ms?: number): Promise<any>;
@@ -13,6 +13,7 @@ export default class Titleblock extends SvelteComponentTyped<{
13
13
  [evt: string]: CustomEvent<any>;
14
14
  }, {
15
15
  before: {};
16
+ default: {};
16
17
  brand: {};
17
18
  after: {};
18
19
  }> {
@@ -36,6 +37,7 @@ declare const __propDef: {
36
37
  };
37
38
  slots: {
38
39
  before: {};
40
+ default: {};
39
41
  brand: {};
40
42
  after: {};
41
43
  };
@@ -1,5 +1,7 @@
1
1
  <script>
2
+ import { createEventDispatcher } from "svelte";
2
3
  import SelectInner from "svelte-select";
4
+ import { sleep } from "../../js/utils";
3
5
 
4
6
  /**
5
7
  * Unique id for the element
@@ -26,6 +28,11 @@
26
28
  * @type {boolean}
27
29
  */
28
30
  export let clearable = true;
31
+ /**
32
+ * Clear value on selection (default for "search" mode)
33
+ * @type {boolean}
34
+ */
35
+ export let autoClear = mode === "search";
29
36
  /**
30
37
  * A label to describe the element (expected for accessibility)
31
38
  * @type {string}
@@ -110,6 +117,16 @@
110
117
  : "No options available";
111
118
 
112
119
  let filterText = "";
120
+
121
+ const dispatch = createEventDispatcher();
122
+
123
+ async function handleChange(e) {
124
+ dispatch("change", e.detail);
125
+ if (autoClear) {
126
+ await sleep(100);
127
+ value = null;
128
+ }
129
+ }
113
130
  </script>
114
131
 
115
132
  <div class="ons-field" style="{style}">
@@ -131,8 +148,8 @@
131
148
  showChevron="{!value}"
132
149
  multiple="{multiple}"
133
150
  clearable="{clearable}"
151
+ on:change="{handleChange}"
134
152
  on:input
135
- on:change
136
153
  on:focus
137
154
  on:blur
138
155
  on:clear
package/dist/js/utils.js CHANGED
@@ -44,3 +44,5 @@ export const ascending = (a, b) =>
44
44
 
45
45
  export const descending = (a, b) =>
46
46
  a == null || b == null ? NaN : b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
47
+
48
+ export const sleep = (ms = 1000) => new Promise((resolve) => setTimeout(resolve, ms));
@@ -67,6 +67,7 @@
67
67
  </div>
68
68
  {/if}
69
69
  </div>
70
+ <slot />
70
71
  <slot name="brand" />
71
72
  {#if censusLogo}
72
73
  <div class="ons-grid ons-u-mb-m">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onsvisual/svelte-components",
3
- "version": "0.0.34",
3
+ "version": "0.0.36",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "homepage": "https://onsvisual.github.io/svelte-components",