@onsvisual/svelte-components 1.1.36 → 1.1.37

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.
@@ -1,6 +1,6 @@
1
1
  <script>
2
2
  import { getContext } from "svelte";
3
- import { slugify } from "../../js/utils.js";
3
+ import { slugify, sleep } from "../../js/utils.js";
4
4
 
5
5
  /**
6
6
  * Sets the title of the accordion item
@@ -24,6 +24,18 @@
24
24
  export let open = false;
25
25
 
26
26
  const dataGroup = getContext("dataGroup");
27
+
28
+ // Sync open state to allow binding
29
+ // Note: This is a one-way binding. Changing the state from outside does not open/close
30
+ let lastState = open ? "Open panel" : "Close panel";
31
+ async function syncOpenState(e) {
32
+ await sleep(0);
33
+ const state = e?.target?.dataset?.gaAction;
34
+ if (state !== lastState) {
35
+ open = state === "Open panel" ? true : false;
36
+ lastState = state;
37
+ }
38
+ }
27
39
  </script>
28
40
 
29
41
  <div
@@ -32,9 +44,16 @@
32
44
  data-group={dataGroup}
33
45
  data-open={open}
34
46
  >
35
- <div class="ons-details__heading ons-js-details-heading" role="button">
47
+ <div
48
+ class="ons-details__heading ons-js-details-heading"
49
+ role="button"
50
+ on:click={syncOpenState}
51
+ on:keyup={syncOpenState}
52
+ >
36
53
  {#if headingTag === "h3"}
37
- <h3 class="ons-details__title ons-u-fs-r--b">{title}</h3>
54
+ <h3 class="ons-details__title ons-u-fs-r--b">
55
+ {title}
56
+ </h3>
38
57
  {:else}
39
58
  <h2 class="ons-details__title ons-u-fs-r--b">{title}</h2>
40
59
  {/if}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onsvisual/svelte-components",
3
- "version": "1.1.36",
3
+ "version": "1.1.37",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "npm run build:package && npm run build:docs",