@financial-times/dotcom-ui-header 13.10.0 → 13.10.1-beta.2

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.
Files changed (2) hide show
  1. package/browser.js +13 -3
  2. package/package.json +3 -3
package/browser.js CHANGED
@@ -1,3 +1,4 @@
1
+ // eslint-disable-next-line import/no-unresolved
1
2
  import Header from '@financial-times/o-header'
2
3
  import TypeAhead from 'n-topic-search'
3
4
  import { h, render } from 'preact'
@@ -7,6 +8,7 @@ import { DropdownNavigation } from './src/components/dropdown-navigation/dropdow
7
8
  * @typedef HeaderOptions
8
9
  * @property { HTMLElement } [rootElement] - the root element passed to o-header
9
10
  * @property { string } [hostName]
11
+ * @property { string } [baseSearchUrl] - a base URL for use when typeahead search does not work with relative URLs, e.g. subdomain based sites
10
12
  */
11
13
 
12
14
  /**
@@ -14,13 +16,15 @@ import { DropdownNavigation } from './src/components/dropdown-navigation/dropdow
14
16
  * @param { HeaderOptions } headerOptions
15
17
  */
16
18
  export const init = (headerOptions = {}) => {
19
+ const baseSearchUrl = headerOptions.baseSearchUrl ? headerOptions.baseSearchUrl : undefined
20
+
17
21
  const topicSearchElements = document.querySelectorAll(
18
22
  '.o-header [data-n-topic-search], .o-header__drawer [data-n-topic-search]'
19
23
  )
20
24
  topicSearchElements.forEach((element) => {
21
25
  const form = element.tagName === 'FORM' ? element : element.querySelector('form')
22
26
  const input = form?.querySelector('input')
23
-
27
+
24
28
  const drawerContainer = form?.closest('[data-o-header-drawer="true"]')
25
29
  const searchContainer = form?.closest('[data-o-header-search]') ?? form?.closest('.o-header__search')
26
30
 
@@ -36,10 +40,16 @@ export const init = (headerOptions = {}) => {
36
40
  if (drawerContainer) {
37
41
  form.appendChild(typeaheadContainer)
38
42
 
39
- render(h(TypeAhead, { container: drawerContainer, inputId: input.id }), typeaheadContainer)
43
+ render(
44
+ h(TypeAhead, { container: drawerContainer, inputId: input.id, baseSearchUrl }),
45
+ typeaheadContainer
46
+ )
40
47
  } else {
41
48
  form.after(typeaheadContainer)
42
- render(h(TypeAhead, { container: searchContainer, inputId: input.id }), typeaheadContainer)
49
+ render(
50
+ h(TypeAhead, { container: searchContainer, inputId: input.id, baseSearchUrl }),
51
+ typeaheadContainer
52
+ )
43
53
  }
44
54
  })
45
55
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@financial-times/dotcom-ui-header",
3
- "version": "13.10.0",
3
+ "version": "13.10.1-beta.2",
4
4
  "description": "",
5
5
  "browser": "browser.js",
6
6
  "main": "component.js",
@@ -21,7 +21,7 @@
21
21
  "author": "",
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
- "@financial-times/dotcom-types-navigation": "^13.10.0"
24
+ "@financial-times/dotcom-types-navigation": "^13.10.1-beta.2"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@financial-times/logo-images": "^1.10.1",
@@ -33,7 +33,7 @@
33
33
  "@financial-times/o-header": "^15.5.0",
34
34
  "@financial-times/o3-button": "^3.15.0",
35
35
  "@financial-times/o-visual-effects": "^5.0.2",
36
- "n-topic-search": "^10.1.1",
36
+ "n-topic-search": "^12.0.0",
37
37
  "preact": "^10.23.2",
38
38
  "react": "17.x || 18.x",
39
39
  "react-dom": "17.x || 18.x"