Skip to content

Commit bcfe278

Browse files
chore(tabs): use getRandomId to generate ids for tabs/tabitems
1 parent 5fb3038 commit bcfe278

File tree

3 files changed

+4
-10
lines changed

3 files changed

+4
-10
lines changed

components/tabs/stories/tabs.stories.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,15 @@ export default {
9393
useAnchors: false,
9494
content: [
9595
{
96-
id: "tab-1",
9796
label: "Tab 1",
9897
icon: "Folder",
9998
isSelected: true,
10099
},
101100
{
102-
id: "tab-2",
103101
label: "Tab 2",
104102
icon: "Image",
105103
},
106104
{
107-
id: "tab-3",
108105
label: "Tab 3",
109106
icon: "Document",
110107
isDisabled: true,
@@ -215,19 +212,16 @@ export const Disabled = Template.bind({});
215212
Disabled.args = {
216213
content: [
217214
{
218-
id: "tab-1",
219215
label: "Selected tab",
220216
icon: "Folder",
221217
isSelected: true,
222218
},
223219
{
224-
id: "tab-2",
225220
label: "Disabled tab",
226221
icon: "Image",
227222
isDisabled: true,
228223
},
229224
{
230-
id: "tab-3",
231225
label: "Tab 3",
232226
icon: "Document",
233227
},

components/tabs/stories/tabs.test.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@ import { Template } from "./template.js";
33

44
const ExampleLabelOnlyTabContent = [
55
{
6-
id: "tab-1",
76
label: "Selected",
87
isSelected: true,
98
},
109
{
11-
id: "tab-2",
1210
label: "Disabled",
1311
isDisabled: true,
1412
},
1513
{
16-
id: "tab-3",
1714
label: "Tab 3",
1815
},
1916
];

components/tabs/stories/template.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Container } from "@spectrum-css/preview/decorators";
1+
import { getRandomId, Container } from "@spectrum-css/preview/decorators";
22
import { Template as Icon } from "@spectrum-css/icon/stories/template.js";
33
import { Template as Menu } from "@spectrum-css/menu/stories/template.js";
44
import { Template as Picker } from "@spectrum-css/picker/stories/template.js";
@@ -23,6 +23,7 @@ export const Template = ({
2323
iconOnly = false,
2424
hasRightAlignedTabs = false,
2525
useAnchors = false,
26+
id = getRandomId("tabs"),
2627
customStyles = {},
2728
content = [],
2829
} = {}, context = {}) => {
@@ -71,6 +72,7 @@ export const Template = ({
7172
...customClasses.reduce((a, c) => ({ ...a, [c]: true }), {}),
7273
})}
7374
style=${styleMap(customStyles)}
75+
id=${ifDefined(id)}
7476
>
7577
${when(!isOverflow, () => repeat(
7678
content,
@@ -85,6 +87,7 @@ export const Template = ({
8587
"is-disabled": item?.isDisabled ?? false,
8688
})}
8789
tabindex="0"
90+
id=${getRandomId("tab-item")}
8891
>
8992
${when(item.icon, () =>
9093
Icon({

0 commit comments

Comments
 (0)