@u-elements/u-tabs 0.1.0 → 0.1.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.
package/dist/u-tabs.cjs CHANGED
@@ -89,23 +89,10 @@ var ATTR_TABS = "data-utabs";
89
89
  var UHTMLTabsElement = class extends UHTMLElement {
90
90
  constructor() {
91
91
  super();
92
- attr(this, ATTR_TABS, "");
93
92
  attachStyle(this, UHTMLTabsStyle);
94
93
  }
95
94
  connectedCallback() {
96
- mutationObserver(this, {
97
- attributeFilter: ["role"],
98
- attributes: true,
99
- childList: true,
100
- subtree: true
101
- });
102
- }
103
- handleEvent() {
104
- var _a2;
105
- (_a2 = this.tabList) == null ? void 0 : _a2.handleEvent();
106
- }
107
- disconnectedCallback() {
108
- mutationObserver(this, false);
95
+ attr(this, ATTR_TABS, "");
109
96
  }
110
97
  get tabList() {
111
98
  return queryWithoutNested("tablist", this)[0] || null;
@@ -182,7 +169,7 @@ var UHTMLTabListElement = class extends UHTMLElement {
182
169
  setSelected(this.tabs[index]);
183
170
  }
184
171
  };
185
- var SKIP_ATTR_CHANGE = false;
172
+ var SKIP_ATTR_CHANGE_TAB = false;
186
173
  var UHTMLTabElement = class extends UHTMLElement {
187
174
  // Using ES2015 syntax for backwards compatibility
188
175
  static get observedAttributes() {
@@ -197,8 +184,8 @@ var UHTMLTabElement = class extends UHTMLElement {
197
184
  attr(this, "tabindex", this.selected ? "0" : "-1");
198
185
  }
199
186
  attributeChangedCallback() {
200
- if (!SKIP_ATTR_CHANGE && this.selected && this.tabList) {
201
- SKIP_ATTR_CHANGE = true;
187
+ if (!SKIP_ATTR_CHANGE_TAB && this.selected && this.tabList) {
188
+ SKIP_ATTR_CHANGE_TAB = true;
202
189
  const tabs = this.tabList ? getTabs(this.tabList) : [];
203
190
  const panels = queryWithoutNested("tabpanel", this.tabsElement || this);
204
191
  const nextPanel = getPanel(this, panels[[...tabs].indexOf(this)]);
@@ -211,7 +198,7 @@ var UHTMLTabElement = class extends UHTMLElement {
211
198
  if (panel == null ? void 0 : panel.id) attr(tab, ARIA_CONTROLS, panel.id);
212
199
  if (panel) panel.hidden = panel !== nextPanel;
213
200
  }
214
- SKIP_ATTR_CHANGE = false;
201
+ SKIP_ATTR_CHANGE_TAB = false;
215
202
  }
216
203
  }
217
204
  get tabsElement() {
@@ -236,24 +223,30 @@ var UHTMLTabElement = class extends UHTMLElement {
236
223
  return getPanel(this);
237
224
  }
238
225
  };
226
+ var SKIP_ATTR_CHANGE_PANEL = false;
239
227
  var UHTMLTabPanelElement = class extends UHTMLElement {
240
228
  // Using ES2015 syntax for backwards compatibility
241
229
  static get observedAttributes() {
242
- return ["hidden"];
230
+ return ["id", "hidden"];
243
231
  }
244
232
  constructor() {
245
233
  super();
246
234
  attachStyle(this, UHTMLTabPanelStyle);
247
235
  }
248
236
  connectedCallback() {
237
+ var _a2, _b;
249
238
  attr(this, "role", "tabpanel");
250
- this.hidden = getSelectedIndex(this.tabs) === -1;
239
+ (_b = (_a2 = this.tabsElement) == null ? void 0 : _a2.tabList) == null ? void 0 : _b.handleEvent();
251
240
  this.attributeChangedCallback();
252
241
  }
253
242
  attributeChangedCallback() {
254
- const hidden = this.hidden;
255
- attr(this, "aria-hidden", `${hidden}`);
256
- attr(this, "tabindex", hidden || isFocusable(this.firstChild) ? null : "0");
243
+ if (SKIP_ATTR_CHANGE_PANEL) return;
244
+ SKIP_ATTR_CHANGE_PANEL = true;
245
+ const hasFocusable = isFocusable(this.firstChild);
246
+ this.hidden = getSelectedIndex(this.tabs) === -1;
247
+ attr(this, "aria-hidden", `${this.hidden}`);
248
+ attr(this, "tabindex", this.hidden || hasFocusable ? null : "0");
249
+ SKIP_ATTR_CHANGE_PANEL = false;
257
250
  }
258
251
  get tabsElement() {
259
252
  return getTabsElement(this);
package/dist/u-tabs.d.cts CHANGED
@@ -26,8 +26,6 @@ declare const UHTMLTabPanelShadowRoot: string;
26
26
  declare class UHTMLTabsElement extends UHTMLElement {
27
27
  constructor();
28
28
  connectedCallback(): void;
29
- handleEvent(): void;
30
- disconnectedCallback(): void;
31
29
  get tabList(): UHTMLTabListElement | null;
32
30
  get selectedIndex(): number;
33
31
  set selectedIndex(index: number);
@@ -61,10 +59,6 @@ declare class UHTMLTabElement extends UHTMLElement {
61
59
  get index(): number;
62
60
  get panel(): HTMLElement | null;
63
61
  }
64
- /**
65
- * The `<u-tabpanel>` HTML element is a container for the resources of layered content associated with a `<u-tab>`.
66
- * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/tabpanel_role)
67
- */
68
62
  declare class UHTMLTabPanelElement extends UHTMLElement {
69
63
  static get observedAttributes(): string[];
70
64
  constructor();
package/dist/u-tabs.d.ts CHANGED
@@ -26,8 +26,6 @@ declare const UHTMLTabPanelShadowRoot: string;
26
26
  declare class UHTMLTabsElement extends UHTMLElement {
27
27
  constructor();
28
28
  connectedCallback(): void;
29
- handleEvent(): void;
30
- disconnectedCallback(): void;
31
29
  get tabList(): UHTMLTabListElement | null;
32
30
  get selectedIndex(): number;
33
31
  set selectedIndex(index: number);
@@ -61,10 +59,6 @@ declare class UHTMLTabElement extends UHTMLElement {
61
59
  get index(): number;
62
60
  get panel(): HTMLElement | null;
63
61
  }
64
- /**
65
- * The `<u-tabpanel>` HTML element is a container for the resources of layered content associated with a `<u-tab>`.
66
- * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/tabpanel_role)
67
- */
68
62
  declare class UHTMLTabPanelElement extends UHTMLElement {
69
63
  static get observedAttributes(): string[];
70
64
  constructor();
package/dist/u-tabs.js CHANGED
@@ -87,23 +87,10 @@ var ATTR_TABS = "data-utabs";
87
87
  var UHTMLTabsElement = class extends UHTMLElement {
88
88
  constructor() {
89
89
  super();
90
- attr(this, ATTR_TABS, "");
91
90
  attachStyle(this, UHTMLTabsStyle);
92
91
  }
93
92
  connectedCallback() {
94
- mutationObserver(this, {
95
- attributeFilter: ["role"],
96
- attributes: true,
97
- childList: true,
98
- subtree: true
99
- });
100
- }
101
- handleEvent() {
102
- var _a2;
103
- (_a2 = this.tabList) == null ? void 0 : _a2.handleEvent();
104
- }
105
- disconnectedCallback() {
106
- mutationObserver(this, false);
93
+ attr(this, ATTR_TABS, "");
107
94
  }
108
95
  get tabList() {
109
96
  return queryWithoutNested("tablist", this)[0] || null;
@@ -180,7 +167,7 @@ var UHTMLTabListElement = class extends UHTMLElement {
180
167
  setSelected(this.tabs[index]);
181
168
  }
182
169
  };
183
- var SKIP_ATTR_CHANGE = false;
170
+ var SKIP_ATTR_CHANGE_TAB = false;
184
171
  var UHTMLTabElement = class extends UHTMLElement {
185
172
  // Using ES2015 syntax for backwards compatibility
186
173
  static get observedAttributes() {
@@ -195,8 +182,8 @@ var UHTMLTabElement = class extends UHTMLElement {
195
182
  attr(this, "tabindex", this.selected ? "0" : "-1");
196
183
  }
197
184
  attributeChangedCallback() {
198
- if (!SKIP_ATTR_CHANGE && this.selected && this.tabList) {
199
- SKIP_ATTR_CHANGE = true;
185
+ if (!SKIP_ATTR_CHANGE_TAB && this.selected && this.tabList) {
186
+ SKIP_ATTR_CHANGE_TAB = true;
200
187
  const tabs = this.tabList ? getTabs(this.tabList) : [];
201
188
  const panels = queryWithoutNested("tabpanel", this.tabsElement || this);
202
189
  const nextPanel = getPanel(this, panels[[...tabs].indexOf(this)]);
@@ -209,7 +196,7 @@ var UHTMLTabElement = class extends UHTMLElement {
209
196
  if (panel == null ? void 0 : panel.id) attr(tab, ARIA_CONTROLS, panel.id);
210
197
  if (panel) panel.hidden = panel !== nextPanel;
211
198
  }
212
- SKIP_ATTR_CHANGE = false;
199
+ SKIP_ATTR_CHANGE_TAB = false;
213
200
  }
214
201
  }
215
202
  get tabsElement() {
@@ -234,24 +221,30 @@ var UHTMLTabElement = class extends UHTMLElement {
234
221
  return getPanel(this);
235
222
  }
236
223
  };
224
+ var SKIP_ATTR_CHANGE_PANEL = false;
237
225
  var UHTMLTabPanelElement = class extends UHTMLElement {
238
226
  // Using ES2015 syntax for backwards compatibility
239
227
  static get observedAttributes() {
240
- return ["hidden"];
228
+ return ["id", "hidden"];
241
229
  }
242
230
  constructor() {
243
231
  super();
244
232
  attachStyle(this, UHTMLTabPanelStyle);
245
233
  }
246
234
  connectedCallback() {
235
+ var _a2, _b;
247
236
  attr(this, "role", "tabpanel");
248
- this.hidden = getSelectedIndex(this.tabs) === -1;
237
+ (_b = (_a2 = this.tabsElement) == null ? void 0 : _a2.tabList) == null ? void 0 : _b.handleEvent();
249
238
  this.attributeChangedCallback();
250
239
  }
251
240
  attributeChangedCallback() {
252
- const hidden = this.hidden;
253
- attr(this, "aria-hidden", `${hidden}`);
254
- attr(this, "tabindex", hidden || isFocusable(this.firstChild) ? null : "0");
241
+ if (SKIP_ATTR_CHANGE_PANEL) return;
242
+ SKIP_ATTR_CHANGE_PANEL = true;
243
+ const hasFocusable = isFocusable(this.firstChild);
244
+ this.hidden = getSelectedIndex(this.tabs) === -1;
245
+ attr(this, "aria-hidden", `${this.hidden}`);
246
+ attr(this, "tabindex", this.hidden || hasFocusable ? null : "0");
247
+ SKIP_ATTR_CHANGE_PANEL = false;
255
248
  }
256
249
  get tabsElement() {
257
250
  return getTabsElement(this);
@@ -50,10 +50,6 @@
50
50
  "description": "The `<u-tabs>` HTML element is used to group a `<u-tablist>` and several `<u-tabpanel>` elements.\nNo MDN reference available.",
51
51
  "name": "UHTMLTabsElement",
52
52
  "members": [
53
- {
54
- "kind": "method",
55
- "name": "handleEvent"
56
- },
57
53
  {
58
54
  "kind": "field",
59
55
  "name": "tabList",
@@ -202,7 +198,7 @@
202
198
  },
203
199
  {
204
200
  "kind": "class",
205
- "description": "The `<u-tabpanel>` HTML element is a container for the resources of layered content associated with a `<u-tab>`.\n[MDN Reference](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/tabpanel_role)",
201
+ "description": "",
206
202
  "name": "UHTMLTabPanelElement",
207
203
  "members": [
208
204
  {
@@ -223,6 +219,9 @@
223
219
  }
224
220
  ],
225
221
  "attributes": [
222
+ {
223
+ "name": "id"
224
+ },
226
225
  {
227
226
  "name": "hidden"
228
227
  }
@@ -22,8 +22,11 @@
22
22
  },
23
23
  {
24
24
  "name": "u-tabpanel",
25
- "description": "The `<u-tabpanel>` HTML element is a container for the resources of layered content associated with a `<u-tab>`.\n[MDN Reference](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/tabpanel_role)\n---\n",
26
- "attributes": [{ "name": "hidden", "values": [] }],
25
+ "description": "\n---\n",
26
+ "attributes": [
27
+ { "name": "id", "values": [] },
28
+ { "name": "hidden", "values": [] }
29
+ ],
27
30
  "references": []
28
31
  }
29
32
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@u-elements/u-tabs",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "license": "MIT",
5
5
  "description": "HTML tags, just truly accessible",
6
6
  "homepage": "https://u-elements.github.io/u-elements/",