@onsvisual/svelte-components 1.1.45 → 1.1.47

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.
@@ -81,22 +81,23 @@
81
81
 
82
82
  let el; // Header HTML element
83
83
 
84
- let url = null;
85
84
  let lang = "en";
86
85
  let baseurl = "https://www.ons.gov.uk";
87
86
  let baseother = "https://cy.ons.gov.uk";
88
87
  let path = "";
88
+ let activeLink = null;
89
89
 
90
90
  function setPaths() {
91
- url = page?.url || document.location;
91
+ const url = page?.url || document.location;
92
92
  lang = url.host.startsWith("cy") ? "cy" : "en";
93
93
  baseurl = lang === "cy" ? "https://cy.ons.gov.uk" : "https://www.ons.gov.uk";
94
94
  baseother = lang === "cy" ? "https://www.ons.gov.uk" : "https://cy.ons.gov.uk";
95
95
  path = url.pathname;
96
+ activeLink = Array.isArray(navLinks) ? getActiveLink(navLinks, path) : null;
96
97
  }
97
98
 
98
99
  function getActiveLink(navLinks, path) {
99
- const candidates = navLinks.filter((link) => path.endsWith(link.href));
100
+ const candidates = navLinks.filter((link) => path.includes(link.href));
100
101
  return candidates.length ? candidates[candidates.length - 1] : null;
101
102
  }
102
103
 
@@ -116,8 +117,6 @@
116
117
  };
117
118
 
118
119
  $: i18n = (text) => (lang === "cy" && texts[text] ? texts[text] : text);
119
- $: activeLink =
120
- Array.isArray(navLinks) && url?.pathname ? getActiveLink(navLinks, url.pathname) : null;
121
120
 
122
121
  onMount(() => {
123
122
  setPaths();
@@ -132,6 +131,8 @@
132
131
  });
133
132
  </script>
134
133
 
134
+ <svelte:window onpopstate={setPaths} />
135
+
135
136
  <header
136
137
  class="ons-header"
137
138
  class:ons-header--basic={!compact && !legacy}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onsvisual/svelte-components",
3
- "version": "1.1.45",
3
+ "version": "1.1.47",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "npm run build:package && npm run build:docs",