Skip to content

Commit b35364d

Browse files
fix(a11y-landmark): spread other html props over tabs nav item (#1405)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent 9f02364 commit b35364d

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

src/components/Tabs/Tabs.test.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,24 @@ describe("Tabs", () => {
7676
).toHaveClass("list-item-class");
7777
});
7878

79+
it("forwards aria-label to the navigation element", () => {
80+
render(
81+
<Tabs
82+
aria-label="Section tabs"
83+
links={[
84+
{
85+
href: "/path1",
86+
label: "label1",
87+
},
88+
]}
89+
/>,
90+
);
91+
92+
expect(
93+
screen.getByRole("navigation", { name: "Section tabs" }),
94+
).toHaveAttribute("aria-label", "Section tabs");
95+
});
96+
7997
it("can use custom elements as links", () => {
8098
render(
8199
<Tabs

src/components/Tabs/Tabs.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import classNames from "classnames";
22
import React from "react";
3-
import type { HTMLProps, ElementType, ReactNode, ComponentType } from "react";
3+
import type {
4+
HTMLProps,
5+
ElementType,
6+
ReactNode,
7+
ComponentType,
8+
ComponentPropsWithoutRef,
9+
} from "react";
410

511
import type { ClassName } from "types";
612

@@ -40,7 +46,7 @@ export type Props<P = null> = {
4046
* Optional classes applied to the "ul" element.
4147
*/
4248
listClassName?: string;
43-
};
49+
} & Omit<ComponentPropsWithoutRef<"nav">, "children" | "className">;
4450

4551
/**
4652
* This is the [React](https://reactjs.org/) component for Vanilla [Tabs](https://vanillaframework.io/docs/patterns/tabs).
@@ -51,9 +57,10 @@ const Tabs = <P,>({
5157
className,
5258
links,
5359
listClassName,
60+
...props
5461
}: Props<P>): React.JSX.Element => {
5562
return (
56-
<nav className={classNames("p-tabs", className)}>
63+
<nav className={classNames("p-tabs", className)} {...props}>
5764
<ul role="tablist" className={classNames("p-tabs__list", listClassName)}>
5865
{links.map((link, i) => {
5966
const {

0 commit comments

Comments
 (0)