@openeuropa/bcl-theme-joinup 1.6.0 → 1.8.0

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.
@@ -4697,6 +4697,56 @@
4697
4697
 
4698
4698
  defineJQueryPlugin(Offcanvas);
4699
4699
 
4700
+ /**
4701
+ * AccessibleToggle enhances Bootstrap Modal and Offcanvas components by:
4702
+ * - Adding ARIA attributes for improved accessibility.
4703
+ * - Updating `aria-expanded` on trigger elements based on visibility.
4704
+ * Automatically initializes all modal and offcanvas triggers on the page.
4705
+ */
4706
+ class AccessibleToggle {
4707
+ constructor(triggerElement, type) {
4708
+ this.triggerElement = triggerElement;
4709
+ this.type = type;
4710
+ const target = triggerElement.getAttribute("data-bs-target") || triggerElement.getAttribute("href");
4711
+ if (!target || target === "#") {
4712
+ return;
4713
+ }
4714
+ this.targetElement = SelectorEngine.findOne(target);
4715
+ if (!this.targetElement) {
4716
+ return;
4717
+ }
4718
+ if (this.type === "modal") {
4719
+ this.instance = Modal.getOrCreateInstance(this.targetElement);
4720
+ } else if (this.type === "offcanvas") {
4721
+ this.instance = Offcanvas.getOrCreateInstance(this.targetElement);
4722
+ }
4723
+ this.addAriaAttributes();
4724
+ this.addEventListeners();
4725
+ }
4726
+ addAriaAttributes() {
4727
+ if (this.triggerElement) {
4728
+ this.triggerElement.setAttribute("aria-haspopup", "true");
4729
+ this.triggerElement.setAttribute("aria-expanded", "false");
4730
+ }
4731
+ }
4732
+ addEventListeners() {
4733
+ const showEvent = this.type === "modal" ? "show.bs.modal" : "show.bs.offcanvas";
4734
+ const hideEvent = this.type === "modal" ? "hide.bs.modal" : "hide.bs.offcanvas";
4735
+ EventHandler.on(this.targetElement, showEvent, () => {
4736
+ this.triggerElement.setAttribute("aria-expanded", "true");
4737
+ });
4738
+ EventHandler.on(this.targetElement, hideEvent, () => {
4739
+ this.triggerElement.setAttribute("aria-expanded", "false");
4740
+ });
4741
+ }
4742
+ static init(toggles) {
4743
+ toggles.forEach(toggle => {
4744
+ const triggerElements = SelectorEngine.find(toggle.selector);
4745
+ triggerElements.forEach(triggerElement => new AccessibleToggle(triggerElement, toggle.type));
4746
+ });
4747
+ }
4748
+ }
4749
+
4700
4750
  /**
4701
4751
  * --------------------------------------------------------------------------
4702
4752
  * Bootstrap (v5.2.3): util/sanitizer.js
@@ -6511,6 +6561,7 @@
6511
6561
  Dropdown,
6512
6562
  Gallery,
6513
6563
  Modal,
6564
+ AccessibleToggle,
6514
6565
  Offcanvas,
6515
6566
  Popover,
6516
6567
  ScrollSpyV2: ScrollSpy$1,