Skip to content

Commit 07c0045

Browse files
authored
fix(uui-tab-group): Unable to remove tab (#753)
* add story * make sure to clean up the breakpoints array to prevent index overflows
1 parent a90a510 commit 07c0045

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

packages/uui-tabs/lib/uui-tab-group.element.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export class UUITabGroupElement extends LitElement {
102102
this.#tabResizeObservers.forEach(observer => observer.disconnect());
103103
});
104104
this.#tabResizeObservers.length = 0;
105+
this.#visibilityBreakpoints.length = 0;
105106
}
106107

107108
#onSlotChange() {

packages/uui-tabs/lib/uui-tabs.story.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,68 @@ Async.parameters = {
291291
},
292292
};
293293

294+
export const Dynamic: Story = props => {
295+
const addTab = () => {
296+
const tabGroup = document.querySelector('uui-tab-group');
297+
if (!tabGroup) return;
298+
299+
const tab = document.createElement('uui-tab');
300+
const nameWithRandomLength = Math.random().toString(36).substring(7);
301+
tab.label = nameWithRandomLength;
302+
tab.innerHTML = nameWithRandomLength;
303+
tabGroup.appendChild(tab);
304+
};
305+
306+
const removeRandomTab = () => {
307+
const tabGroup = document.querySelector('uui-tab-group');
308+
if (!tabGroup) return;
309+
310+
const tabs = tabGroup.querySelectorAll('uui-tab');
311+
if (tabs.length > 0) {
312+
const randomIndex = Math.floor(Math.random() * tabs.length);
313+
tabGroup.removeChild(tabs[randomIndex]);
314+
}
315+
};
316+
317+
return html`
318+
<uui-icon-registry-essential>
319+
<div style="display: flex">
320+
<uui-tab-group
321+
dropdown-direction="vertical"
322+
style="
323+
margin: auto;
324+
--uui-tab-group-gap: 25px;
325+
font-size: var(--uui-type-small-size);
326+
${props.inlineStyles}">
327+
</uui-tab-group>
328+
</div>
329+
<uui-button @click=${addTab}>Add tab</uui-button>
330+
<uui-button @click=${removeRandomTab}>Remove tab</uui-button>
331+
</uui-icon-registry-essential>
332+
`;
333+
};
334+
Dynamic.parameters = {
335+
docs: {
336+
source: {
337+
code: `
338+
<uui-tab-group>
339+
<uui-tab>
340+
<uui-icon slot="icon" name="document"></uui-icon>
341+
Content
342+
</uui-tab>
343+
<uui-tab active>
344+
<uui-icon slot="icon" name="settings"></uui-icon>
345+
Packages
346+
</uui-tab>
347+
<uui-tab>
348+
<uui-icon slot="icon" name="picture"></uui-icon>
349+
Media
350+
</uui-tab>
351+
</uui-tab-group>`,
352+
},
353+
},
354+
};
355+
294356
export const FlexLayout: Story = props => html`
295357
<uui-icon-registry-essential>
296358
<div style="display: flex;">

0 commit comments

Comments
 (0)