Skip to content

Commit 34ac33b

Browse files
authored
Add onClick handler for ToggleMenuItem (#324)
1 parent 1b6ff5c commit 34ac33b

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/components/Menu/MenuItem.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ type Props<C extends MenuItemElement> = {
5555
*/
5656
// This prop is required because it's rare to not want a selection handler
5757
onSelect: ((e: Event) => void) | null;
58+
/**
59+
* Event callback for when the item is clicked.
60+
* @param e
61+
*/
62+
onClick?: (e: Event) => void;
5863
/**
5964
* The color variant of the menu item.
6065
* @default primary
@@ -65,7 +70,7 @@ type Props<C extends MenuItemElement> = {
6570
* Whether to hide the chevron navigation hint.
6671
*/
6772
hideChevron?: boolean;
68-
} & Omit<ComponentPropsWithoutRef<C>, "onSelect">;
73+
} & Omit<ComponentPropsWithoutRef<C>, "onSelect" | "onClick">;
6974

7075
/**
7176
* An item within a menu, acting either as a navigation button, or simply a

src/components/Menu/ToggleMenuItem.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { ToggleInput } from "../Form/Controls/Toggle";
1111

1212
type Props = Pick<
1313
ComponentProps<typeof MenuItem>,
14-
"className" | "Icon" | "label" | "onSelect" | "disabled"
14+
"className" | "Icon" | "label" | "onSelect" | "disabled" | "onClick"
1515
> & {
1616
/**
1717
* Whether the toggle is checked.
@@ -25,7 +25,7 @@ type Props = Pick<
2525
*/
2626
export const ToggleMenuItem = forwardRef<HTMLInputElement, Props>(
2727
function ToggleMenuItem(
28-
{ className, Icon, label, onSelect, checked, disabled },
28+
{ className, Icon, label, onSelect, checked, disabled, onClick },
2929
ref,
3030
) {
3131
const toggleId = useId();
@@ -46,6 +46,7 @@ export const ToggleMenuItem = forwardRef<HTMLInputElement, Props>(
4646
label={label}
4747
onSelect={onSelect}
4848
disabled={disabled}
49+
onClick={onClick}
4950
>
5051
<ToggleInput
5152
id={toggleId}

0 commit comments

Comments
 (0)