Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: enable ARIA attributes on MenuButton #1893

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions packages/odyssey-react-mui/src/MenuButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,17 @@ import { NullElement } from "./NullElement";

export type MenuButtonProps = {
/**
* aria-label to describe the button when the button label is empty, e.g., an Icon only Button
* The ARIA label for the Button
*/
ariaLabel?: string;
/**
* The ID of the element that labels the Button
*/
ariaLabelledBy?: string;
/**
* The ID of the element that describes the Button
*/
ariaDescribedBy?: string;
/**
* The label on the triggering Button
*/
Expand All @@ -52,10 +60,28 @@ export type MenuButtonProps = {
* The id of the Button
*/
id?: string;
};
} & (
| {
buttonLabel: string;
ariaLabel?: string;
ariaLabelledBy?: string;
}
| {
buttonLabel?: undefined | "";
ariaLabel: string;
ariaLabelledBy?: string;
}
| {
buttonLabel?: undefined | "";
ariaLabel?: string;
ariaLabelledBy: string;
}
);

const MenuButton = ({
ariaLabel,
ariaLabelledBy,
ariaDescribedBy,
buttonLabel = "",
buttonVariant = "secondary",
children,
Expand Down Expand Up @@ -100,6 +126,8 @@ const MenuButton = ({
onClick={openMenu}
text={buttonLabel}
ariaLabel={ariaLabel}
ariaLabelledBy={ariaLabelledBy}
ariaDescribedBy={ariaDescribedBy}
variant={buttonVariant}
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,27 @@ const storybookMeta: Meta<MenuButtonProps> = {
ariaLabel: {
control: "text",
description:
"aria-label to describe the button when the button label is empty",
"aria-label to describe the MenuButton when the button label is empty",
table: {
type: {
summary: "string",
},
},
},
ariaLabelledBy: {
control: "text",
description:
"The ID of the element that labels the MenuButton. Only needed if the button has no text and `ariaLabel` is empty.",
table: {
type: {
summary: "string",
},
},
},
ariaDescribedBy: {
control: "text",
description:
"The ID of the element that describes the MenuButton, if one exists.",
table: {
type: {
summary: "string",
Expand Down Expand Up @@ -130,7 +150,15 @@ export const Simple: StoryObj<MenuButtonProps> = {
<MenuItem key="3">Launch</MenuItem>,
],
},
play: async ({ args, canvasElement, step }) => {
play: async ({
args,
canvasElement,
step,
}: {
args: MenuButtonProps;
canvasElement: HTMLElement;
step: PlaywrightProps<MenuButtonProps>["step"];
}) => {
clickMenuButton({ canvasElement, step })(args, "Menu Button Simple");
},
};
Expand Down Expand Up @@ -158,7 +186,15 @@ export const ActionIcons: StoryObj<MenuButtonProps> = {
</MenuItem>,
],
},
play: async ({ args, canvasElement, step }) => {
play: async ({
args,
canvasElement,
step,
}: {
args: MenuButtonProps;
canvasElement: HTMLElement;
step: PlaywrightProps<MenuButtonProps>["step"];
}) => {
clickMenuButton({ canvasElement, step })(args, "Menu Button Action Icons");
},
};
Expand Down Expand Up @@ -202,7 +238,15 @@ export const WithDestructive: StoryObj<MenuButtonProps> = {
</MenuItem>,
],
},
play: async ({ args, canvasElement, step }) => {
play: async ({
args,
canvasElement,
step,
}: {
args: MenuButtonProps;
canvasElement: HTMLElement;
step: PlaywrightProps<MenuButtonProps>["step"];
}) => {
clickMenuButton({ canvasElement, step })(args, "Menu Button Destructive");
},
};
Expand Down
Loading