@cocreate/aria 1.0.0 → 1.1.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # [1.1.0](https://github.com/CoCreate-app/CoCreate-aria/compare/v1.0.0...v1.1.0) (2025-11-16)
2
+
3
+
4
+ ### Features
5
+
6
+ * Enhance popup close conditions and aria attributes handling ([608da59](https://github.com/CoCreate-app/CoCreate-aria/commit/608da59ac5f179a2c9ddf27d2657c2f28d355766))
7
+ * Initialize aria controls and enhance event handling ([a62f790](https://github.com/CoCreate-app/CoCreate-aria/commit/a62f79079a0c889b8d395406df2ef4a704ac6552))
8
+
1
9
  # 1.0.0 (2025-08-25)
2
10
 
3
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/aria",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Chain multiple component executions to generate your desired logic, when one action is complete next one will start. The sequence goes until all aria have been completed. Vanilla javascript, easily configured using HTML5 attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "aria",
package/src/index.js CHANGED
@@ -11,6 +11,7 @@ let popupListener = null;
11
11
  function addPopupListener() {
12
12
  if (!popupListener) {
13
13
  popupListener = function (event) {
14
+
14
15
  const hasPopUps = document.querySelectorAll(
15
16
  '[aria-controls][aria-haspopup][aria-expanded="true"]'
16
17
  );
@@ -25,6 +26,7 @@ function addPopupListener() {
25
26
  skipControlledId = controlledId;
26
27
  continue; // Ignore clicks inside the popup
27
28
  }
29
+
28
30
  const controlledElement = document.getElementById(controlledId);
29
31
  let closeOn = controlledElement.getAttribute("aria-close-on");
30
32
  let closeOnEl = controlledElement;
@@ -37,13 +39,26 @@ function addPopupListener() {
37
39
  }
38
40
  }
39
41
 
40
- if (closeOn === "outside") {
41
- if (closeOnEl.contains(event.target)) continue;
42
- } else if (closeOn === "button" || closeOn === "btn") {
43
- continue;
42
+ let closeOnConditions = closeOn ? closeOn.split(",").map(c => c.trim()) : [];
43
+
44
+ let shouldClose = false;
45
+ for (let condition of closeOnConditions) {
46
+ if (condition === "outside" && !closeOnEl.contains(event.target)) {
47
+ shouldClose = true;
48
+ } else if (condition === "inside" && closeOnEl.contains(event.target)) {
49
+ shouldClose = true;
50
+ } else if (condition === "anywhere") {
51
+ shouldClose = true;
52
+ }
53
+
54
+ // If any condition matches, break the loop
55
+ if (shouldClose) break;
44
56
  }
45
57
 
58
+ if (!shouldClose) continue;
59
+
46
60
  controlledElement.classList.remove("show");
61
+ controlledElement.setAttribute("aria-hidden", "true");
47
62
  updateAllControls(controlledId, "false");
48
63
  }
49
64
  // Remove listener if no popups remain open
@@ -104,6 +119,7 @@ function initElement(elements) {
104
119
  const hasAriaOpen = this.hasAttribute("aria-open");
105
120
  const hasAriaClose = this.hasAttribute("aria-close");
106
121
  const expanded = this.getAttribute("aria-expanded");
122
+ const controlsClass = this.getAttribute("aria-controls-class") || "show";
107
123
 
108
124
  // Apply aria-open and aria-close logic globally, before any role-specific logic
109
125
  if (hasAriaOpen && expanded === "true") {
@@ -124,20 +140,32 @@ function initElement(elements) {
124
140
  document.getElementById(tabControlledId);
125
141
  if (this === tab) {
126
142
  tab.setAttribute("aria-selected", "true");
127
- tabControlledEl.classList.add("show");
143
+ tabControlledEl.setAttribute("aria-hidden", "false");
144
+ if (controlsClass) {
145
+ tabControlledEl.classList.add(controlsClass);
146
+ }
128
147
  } else {
129
148
  tab.setAttribute("aria-selected", "false");
130
- tabControlledEl.classList.remove("show");
149
+ tabControlledEl.setAttribute("aria-hidden", "true");
150
+ if (controlsClass) {
151
+ tabControlledEl.classList.remove(controlsClass);
152
+ }
131
153
  }
132
154
  }
133
155
  } else {
134
156
  // Default toggle logic
135
157
  if (expanded === "true") {
136
- controlledElement.classList.remove("show");
158
+ controlledElement.setAttribute("aria-hidden", "true");
159
+ if (controlsClass) {
160
+ controlledElement.classList.remove(controlsClass);
161
+ }
137
162
  updateAllControls(controlledId, "false");
138
163
  removePopupListener();
139
164
  } else {
140
- controlledElement.classList.add("show");
165
+ controlledElement.setAttribute("aria-hidden", "false");
166
+ if (controlsClass) {
167
+ controlledElement.classList.add(controlsClass);
168
+ }
141
169
  updateAllControls(controlledId, "true");
142
170
  if (closeOn !== "btn" && closeOn !== "button") {
143
171
  addPopupListener();