Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add canInitialise to GOVUKFrontendComponent #5333

Closed
wants to merge 1 commit into from

Conversation

patrickpatrickpatrick
Copy link
Contributor

@patrickpatrickpatrick patrickpatrickpatrick commented Sep 18, 2024

What

Add canInitialise to GOVUKFrontendComponent and associated test.

Why

If user extends GOVUKFrontendComponent they can define a function that will be executed before initialisation. If function returns false, then component will not initialise.

Fixes #5225

@patrickpatrickpatrick patrickpatrickpatrick changed the base branch from main to public-js-api September 18, 2024 10:24
Copy link

github-actions bot commented Sep 18, 2024

📋 Stats

File sizes

File Size
dist/govuk-frontend-development.min.css 118.52 KiB
dist/govuk-frontend-development.min.js 44.81 KiB
packages/govuk-frontend/dist/govuk/all.bundle.js 94.73 KiB
packages/govuk-frontend/dist/govuk/all.bundle.mjs 88.96 KiB
packages/govuk-frontend/dist/govuk/all.mjs 1.1 KiB
packages/govuk-frontend/dist/govuk/govuk-frontend-component.mjs 1.7 KiB
packages/govuk-frontend/dist/govuk/govuk-frontend.min.css 118.5 KiB
packages/govuk-frontend/dist/govuk/govuk-frontend.min.js 44.79 KiB
packages/govuk-frontend/dist/govuk/i18n.mjs 5.55 KiB
packages/govuk-frontend/dist/govuk/init.mjs 6.9 KiB

Modules

File Size (bundled) Size (minified)
all.mjs 84.97 KiB 42.54 KiB
accordion.mjs 25.41 KiB 13.11 KiB
button.mjs 7.88 KiB 3.41 KiB
character-count.mjs 24.3 KiB 10.64 KiB
checkboxes.mjs 7.74 KiB 3.55 KiB
error-summary.mjs 9.79 KiB 4.17 KiB
exit-this-page.mjs 19.01 KiB 9.98 KiB
header.mjs 6.37 KiB 3.32 KiB
notification-banner.mjs 8.16 KiB 3.34 KiB
password-input.mjs 17.04 KiB 7.97 KiB
radios.mjs 6.73 KiB 3.09 KiB
service-navigation.mjs 6.35 KiB 3.41 KiB
skip-link.mjs 6.29 KiB 2.9 KiB
tabs.mjs 11.95 KiB 6.78 KiB

View stats and visualisations on the review app


Action run for 1824bf1

Copy link

github-actions bot commented Sep 18, 2024

JavaScript changes to npm package

diff --git a/packages/govuk-frontend/dist/govuk/govuk-frontend.min.js b/packages/govuk-frontend/dist/govuk/govuk-frontend.min.js
index 19e286ee0..231411483 100644
--- a/packages/govuk-frontend/dist/govuk/govuk-frontend.min.js
+++ b/packages/govuk-frontend/dist/govuk/govuk-frontend.min.js
@@ -101,6 +101,11 @@ class ConfigError extends GOVUKFrontendError {
         super(...e), this.name = "ConfigError"
     }
 }
+class CanInitError extends GOVUKFrontendError {
+    constructor(...e) {
+        super(...e), this.name = "CanInitError"
+    }
+}
 class ElementError extends GOVUKFrontendError {
     constructor(e) {
         let t = "string" == typeof e ? e : "";
@@ -125,9 +130,12 @@ class InitError extends GOVUKFrontendError {
 class GOVUKFrontendComponent {
     constructor(e) {
         this.checkSupport(), this.checkInitialised(e);
-        const t = this.constructor.moduleName;
-        if ("string" != typeof t) throw new InitError(t);
-        t && (null == e || e.setAttribute(`data-${t}-init`, ""))
+        const t = this.constructor,
+            n = t.moduleName,
+            i = t.canInitialise;
+        if ("function" == typeof i && !i()) throw new CanInitError("`canInitialise` returned `false`");
+        if ("string" != typeof n) throw new InitError(n);
+        n && (null == e || e.setAttribute(`data-${n}-init`, ""))
     }
     checkInitialised(e) {
         const t = this.constructor.moduleName;

Action run for 1824bf1

Copy link

github-actions bot commented Sep 18, 2024

Other changes to npm package

diff --git a/packages/govuk-frontend/dist/govuk/all.bundle.js b/packages/govuk-frontend/dist/govuk/all.bundle.js
index 1c67edb22..f699cd71c 100644
--- a/packages/govuk-frontend/dist/govuk/all.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/all.bundle.js
@@ -220,6 +220,12 @@
       this.name = 'ConfigError';
     }
   }
+  class CanInitError extends GOVUKFrontendError {
+    constructor(...args) {
+      super(...args);
+      this.name = 'CanInitError';
+    }
+  }
   class ElementError extends GOVUKFrontendError {
     constructor(messageOrOptions) {
       let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
@@ -252,7 +258,14 @@
     constructor($module) {
       this.checkSupport();
       this.checkInitialised($module);
-      const moduleName = this.constructor.moduleName;
+      const childClassConstructor = this.constructor;
+      const moduleName = childClassConstructor.moduleName;
+      const canInitialise = childClassConstructor.canInitialise;
+      if (typeof canInitialise === 'function') {
+        if (!canInitialise()) {
+          throw new CanInitError('`canInitialise` returned `false`');
+        }
+      }
       if (typeof moduleName === 'string') {
         moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
       } else {
@@ -285,6 +298,7 @@
   /**
    * @typedef ChildClass
    * @property {string} [moduleName] - The module name that'll be looked for in the DOM when initialising the component
+   * @property {() => boolean} [canInitialise] - The module name that'll be looked for in the DOM when initialising the component
    */
 
   /**
diff --git a/packages/govuk-frontend/dist/govuk/all.bundle.mjs b/packages/govuk-frontend/dist/govuk/all.bundle.mjs
index f8c1c3ed1..ce5fa2d28 100644
--- a/packages/govuk-frontend/dist/govuk/all.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/all.bundle.mjs
@@ -214,6 +214,12 @@ class ConfigError extends GOVUKFrontendError {
     this.name = 'ConfigError';
   }
 }
+class CanInitError extends GOVUKFrontendError {
+  constructor(...args) {
+    super(...args);
+    this.name = 'CanInitError';
+  }
+}
 class ElementError extends GOVUKFrontendError {
   constructor(messageOrOptions) {
     let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
@@ -246,7 +252,14 @@ class GOVUKFrontendComponent {
   constructor($module) {
     this.checkSupport();
     this.checkInitialised($module);
-    const moduleName = this.constructor.moduleName;
+    const childClassConstructor = this.constructor;
+    const moduleName = childClassConstructor.moduleName;
+    const canInitialise = childClassConstructor.canInitialise;
+    if (typeof canInitialise === 'function') {
+      if (!canInitialise()) {
+        throw new CanInitError('`canInitialise` returned `false`');
+      }
+    }
     if (typeof moduleName === 'string') {
       moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
     } else {
@@ -279,6 +292,7 @@ class GOVUKFrontendComponent {
 /**
  * @typedef ChildClass
  * @property {string} [moduleName] - The module name that'll be looked for in the DOM when initialising the component
+ * @property {() => boolean} [canInitialise] - The module name that'll be looked for in the DOM when initialising the component
  */
 
 /**
diff --git a/packages/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.js b/packages/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.js
index 0b96e7125..ea96a31e6 100644
--- a/packages/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.js
@@ -154,6 +154,12 @@
       this.name = 'SupportError';
     }
   }
+  class CanInitError extends GOVUKFrontendError {
+    constructor(...args) {
+      super(...args);
+      this.name = 'CanInitError';
+    }
+  }
   class ElementError extends GOVUKFrontendError {
     constructor(messageOrOptions) {
       let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
@@ -186,7 +192,14 @@
     constructor($module) {
       this.checkSupport();
       this.checkInitialised($module);
-      const moduleName = this.constructor.moduleName;
+      const childClassConstructor = this.constructor;
+      const moduleName = childClassConstructor.moduleName;
+      const canInitialise = childClassConstructor.canInitialise;
+      if (typeof canInitialise === 'function') {
+        if (!canInitialise()) {
+          throw new CanInitError('`canInitialise` returned `false`');
+        }
+      }
       if (typeof moduleName === 'string') {
         moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
       } else {
@@ -219,6 +232,7 @@
   /**
    * @typedef ChildClass
    * @property {string} [moduleName] - The module name that'll be looked for in the DOM when initialising the component
+   * @property {() => boolean} [canInitialise] - The module name that'll be looked for in the DOM when initialising the component
    */
 
   /**
diff --git a/packages/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.mjs b/packages/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.mjs
index 4c4530f84..abdb13673 100644
--- a/packages/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/components/accordion/accordion.bundle.mjs
@@ -148,6 +148,12 @@ class SupportError extends GOVUKFrontendError {
     this.name = 'SupportError';
   }
 }
+class CanInitError extends GOVUKFrontendError {
+  constructor(...args) {
+    super(...args);
+    this.name = 'CanInitError';
+  }
+}
 class ElementError extends GOVUKFrontendError {
   constructor(messageOrOptions) {
     let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
@@ -180,7 +186,14 @@ class GOVUKFrontendComponent {
   constructor($module) {
     this.checkSupport();
     this.checkInitialised($module);
-    const moduleName = this.constructor.moduleName;
+    const childClassConstructor = this.constructor;
+    const moduleName = childClassConstructor.moduleName;
+    const canInitialise = childClassConstructor.canInitialise;
+    if (typeof canInitialise === 'function') {
+      if (!canInitialise()) {
+        throw new CanInitError('`canInitialise` returned `false`');
+      }
+    }
     if (typeof moduleName === 'string') {
       moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
     } else {
@@ -213,6 +226,7 @@ class GOVUKFrontendComponent {
 /**
  * @typedef ChildClass
  * @property {string} [moduleName] - The module name that'll be looked for in the DOM when initialising the component
+ * @property {() => boolean} [canInitialise] - The module name that'll be looked for in the DOM when initialising the component
  */
 
 /**
diff --git a/packages/govuk-frontend/dist/govuk/components/button/button.bundle.js b/packages/govuk-frontend/dist/govuk/components/button/button.bundle.js
index 07424eb65..9346552e5 100644
--- a/packages/govuk-frontend/dist/govuk/components/button/button.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/components/button/button.bundle.js
@@ -154,6 +154,12 @@
       this.name = 'SupportError';
     }
   }
+  class CanInitError extends GOVUKFrontendError {
+    constructor(...args) {
+      super(...args);
+      this.name = 'CanInitError';
+    }
+  }
   class ElementError extends GOVUKFrontendError {
     constructor(messageOrOptions) {
       let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
@@ -186,7 +192,14 @@
     constructor($module) {
       this.checkSupport();
       this.checkInitialised($module);
-      const moduleName = this.constructor.moduleName;
+      const childClassConstructor = this.constructor;
+      const moduleName = childClassConstructor.moduleName;
+      const canInitialise = childClassConstructor.canInitialise;
+      if (typeof canInitialise === 'function') {
+        if (!canInitialise()) {
+          throw new CanInitError('`canInitialise` returned `false`');
+        }
+      }
       if (typeof moduleName === 'string') {
         moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
       } else {
@@ -219,6 +232,7 @@
   /**
    * @typedef ChildClass
    * @property {string} [moduleName] - The module name that'll be looked for in the DOM when initialising the component
+   * @property {() => boolean} [canInitialise] - The module name that'll be looked for in the DOM when initialising the component
    */
 
   /**
diff --git a/packages/govuk-frontend/dist/govuk/components/button/button.bundle.mjs b/packages/govuk-frontend/dist/govuk/components/button/button.bundle.mjs
index d9412f41d..be62c7f0f 100644
--- a/packages/govuk-frontend/dist/govuk/components/button/button.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/components/button/button.bundle.mjs
@@ -148,6 +148,12 @@ class SupportError extends GOVUKFrontendError {
     this.name = 'SupportError';
   }
 }
+class CanInitError extends GOVUKFrontendError {
+  constructor(...args) {
+    super(...args);
+    this.name = 'CanInitError';
+  }
+}
 class ElementError extends GOVUKFrontendError {
   constructor(messageOrOptions) {
     let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
@@ -180,7 +186,14 @@ class GOVUKFrontendComponent {
   constructor($module) {
     this.checkSupport();
     this.checkInitialised($module);
-    const moduleName = this.constructor.moduleName;
+    const childClassConstructor = this.constructor;
+    const moduleName = childClassConstructor.moduleName;
+    const canInitialise = childClassConstructor.canInitialise;
+    if (typeof canInitialise === 'function') {
+      if (!canInitialise()) {
+        throw new CanInitError('`canInitialise` returned `false`');
+      }
+    }
     if (typeof moduleName === 'string') {
       moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
     } else {
@@ -213,6 +226,7 @@ class GOVUKFrontendComponent {
 /**
  * @typedef ChildClass
  * @property {string} [moduleName] - The module name that'll be looked for in the DOM when initialising the component
+ * @property {() => boolean} [canInitialise] - The module name that'll be looked for in the DOM when initialising the component
  */
 
 /**
diff --git a/packages/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.js b/packages/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.js
index 76ce4eea5..1d149c067 100644
--- a/packages/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.js
@@ -185,6 +185,12 @@
       this.name = 'ConfigError';
     }
   }
+  class CanInitError extends GOVUKFrontendError {
+    constructor(...args) {
+      super(...args);
+      this.name = 'CanInitError';
+    }
+  }
   class ElementError extends GOVUKFrontendError {
     constructor(messageOrOptions) {
       let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
@@ -217,7 +223,14 @@
     constructor($module) {
       this.checkSupport();
       this.checkInitialised($module);
-      const moduleName = this.constructor.moduleName;
+      const childClassConstructor = this.constructor;
+      const moduleName = childClassConstructor.moduleName;
+      const canInitialise = childClassConstructor.canInitialise;
+      if (typeof canInitialise === 'function') {
+        if (!canInitialise()) {
+          throw new CanInitError('`canInitialise` returned `false`');
+        }
+      }
       if (typeof moduleName === 'string') {
         moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
       } else {
@@ -250,6 +263,7 @@
   /**
    * @typedef ChildClass
    * @property {string} [moduleName] - The module name that'll be looked for in the DOM when initialising the component
+   * @property {() => boolean} [canInitialise] - The module name that'll be looked for in the DOM when initialising the component
    */
 
   /**
diff --git a/packages/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.mjs b/packages/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.mjs
index 34ee63460..01996e924 100644
--- a/packages/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/components/character-count/character-count.bundle.mjs
@@ -179,6 +179,12 @@ class ConfigError extends GOVUKFrontendError {
     this.name = 'ConfigError';
   }
 }
+class CanInitError extends GOVUKFrontendError {
+  constructor(...args) {
+    super(...args);
+    this.name = 'CanInitError';
+  }
+}
 class ElementError extends GOVUKFrontendError {
   constructor(messageOrOptions) {
     let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
@@ -211,7 +217,14 @@ class GOVUKFrontendComponent {
   constructor($module) {
     this.checkSupport();
     this.checkInitialised($module);
-    const moduleName = this.constructor.moduleName;
+    const childClassConstructor = this.constructor;
+    const moduleName = childClassConstructor.moduleName;
+    const canInitialise = childClassConstructor.canInitialise;
+    if (typeof canInitialise === 'function') {
+      if (!canInitialise()) {
+        throw new CanInitError('`canInitialise` returned `false`');
+      }
+    }
     if (typeof moduleName === 'string') {
       moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
     } else {
@@ -244,6 +257,7 @@ class GOVUKFrontendComponent {
 /**
  * @typedef ChildClass
  * @property {string} [moduleName] - The module name that'll be looked for in the DOM when initialising the component
+ * @property {() => boolean} [canInitialise] - The module name that'll be looked for in the DOM when initialising the component
  */
 
 /**
diff --git a/packages/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.js b/packages/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.js
index b77f9b743..ba5be38d5 100644
--- a/packages/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.js
@@ -22,6 +22,12 @@
       this.name = 'SupportError';
     }
   }
+  class CanInitError extends GOVUKFrontendError {
+    constructor(...args) {
+      super(...args);
+      this.name = 'CanInitError';
+    }
+  }
   class ElementError extends GOVUKFrontendError {
     constructor(messageOrOptions) {
       let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
@@ -97,7 +103,14 @@
     constructor($module) {
       this.checkSupport();
       this.checkInitialised($module);
-      const moduleName = this.constructor.moduleName;
+      const childClassConstructor = this.constructor;
+      const moduleName = childClassConstructor.moduleName;
+      const canInitialise = childClassConstructor.canInitialise;
+      if (typeof canInitialise === 'function') {
+        if (!canInitialise()) {
+          throw new CanInitError('`canInitialise` returned `false`');
+        }
+      }
       if (typeof moduleName === 'string') {
         moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
       } else {
@@ -130,6 +143,7 @@
   /**
    * @typedef ChildClass
    * @property {string} [moduleName] - The module name that'll be looked for in the DOM when initialising the component
+   * @property {() => boolean} [canInitialise] - The module name that'll be looked for in the DOM when initialising the component
    */
 
   /**
diff --git a/packages/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.mjs b/packages/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.mjs
index e3c1fd925..d3b6af60d 100644
--- a/packages/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/components/checkboxes/checkboxes.bundle.mjs
@@ -16,6 +16,12 @@ class SupportError extends GOVUKFrontendError {
     this.name = 'SupportError';
   }
 }
+class CanInitError extends GOVUKFrontendError {
+  constructor(...args) {
+    super(...args);
+    this.name = 'CanInitError';
+  }
+}
 class ElementError extends GOVUKFrontendError {
   constructor(messageOrOptions) {
     let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
@@ -91,7 +97,14 @@ class GOVUKFrontendComponent {
   constructor($module) {
     this.checkSupport();
     this.checkInitialised($module);
-    const moduleName = this.constructor.moduleName;
+    const childClassConstructor = this.constructor;
+    const moduleName = childClassConstructor.moduleName;
+    const canInitialise = childClassConstructor.canInitialise;
+    if (typeof canInitialise === 'function') {
+      if (!canInitialise()) {
+        throw new CanInitError('`canInitialise` returned `false`');
+      }
+    }
     if (typeof moduleName === 'string') {
       moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
     } else {
@@ -124,6 +137,7 @@ class GOVUKFrontendComponent {
 /**
  * @typedef ChildClass
  * @property {string} [moduleName] - The module name that'll be looked for in the DOM when initialising the component
+ * @property {() => boolean} [canInitialise] - The module name that'll be looked for in the DOM when initialising the component
  */
 
 /**
diff --git a/packages/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.js b/packages/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.js
index 99c71b5ff..c5278bd8e 100644
--- a/packages/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.js
@@ -184,6 +184,12 @@
       this.name = 'SupportError';
     }
   }
+  class CanInitError extends GOVUKFrontendError {
+    constructor(...args) {
+      super(...args);
+      this.name = 'CanInitError';
+    }
+  }
   class ElementError extends GOVUKFrontendError {
     constructor(messageOrOptions) {
       let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
@@ -216,7 +222,14 @@
     constructor($module) {
       this.checkSupport();
       this.checkInitialised($module);
-      const moduleName = this.constructor.moduleName;
+      const childClassConstructor = this.constructor;
+      const moduleName = childClassConstructor.moduleName;
+      const canInitialise = childClassConstructor.canInitialise;
+      if (typeof canInitialise === 'function') {
+        if (!canInitialise()) {
+          throw new CanInitError('`canInitialise` returned `false`');
+        }
+      }
       if (typeof moduleName === 'string') {
         moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
       } else {
@@ -249,6 +262,7 @@
   /**
    * @typedef ChildClass
    * @property {string} [moduleName] - The module name that'll be looked for in the DOM when initialising the component
+   * @property {() => boolean} [canInitialise] - The module name that'll be looked for in the DOM when initialising the component
    */
 
   /**
diff --git a/packages/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.mjs b/packages/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.mjs
index 8600154f1..9fbc0f7f4 100644
--- a/packages/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/components/error-summary/error-summary.bundle.mjs
@@ -178,6 +178,12 @@ class SupportError extends GOVUKFrontendError {
     this.name = 'SupportError';
   }
 }
+class CanInitError extends GOVUKFrontendError {
+  constructor(...args) {
+    super(...args);
+    this.name = 'CanInitError';
+  }
+}
 class ElementError extends GOVUKFrontendError {
   constructor(messageOrOptions) {
     let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
@@ -210,7 +216,14 @@ class GOVUKFrontendComponent {
   constructor($module) {
     this.checkSupport();
     this.checkInitialised($module);
-    const moduleName = this.constructor.moduleName;
+    const childClassConstructor = this.constructor;
+    const moduleName = childClassConstructor.moduleName;
+    const canInitialise = childClassConstructor.canInitialise;
+    if (typeof canInitialise === 'function') {
+      if (!canInitialise()) {
+        throw new CanInitError('`canInitialise` returned `false`');
+      }
+    }
     if (typeof moduleName === 'string') {
       moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
     } else {
@@ -243,6 +256,7 @@ class GOVUKFrontendComponent {
 /**
  * @typedef ChildClass
  * @property {string} [moduleName] - The module name that'll be looked for in the DOM when initialising the component
+ * @property {() => boolean} [canInitialise] - The module name that'll be looked for in the DOM when initialising the component
  */
 
 /**
diff --git a/packages/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.js b/packages/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.js
index fb4533397..863d24beb 100644
--- a/packages/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.js
@@ -154,6 +154,12 @@
       this.name = 'SupportError';
     }
   }
+  class CanInitError extends GOVUKFrontendError {
+    constructor(...args) {
+      super(...args);
+      this.name = 'CanInitError';
+    }
+  }
   class ElementError extends GOVUKFrontendError {
     constructor(messageOrOptions) {
       let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
@@ -186,7 +192,14 @@
     constructor($module) {
       this.checkSupport();
       this.checkInitialised($module);
-      const moduleName = this.constructor.moduleName;
+      const childClassConstructor = this.constructor;
+      const moduleName = childClassConstructor.moduleName;
+      const canInitialise = childClassConstructor.canInitialise;
+      if (typeof canInitialise === 'function') {
+        if (!canInitialise()) {
+          throw new CanInitError('`canInitialise` returned `false`');
+        }
+      }
       if (typeof moduleName === 'string') {
         moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
       } else {
@@ -219,6 +232,7 @@
   /**
    * @typedef ChildClass
    * @property {string} [moduleName] - The module name that'll be looked for in the DOM when initialising the component
+   * @property {() => boolean} [canInitialise] - The module name that'll be looked for in the DOM when initialising the component
    */
 
   /**
diff --git a/packages/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.mjs b/packages/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.mjs
index 714daefad..b30d7da1a 100644
--- a/packages/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.bundle.mjs
@@ -148,6 +148,12 @@ class SupportError extends GOVUKFrontendError {
     this.name = 'SupportError';
   }
 }
+class CanInitError extends GOVUKFrontendError {
+  constructor(...args) {
+    super(...args);
+    this.name = 'CanInitError';
+  }
+}
 class ElementError extends GOVUKFrontendError {
   constructor(messageOrOptions) {
     let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
@@ -180,7 +186,14 @@ class GOVUKFrontendComponent {
   constructor($module) {
     this.checkSupport();
     this.checkInitialised($module);
-    const moduleName = this.constructor.moduleName;
+    const childClassConstructor = this.constructor;
+    const moduleName = childClassConstructor.moduleName;
+    const canInitialise = childClassConstructor.canInitialise;
+    if (typeof canInitialise === 'function') {
+      if (!canInitialise()) {
+        throw new CanInitError('`canInitialise` returned `false`');
+      }
+    }
     if (typeof moduleName === 'string') {
       moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
     } else {
@@ -213,6 +226,7 @@ class GOVUKFrontendComponent {
 /**
  * @typedef ChildClass
  * @property {string} [moduleName] - The module name that'll be looked for in the DOM when initialising the component
+ * @property {() => boolean} [canInitialise] - The module name that'll be looked for in the DOM when initialising the component
  */
 
 /**
diff --git a/packages/govuk-frontend/dist/govuk/components/header/header.bundle.js b/packages/govuk-frontend/dist/govuk/components/header/header.bundle.js
index 5bbcbe1be..1684ab05e 100644
--- a/packages/govuk-frontend/dist/govuk/components/header/header.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/components/header/header.bundle.js
@@ -73,6 +73,12 @@
       this.name = 'SupportError';
     }
   }
+  class CanInitError extends GOVUKFrontendError {
+    constructor(...args) {
+      super(...args);
+      this.name = 'CanInitError';
+    }
+  }
   class ElementError extends GOVUKFrontendError {
     constructor(messageOrOptions) {
       let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
@@ -105,7 +111,14 @@
     constructor($module) {
       this.checkSupport();
       this.checkInitialised($module);
-      const moduleName = this.constructor.moduleName;
+      const childClassConstructor = this.constructor;
+      const moduleName = childClassConstructor.moduleName;
+      const canInitialise = childClassConstructor.canInitialise;
+      if (typeof canInitialise === 'function') {
+        if (!canInitialise()) {
+          throw new CanInitError('`canInitialise` returned `false`');
+        }
+      }
       if (typeof moduleName === 'string') {
         moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
       } else {
@@ -138,6 +151,7 @@
   /**
    * @typedef ChildClass
    * @property {string} [moduleName] - The module name that'll be looked for in the DOM when initialising the component
+   * @property {() => boolean} [canInitialise] - The module name that'll be looked for in the DOM when initialising the component
    */
 
   /**
diff --git a/packages/govuk-frontend/dist/govuk/components/header/header.bundle.mjs b/packages/govuk-frontend/dist/govuk/components/header/header.bundle.mjs
index 224c11925..f09e98cee 100644
--- a/packages/govuk-frontend/dist/govuk/components/header/header.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/components/header/header.bundle.mjs
@@ -67,6 +67,12 @@ class SupportError extends GOVUKFrontendError {
     this.name = 'SupportError';
   }
 }
+class CanInitError extends GOVUKFrontendError {
+  constructor(...args) {
+    super(...args);
+    this.name = 'CanInitError';
+  }
+}
 class ElementError extends GOVUKFrontendError {
   constructor(messageOrOptions) {
     let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
@@ -99,7 +105,14 @@ class GOVUKFrontendComponent {
   constructor($module) {
     this.checkSupport();
     this.checkInitialised($module);
-    const moduleName = this.constructor.moduleName;
+    const childClassConstructor = this.constructor;
+    const moduleName = childClassConstructor.moduleName;
+    const canInitialise = childClassConstructor.canInitialise;
+    if (typeof canInitialise === 'function') {
+      if (!canInitialise()) {
+        throw new CanInitError('`canInitialise` returned `false`');
+      }
+    }
     if (typeof moduleName === 'string') {
       moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
     } else {
@@ -132,6 +145,7 @@ class GOVUKFrontendComponent {
 /**
  * @typedef ChildClass
  * @property {string} [moduleName] - The module name that'll be looked for in the DOM when initialising the component
+ * @property {() => boolean} [canInitialise] - The module name that'll be looked for in the DOM when initialising the component
  */
 
 /**
diff --git a/packages/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.js b/packages/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.js
index 6a44dd11c..b848f91c8 100644
--- a/packages/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.js
@@ -178,6 +178,12 @@
       this.name = 'SupportError';
     }
   }
+  class CanInitError extends GOVUKFrontendError {
+    constructor(...args) {
+      super(...args);
+      this.name = 'CanInitError';
+    }
+  }
   class ElementError extends GOVUKFrontendError {
     constructor(messageOrOptions) {
       let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
@@ -210,7 +216,14 @@
     constructor($module) {
       this.checkSupport();
       this.checkInitialised($module);
-      const moduleName = this.constructor.moduleName;
+      const childClassConstructor = this.constructor;
+      const moduleName = childClassConstructor.moduleName;
+      const canInitialise = childClassConstructor.canInitialise;
+      if (typeof canInitialise === 'function') {
+        if (!canInitialise()) {
+          throw new CanInitError('`canInitialise` returned `false`');
+        }
+      }
       if (typeof moduleName === 'string') {
         moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
       } else {
@@ -243,6 +256,7 @@
   /**
    * @typedef ChildClass
    * @property {string} [moduleName] - The module name that'll be looked for in the DOM when initialising the component
+   * @property {() => boolean} [canInitialise] - The module name that'll be looked for in the DOM when initialising the component
    */
 
   /**
diff --git a/packages/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.mjs b/packages/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.mjs
index 7b0c12d39..77606252d 100644
--- a/packages/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.bundle.mjs
@@ -172,6 +172,12 @@ class SupportError extends GOVUKFrontendError {
     this.name = 'SupportError';
   }
 }
+class CanInitError extends GOVUKFrontendError {
+  constructor(...args) {
+    super(...args);
+    this.name = 'CanInitError';
+  }
+}
 class ElementError extends GOVUKFrontendError {
   constructor(messageOrOptions) {
     let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
@@ -204,7 +210,14 @@ class GOVUKFrontendComponent {
   constructor($module) {
     this.checkSupport();
     this.checkInitialised($module);
-    const moduleName = this.constructor.moduleName;
+    const childClassConstructor = this.constructor;
+    const moduleName = childClassConstructor.moduleName;
+    const canInitialise = childClassConstructor.canInitialise;
+    if (typeof canInitialise === 'function') {
+      if (!canInitialise()) {
+        throw new CanInitError('`canInitialise` returned `false`');
+      }
+    }
     if (typeof moduleName === 'string') {
       moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
     } else {
@@ -237,6 +250,7 @@ class GOVUKFrontendComponent {
 /**
  * @typedef ChildClass
  * @property {string} [moduleName] - The module name that'll be looked for in the DOM when initialising the component
+ * @property {() => boolean} [canInitialise] - The module name that'll be looked for in the DOM when initialising the component
  */
 
 /**
diff --git a/packages/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.js b/packages/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.js
index 38adb9a52..1bcc2a082 100644
--- a/packages/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.js
@@ -159,6 +159,12 @@
       this.name = 'SupportError';
     }
   }
+  class CanInitError extends GOVUKFrontendError {
+    constructor(...args) {
+      super(...args);
+      this.name = 'CanInitError';
+    }
+  }
   class ElementError extends GOVUKFrontendError {
     constructor(messageOrOptions) {
       let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
@@ -191,7 +197,14 @@
     constructor($module) {
       this.checkSupport();
       this.checkInitialised($module);
-      const moduleName = this.constructor.moduleName;
+      const childClassConstructor = this.constructor;
+      const moduleName = childClassConstructor.moduleName;
+      const canInitialise = childClassConstructor.canInitialise;
+      if (typeof canInitialise === 'function') {
+        if (!canInitialise()) {
+          throw new CanInitError('`canInitialise` returned `false`');
+        }
+      }
       if (typeof moduleName === 'string') {
         moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
       } else {
@@ -224,6 +237,7 @@
   /**
    * @typedef ChildClass
    * @property {string} [moduleName] - The module name that'll be looked for in the DOM when initialising the component
+   * @property {() => boolean} [canInitialise] - The module name that'll be looked for in the DOM when initialising the component
    */
 
   /**
diff --git a/packages/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.mjs b/packages/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.mjs
index a0465d235..bbcb852b4 100644
--- a/packages/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/components/password-input/password-input.bundle.mjs
@@ -153,6 +153,12 @@ class SupportError extends GOVUKFrontendError {
     this.name = 'SupportError';
   }
 }
+class CanInitError extends GOVUKFrontendError {
+  constructor(...args) {
+    super(...args);
+    this.name = 'CanInitError';
+  }
+}
 class ElementError extends GOVUKFrontendError {
   constructor(messageOrOptions) {
     let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
@@ -185,7 +191,14 @@ class GOVUKFrontendComponent {
   constructor($module) {
     this.checkSupport();
     this.checkInitialised($module);
-    const moduleName = this.constructor.moduleName;
+    const childClassConstructor = this.constructor;
+    const moduleName = childClassConstructor.moduleName;
+    const canInitialise = childClassConstructor.canInitialise;
+    if (typeof canInitialise === 'function') {
+      if (!canInitialise()) {
+        throw new CanInitError('`canInitialise` returned `false`');
+      }
+    }
     if (typeof moduleName === 'string') {
       moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
     } else {
@@ -218,6 +231,7 @@ class GOVUKFrontendComponent {
 /**
  * @typedef ChildClass
  * @property {string} [moduleName] - The module name that'll be looked for in the DOM when initialising the component
+ * @property {() => boolean} [canInitialise] - The module name that'll be looked for in the DOM when initialising the component
  */
 
 /**
diff --git a/packages/govuk-frontend/dist/govuk/components/radios/radios.bundle.js b/packages/govuk-frontend/dist/govuk/components/radios/radios.bundle.js
index 7444eea07..804488bc2 100644
--- a/packages/govuk-frontend/dist/govuk/components/radios/radios.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/components/radios/radios.bundle.js
@@ -22,6 +22,12 @@
       this.name = 'SupportError';
     }
   }
+  class CanInitError extends GOVUKFrontendError {
+    constructor(...args) {
+      super(...args);
+      this.name = 'CanInitError';
+    }
+  }
   class ElementError extends GOVUKFrontendError {
     constructor(messageOrOptions) {
       let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
@@ -97,7 +103,14 @@
     constructor($module) {
       this.checkSupport();
       this.checkInitialised($module);
-      const moduleName = this.constructor.moduleName;
+      const childClassConstructor = this.constructor;
+      const moduleName = childClassConstructor.moduleName;
+      const canInitialise = childClassConstructor.canInitialise;
+      if (typeof canInitialise === 'function') {
+        if (!canInitialise()) {
+          throw new CanInitError('`canInitialise` returned `false`');
+        }
+      }
       if (typeof moduleName === 'string') {
         moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
       } else {
@@ -130,6 +143,7 @@
   /**
    * @typedef ChildClass
    * @property {string} [moduleName] - The module name that'll be looked for in the DOM when initialising the component
+   * @property {() => boolean} [canInitialise] - The module name that'll be looked for in the DOM when initialising the component
    */
 
   /**
diff --git a/packages/govuk-frontend/dist/govuk/components/radios/radios.bundle.mjs b/packages/govuk-frontend/dist/govuk/components/radios/radios.bundle.mjs
index 1fd810d35..6c448a82b 100644
--- a/packages/govuk-frontend/dist/govuk/components/radios/radios.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/components/radios/radios.bundle.mjs
@@ -16,6 +16,12 @@ class SupportError extends GOVUKFrontendError {
     this.name = 'SupportError';
   }
 }
+class CanInitError extends GOVUKFrontendError {
+  constructor(...args) {
+    super(...args);
+    this.name = 'CanInitError';
+  }
+}
 class ElementError extends GOVUKFrontendError {
   constructor(messageOrOptions) {
     let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
@@ -91,7 +97,14 @@ class GOVUKFrontendComponent {
   constructor($module) {
     this.checkSupport();
     this.checkInitialised($module);
-    const moduleName = this.constructor.moduleName;
+    const childClassConstructor = this.constructor;
+    const moduleName = childClassConstructor.moduleName;
+    const canInitialise = childClassConstructor.canInitialise;
+    if (typeof canInitialise === 'function') {
+      if (!canInitialise()) {
+        throw new CanInitError('`canInitialise` returned `false`');
+      }
+    }
     if (typeof moduleName === 'string') {
       moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
     } else {
@@ -124,6 +137,7 @@ class GOVUKFrontendComponent {
 /**
  * @typedef ChildClass
  * @property {string} [moduleName] - The module name that'll be looked for in the DOM when initialising the component
+ * @property {() => boolean} [canInitialise] - The module name that'll be looked for in the DOM when initialising the component
  */
 
 /**
diff --git a/packages/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.js b/packages/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.js
index 09499031c..00e3264ec 100644
--- a/packages/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.js
@@ -73,6 +73,12 @@
       this.name = 'SupportError';
     }
   }
+  class CanInitError extends GOVUKFrontendError {
+    constructor(...args) {
+      super(...args);
+      this.name = 'CanInitError';
+    }
+  }
   class ElementError extends GOVUKFrontendError {
     constructor(messageOrOptions) {
       let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
@@ -105,7 +111,14 @@
     constructor($module) {
       this.checkSupport();
       this.checkInitialised($module);
-      const moduleName = this.constructor.moduleName;
+      const childClassConstructor = this.constructor;
+      const moduleName = childClassConstructor.moduleName;
+      const canInitialise = childClassConstructor.canInitialise;
+      if (typeof canInitialise === 'function') {
+        if (!canInitialise()) {
+          throw new CanInitError('`canInitialise` returned `false`');
+        }
+      }
       if (typeof moduleName === 'string') {
         moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
       } else {
@@ -138,6 +151,7 @@
   /**
    * @typedef ChildClass
    * @property {string} [moduleName] - The module name that'll be looked for in the DOM when initialising the component
+   * @property {() => boolean} [canInitialise] - The module name that'll be looked for in the DOM when initialising the component
    */
 
   /**
diff --git a/packages/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.mjs b/packages/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.mjs
index c944b0639..73b94ff5d 100644
--- a/packages/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/components/service-navigation/service-navigation.bundle.mjs
@@ -67,6 +67,12 @@ class SupportError extends GOVUKFrontendError {
     this.name = 'SupportError';
   }
 }
+class CanInitError extends GOVUKFrontendError {
+  constructor(...args) {
+    super(...args);
+    this.name = 'CanInitError';
+  }
+}
 class ElementError extends GOVUKFrontendError {
   constructor(messageOrOptions) {
     let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
@@ -99,7 +105,14 @@ class GOVUKFrontendComponent {
   constructor($module) {
     this.checkSupport();
     this.checkInitialised($module);
-    const moduleName = this.constructor.moduleName;
+    const childClassConstructor = this.constructor;
+    const moduleName = childClassConstructor.moduleName;
+    const canInitialise = childClassConstructor.canInitialise;
+    if (typeof canInitialise === 'function') {
+      if (!canInitialise()) {
+        throw new CanInitError('`canInitialise` returned `false`');
+      }
+    }
     if (typeof moduleName === 'string') {
       moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
     } else {
@@ -132,6 +145,7 @@ class GOVUKFrontendComponent {
 /**
  * @typedef ChildClass
  * @property {string} [moduleName] - The module name that'll be looked for in the DOM when initialising the component
+ * @property {() => boolean} [canInitialise] - The module name that'll be looked for in the DOM when initialising the component
  */
 
 /**
diff --git a/packages/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.js b/packages/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.js
index 29e6e9727..623eb2dfc 100644
--- a/packages/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.js
@@ -95,6 +95,12 @@
       this.name = 'SupportError';
     }
   }
+  class CanInitError extends GOVUKFrontendError {
+    constructor(...args) {
+      super(...args);
+      this.name = 'CanInitError';
+    }
+  }
   class ElementError extends GOVUKFrontendError {
     constructor(messageOrOptions) {
       let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
@@ -127,7 +133,14 @@
     constructor($module) {
       this.checkSupport();
       this.checkInitialised($module);
-      const moduleName = this.constructor.moduleName;
+      const childClassConstructor = this.constructor;
+      const moduleName = childClassConstructor.moduleName;
+      const canInitialise = childClassConstructor.canInitialise;
+      if (typeof canInitialise === 'function') {
+        if (!canInitialise()) {
+          throw new CanInitError('`canInitialise` returned `false`');
+        }
+      }
       if (typeof moduleName === 'string') {
         moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
       } else {
@@ -160,6 +173,7 @@
   /**
    * @typedef ChildClass
    * @property {string} [moduleName] - The module name that'll be looked for in the DOM when initialising the component
+   * @property {() => boolean} [canInitialise] - The module name that'll be looked for in the DOM when initialising the component
    */
 
   /**
diff --git a/packages/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.mjs b/packages/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.mjs
index b5b902021..eeeb89015 100644
--- a/packages/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/components/skip-link/skip-link.bundle.mjs
@@ -89,6 +89,12 @@ class SupportError extends GOVUKFrontendError {
     this.name = 'SupportError';
   }
 }
+class CanInitError extends GOVUKFrontendError {
+  constructor(...args) {
+    super(...args);
+    this.name = 'CanInitError';
+  }
+}
 class ElementError extends GOVUKFrontendError {
   constructor(messageOrOptions) {
     let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
@@ -121,7 +127,14 @@ class GOVUKFrontendComponent {
   constructor($module) {
     this.checkSupport();
     this.checkInitialised($module);
-    const moduleName = this.constructor.moduleName;
+    const childClassConstructor = this.constructor;
+    const moduleName = childClassConstructor.moduleName;
+    const canInitialise = childClassConstructor.canInitialise;
+    if (typeof canInitialise === 'function') {
+      if (!canInitialise()) {
+        throw new CanInitError('`canInitialise` returned `false`');
+      }
+    }
     if (typeof moduleName === 'string') {
       moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
     } else {
@@ -154,6 +167,7 @@ class GOVUKFrontendComponent {
 /**
  * @typedef ChildClass
  * @property {string} [moduleName] - The module name that'll be looked for in the DOM when initialising the component
+ * @property {() => boolean} [canInitialise] - The module name that'll be looked for in the DOM when initialising the component
  */
 
 /**
diff --git a/packages/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.js b/packages/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.js
index 3400748c8..e5f4cb854 100644
--- a/packages/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.js
@@ -79,6 +79,12 @@
       this.name = 'SupportError';
     }
   }
+  class CanInitError extends GOVUKFrontendError {
+    constructor(...args) {
+      super(...args);
+      this.name = 'CanInitError';
+    }
+  }
   class ElementError extends GOVUKFrontendError {
     constructor(messageOrOptions) {
       let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
@@ -111,7 +117,14 @@
     constructor($module) {
       this.checkSupport();
       this.checkInitialised($module);
-      const moduleName = this.constructor.moduleName;
+      const childClassConstructor = this.constructor;
+      const moduleName = childClassConstructor.moduleName;
+      const canInitialise = childClassConstructor.canInitialise;
+      if (typeof canInitialise === 'function') {
+        if (!canInitialise()) {
+          throw new CanInitError('`canInitialise` returned `false`');
+        }
+      }
       if (typeof moduleName === 'string') {
         moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
       } else {
@@ -144,6 +157,7 @@
   /**
    * @typedef ChildClass
    * @property {string} [moduleName] - The module name that'll be looked for in the DOM when initialising the component
+   * @property {() => boolean} [canInitialise] - The module name that'll be looked for in the DOM when initialising the component
    */
 
   /**
diff --git a/packages/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.mjs b/packages/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.mjs
index fb5ce2526..dc7a69a44 100644
--- a/packages/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/components/tabs/tabs.bundle.mjs
@@ -73,6 +73,12 @@ class SupportError extends GOVUKFrontendError {
     this.name = 'SupportError';
   }
 }
+class CanInitError extends GOVUKFrontendError {
+  constructor(...args) {
+    super(...args);
+    this.name = 'CanInitError';
+  }
+}
 class ElementError extends GOVUKFrontendError {
   constructor(messageOrOptions) {
     let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
@@ -105,7 +111,14 @@ class GOVUKFrontendComponent {
   constructor($module) {
     this.checkSupport();
     this.checkInitialised($module);
-    const moduleName = this.constructor.moduleName;
+    const childClassConstructor = this.constructor;
+    const moduleName = childClassConstructor.moduleName;
+    const canInitialise = childClassConstructor.canInitialise;
+    if (typeof canInitialise === 'function') {
+      if (!canInitialise()) {
+        throw new CanInitError('`canInitialise` returned `false`');
+      }
+    }
     if (typeof moduleName === 'string') {
       moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
     } else {
@@ -138,6 +151,7 @@ class GOVUKFrontendComponent {
 /**
  * @typedef ChildClass
  * @property {string} [moduleName] - The module name that'll be looked for in the DOM when initialising the component
+ * @property {() => boolean} [canInitialise] - The module name that'll be looked for in the DOM when initialising the component
  */
 
 /**
diff --git a/packages/govuk-frontend/dist/govuk/errors/index.mjs b/packages/govuk-frontend/dist/govuk/errors/index.mjs
index 5fdb0858c..83066b6cd 100644
--- a/packages/govuk-frontend/dist/govuk/errors/index.mjs
+++ b/packages/govuk-frontend/dist/govuk/errors/index.mjs
@@ -22,6 +22,12 @@ class ConfigError extends GOVUKFrontendError {
     this.name = 'ConfigError';
   }
 }
+class CanInitError extends GOVUKFrontendError {
+  constructor(...args) {
+    super(...args);
+    this.name = 'CanInitError';
+  }
+}
 class ElementError extends GOVUKFrontendError {
   constructor(messageOrOptions) {
     let message = typeof messageOrOptions === 'string' ? messageOrOptions : '';
@@ -50,5 +56,5 @@ class InitError extends GOVUKFrontendError {
   }
 }
 
-export { ConfigError, ElementError, GOVUKFrontendError, InitError, SupportError };
+export { CanInitError, ConfigError, ElementError, GOVUKFrontendError, InitError, SupportError };
 //# sourceMappingURL=index.mjs.map
diff --git a/packages/govuk-frontend/dist/govuk/govuk-frontend-component.mjs b/packages/govuk-frontend/dist/govuk/govuk-frontend-component.mjs
index 2bf203f9d..5c058ee5a 100644
--- a/packages/govuk-frontend/dist/govuk/govuk-frontend-component.mjs
+++ b/packages/govuk-frontend/dist/govuk/govuk-frontend-component.mjs
@@ -1,11 +1,18 @@
 import { isInitialised, isSupported } from './common/index.mjs';
-import { InitError, SupportError } from './errors/index.mjs';
+import { CanInitError, InitError, SupportError } from './errors/index.mjs';
 
 class GOVUKFrontendComponent {
   constructor($module) {
     this.checkSupport();
     this.checkInitialised($module);
-    const moduleName = this.constructor.moduleName;
+    const childClassConstructor = this.constructor;
+    const moduleName = childClassConstructor.moduleName;
+    const canInitialise = childClassConstructor.canInitialise;
+    if (typeof canInitialise === 'function') {
+      if (!canInitialise()) {
+        throw new CanInitError('`canInitialise` returned `false`');
+      }
+    }
     if (typeof moduleName === 'string') {
       moduleName && ($module == null ? void 0 : $module.setAttribute(`data-${moduleName}-init`, ''));
     } else {
@@ -38,6 +45,7 @@ class GOVUKFrontendComponent {
 /**
  * @typedef ChildClass
  * @property {string} [moduleName] - The module name that'll be looked for in the DOM when initialising the component
+ * @property {() => boolean} [canInitialise] - The module name that'll be looked for in the DOM when initialising the component
  */
 
 /**

Action run for 1824bf1

If `canInitialise` defined in class that extends GOVUKFrontendComponent
then `canInitialise` will be executed in `super()` before initialisation
routine and prevent child component from initialising.
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-5333 September 18, 2024 13:48 Inactive
@romaricpascal
Copy link
Member

Closing as we're picking a different route after noticing the overlap with the existing checkSupport.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants