Skip to content

Commit a7d639f

Browse files
authored
fix(ContextualMenu): use menuitem role (#1328)
BREAKING CHANGE: If you have any tests that rely on the old role button for this component, change them to look for menuitem role instead.
1 parent 0eaad9a commit a7d639f

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

src/components/ContextualMenu/ContextualMenu.test.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ describe("ContextualMenu ", () => {
137137

138138
it("can display links", () => {
139139
render(<ContextualMenu links={[{ children: "Link1" }]} visible />);
140-
expect(screen.getByRole("button", { name: "Link1" })).toBeInTheDocument();
140+
expect(screen.getByRole("menuitem", { name: "Link1" })).toBeInTheDocument();
141141
});
142142

143143
it("can display links in groups", () => {
@@ -147,7 +147,7 @@ describe("ContextualMenu ", () => {
147147
) as HTMLElement;
148148
expect(group).toBeInTheDocument();
149149
expect(
150-
within(group).getByRole("button", { name: "Link1" }),
150+
within(group).getByRole("menuitem", { name: "Link1" }),
151151
).toBeInTheDocument();
152152
});
153153

@@ -163,12 +163,12 @@ describe("ContextualMenu ", () => {
163163
) as HTMLElement;
164164
expect(group).toBeInTheDocument();
165165
expect(
166-
within(group).getByRole("button", { name: "Link1" }),
166+
within(group).getByRole("menuitem", { name: "Link1" }),
167167
).toBeInTheDocument();
168168
expect(
169-
within(group).queryByRole("button", { name: "Link2" }),
169+
within(group).queryByRole("menuitem", { name: "Link2" }),
170170
).not.toBeInTheDocument();
171-
expect(screen.getByRole("button", { name: "Link2" })).toBeInTheDocument();
171+
expect(screen.getByRole("menuitem", { name: "Link2" })).toBeInTheDocument();
172172
});
173173

174174
it("can supply content instead of links", () => {
@@ -194,7 +194,7 @@ describe("ContextualMenu ", () => {
194194
await userEvent.click(screen.getByRole("button", { name: "Toggle" }));
195195
expect(screen.getByLabelText(DropdownLabel.Dropdown)).toBeInTheDocument();
196196
// Click on an item:
197-
await userEvent.click(screen.getByRole("button", { name: "Link1" }));
197+
await userEvent.click(screen.getByRole("menuitem", { name: "Link1" }));
198198
expect(
199199
screen.queryByLabelText(DropdownLabel.Dropdown),
200200
).not.toBeInTheDocument();

src/components/ContextualMenu/ContextualMenuDropdown/ContextualMenuDropdown.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ const generateLink = <L,>(
145145
<Button<L>
146146
className={classNames("p-contextual-menu__link", className)}
147147
key={key}
148+
role="menuitem"
148149
onClick={
149150
onClick
150151
? (evt) => {

0 commit comments

Comments
 (0)