@u-elements/u-tabs 0.0.4 → 0.0.5
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 +12 -12
- package/dist/u-tabs.js +12 -12
- package/package.json +1 -1
package/dist/u-tabs.cjs
CHANGED
|
@@ -115,28 +115,27 @@ var UHTMLTabElement = class extends UHTMLElement {
|
|
|
115
115
|
);
|
|
116
116
|
}
|
|
117
117
|
connectedCallback() {
|
|
118
|
-
const selected = this.selected || [...queryWithoutNested("u-tab", this.tabList || this)].
|
|
119
|
-
(tab) => tab.ariaSelected !== "true"
|
|
120
|
-
);
|
|
118
|
+
const selected = this.selected || ![...queryWithoutNested("u-tab", this.tabList || this)].some(isSelected);
|
|
121
119
|
this.role = "tab";
|
|
122
120
|
this.tabIndex = selected ? 0 : -1;
|
|
123
121
|
this.ariaSelected = `${selected}`;
|
|
122
|
+
if (!this.hasAttribute(ARIA_CONTROLS))
|
|
123
|
+
this.setAttribute(ARIA_CONTROLS, useId(getPanel(this)));
|
|
124
124
|
}
|
|
125
125
|
attributeChangedCallback(name, prev) {
|
|
126
126
|
if (!this.selected) return;
|
|
127
127
|
const nextPanel = getPanel(this);
|
|
128
128
|
const nextPanelId = useId(nextPanel);
|
|
129
|
-
if (this.tabList)
|
|
129
|
+
if (name === "aria-selected" && this.tabList)
|
|
130
130
|
queryWithoutNested("u-tab", this.tabList).forEach((tab) => {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if (prevPanel && prevPanel !== nextPanel) prevPanel.hidden = true;
|
|
134
|
-
if (isUnselect) {
|
|
131
|
+
if (tab !== this && isSelected(tab)) {
|
|
132
|
+
getPanel(tab)?.setAttribute("hidden", "");
|
|
135
133
|
tab.ariaSelected = "false";
|
|
136
134
|
tab.tabIndex = -1;
|
|
137
135
|
}
|
|
138
136
|
});
|
|
139
|
-
if (name === ARIA_CONTROLS
|
|
137
|
+
if (name === ARIA_CONTROLS && prev)
|
|
138
|
+
getPanel(this, prev)?.setAttribute("hidden", "");
|
|
140
139
|
if (this.getAttribute(ARIA_CONTROLS) !== nextPanelId)
|
|
141
140
|
this.setAttribute(ARIA_CONTROLS, nextPanelId);
|
|
142
141
|
this.tabIndex = 0;
|
|
@@ -150,7 +149,7 @@ var UHTMLTabElement = class extends UHTMLElement {
|
|
|
150
149
|
return this.closest("u-tablist");
|
|
151
150
|
}
|
|
152
151
|
get selected() {
|
|
153
|
-
return this
|
|
152
|
+
return isSelected(this);
|
|
154
153
|
}
|
|
155
154
|
set selected(value) {
|
|
156
155
|
this.ariaSelected = `${!!value}`;
|
|
@@ -171,7 +170,7 @@ var UHTMLTabPanelElement = class extends UHTMLElement {
|
|
|
171
170
|
attachStyle(this, DISPLAY_BLOCK);
|
|
172
171
|
}
|
|
173
172
|
connectedCallback() {
|
|
174
|
-
this.hidden =
|
|
173
|
+
this.hidden = getSelectedIndex(this.tabs) === -1;
|
|
175
174
|
this.role = "tabpanel";
|
|
176
175
|
}
|
|
177
176
|
get tabsElement() {
|
|
@@ -187,7 +186,8 @@ var queryWithoutNested = (tag, self) => {
|
|
|
187
186
|
const css = `${tag}:not(:scope ${self.nodeName}:not(:scope) ${tag})`;
|
|
188
187
|
return self.querySelectorAll(css);
|
|
189
188
|
};
|
|
190
|
-
var
|
|
189
|
+
var isSelected = (tab) => tab.ariaSelected === "true";
|
|
190
|
+
var getSelectedIndex = (tabs) => [...tabs].findIndex(isSelected);
|
|
191
191
|
var getPanel = (self, id2) => {
|
|
192
192
|
const css = `u-tabpanel[id="${id2 || self.getAttribute(ARIA_CONTROLS)}"]`;
|
|
193
193
|
const tabsElement = self.closest("u-tabs");
|
package/dist/u-tabs.js
CHANGED
|
@@ -113,28 +113,27 @@ var UHTMLTabElement = class extends UHTMLElement {
|
|
|
113
113
|
);
|
|
114
114
|
}
|
|
115
115
|
connectedCallback() {
|
|
116
|
-
const selected = this.selected || [...queryWithoutNested("u-tab", this.tabList || this)].
|
|
117
|
-
(tab) => tab.ariaSelected !== "true"
|
|
118
|
-
);
|
|
116
|
+
const selected = this.selected || ![...queryWithoutNested("u-tab", this.tabList || this)].some(isSelected);
|
|
119
117
|
this.role = "tab";
|
|
120
118
|
this.tabIndex = selected ? 0 : -1;
|
|
121
119
|
this.ariaSelected = `${selected}`;
|
|
120
|
+
if (!this.hasAttribute(ARIA_CONTROLS))
|
|
121
|
+
this.setAttribute(ARIA_CONTROLS, useId(getPanel(this)));
|
|
122
122
|
}
|
|
123
123
|
attributeChangedCallback(name, prev) {
|
|
124
124
|
if (!this.selected) return;
|
|
125
125
|
const nextPanel = getPanel(this);
|
|
126
126
|
const nextPanelId = useId(nextPanel);
|
|
127
|
-
if (this.tabList)
|
|
127
|
+
if (name === "aria-selected" && this.tabList)
|
|
128
128
|
queryWithoutNested("u-tab", this.tabList).forEach((tab) => {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (prevPanel && prevPanel !== nextPanel) prevPanel.hidden = true;
|
|
132
|
-
if (isUnselect) {
|
|
129
|
+
if (tab !== this && isSelected(tab)) {
|
|
130
|
+
getPanel(tab)?.setAttribute("hidden", "");
|
|
133
131
|
tab.ariaSelected = "false";
|
|
134
132
|
tab.tabIndex = -1;
|
|
135
133
|
}
|
|
136
134
|
});
|
|
137
|
-
if (name === ARIA_CONTROLS
|
|
135
|
+
if (name === ARIA_CONTROLS && prev)
|
|
136
|
+
getPanel(this, prev)?.setAttribute("hidden", "");
|
|
138
137
|
if (this.getAttribute(ARIA_CONTROLS) !== nextPanelId)
|
|
139
138
|
this.setAttribute(ARIA_CONTROLS, nextPanelId);
|
|
140
139
|
this.tabIndex = 0;
|
|
@@ -148,7 +147,7 @@ var UHTMLTabElement = class extends UHTMLElement {
|
|
|
148
147
|
return this.closest("u-tablist");
|
|
149
148
|
}
|
|
150
149
|
get selected() {
|
|
151
|
-
return this
|
|
150
|
+
return isSelected(this);
|
|
152
151
|
}
|
|
153
152
|
set selected(value) {
|
|
154
153
|
this.ariaSelected = `${!!value}`;
|
|
@@ -169,7 +168,7 @@ var UHTMLTabPanelElement = class extends UHTMLElement {
|
|
|
169
168
|
attachStyle(this, DISPLAY_BLOCK);
|
|
170
169
|
}
|
|
171
170
|
connectedCallback() {
|
|
172
|
-
this.hidden =
|
|
171
|
+
this.hidden = getSelectedIndex(this.tabs) === -1;
|
|
173
172
|
this.role = "tabpanel";
|
|
174
173
|
}
|
|
175
174
|
get tabsElement() {
|
|
@@ -185,7 +184,8 @@ var queryWithoutNested = (tag, self) => {
|
|
|
185
184
|
const css = `${tag}:not(:scope ${self.nodeName}:not(:scope) ${tag})`;
|
|
186
185
|
return self.querySelectorAll(css);
|
|
187
186
|
};
|
|
188
|
-
var
|
|
187
|
+
var isSelected = (tab) => tab.ariaSelected === "true";
|
|
188
|
+
var getSelectedIndex = (tabs) => [...tabs].findIndex(isSelected);
|
|
189
189
|
var getPanel = (self, id2) => {
|
|
190
190
|
const css = `u-tabpanel[id="${id2 || self.getAttribute(ARIA_CONTROLS)}"]`;
|
|
191
191
|
const tabsElement = self.closest("u-tabs");
|