Skip to content

Commit b75e102

Browse files
fix(tabs): address a11y issues
1 parent 1f1d1d4 commit b75e102

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

src/Tabs/Tab.svelte

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
<!-- svelte-ignore a11y-mouse-events-have-key-events -->
3333
<li
3434
tabindex="-1"
35-
role="presentation"
35+
role="tab"
36+
aria-selected={selected}
37+
aria-disabled={disabled}
3638
class:bx--tabs__nav-item={true}
3739
class:bx--tabs__nav-item--disabled={disabled}
3840
class:bx--tabs__nav-item--selected={selected}
@@ -60,10 +62,7 @@
6062
>
6163
<a
6264
bind:this={ref}
63-
role="tab"
6465
tabindex={disabled ? "-1" : tabindex}
65-
aria-selected={selected}
66-
aria-disabled={disabled}
6766
{id}
6867
{href}
6968
class:bx--tabs__nav-link={true}

tests/Tabs/Tabs.test.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,12 @@ describe("Tab", () => {
136136

137137
const tab = screen.getByRole("tab", { name: "Test Tab" });
138138
expect(tab).toBeInTheDocument();
139-
expect(tab).toHaveAttribute("href", "#test");
140-
expect(tab).toHaveAttribute("tabindex", "0");
141-
expect(tab).toHaveAttribute("id", "test-tab");
139+
expect(tab).toHaveAttribute("aria-selected", "true");
140+
141+
const link = tab.querySelector("a");
142+
expect(link).toHaveAttribute("href", "#test");
143+
expect(link).toHaveAttribute("tabindex", "0");
144+
expect(link).toHaveAttribute("id", "test-tab");
142145
});
143146

144147
it("should render with custom label", () => {
@@ -153,29 +156,34 @@ describe("Tab", () => {
153156
render(Tab, { props: { href: "/custom" } });
154157

155158
const tab = screen.getByRole("tab");
156-
expect(tab).toHaveAttribute("href", "/custom");
159+
const link = tab.querySelector("a");
160+
expect(link).toHaveAttribute("href", "/custom");
157161
});
158162

159163
it("should handle disabled state", () => {
160164
render(Tab, { props: { disabled: true } });
161165

162166
const tab = screen.getByRole("tab");
163167
expect(tab).toHaveAttribute("aria-disabled", "true");
164-
expect(tab).toHaveAttribute("tabindex", "-1");
168+
169+
const link = tab.querySelector("a");
170+
expect(link).toHaveAttribute("tabindex", "-1");
165171
});
166172

167173
it("should handle custom tabindex", () => {
168174
render(Tab, { props: { tabindex: "1" } });
169175

170176
const tab = screen.getByRole("tab");
171-
expect(tab).toHaveAttribute("tabindex", "1");
177+
const link = tab.querySelector("a");
178+
expect(link).toHaveAttribute("tabindex", "1");
172179
});
173180

174181
it("should handle custom id", () => {
175182
render(Tab, { props: { id: "custom-id" } });
176183

177184
const tab = screen.getByRole("tab");
178-
expect(tab).toHaveAttribute("id", "custom-id");
185+
const link = tab.querySelector("a");
186+
expect(link).toHaveAttribute("id", "custom-id");
179187
});
180188

181189
it("should be clickable when enabled", async () => {

0 commit comments

Comments
 (0)