Skip to content

Commit f0b16bd

Browse files
committed
fix(MenuItem): Change div to button
1 parent 6c8f99e commit f0b16bd

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

src/components/MenuItem.tsx

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,22 @@
1-
import { ReactNode, useState, useCallback } from 'react';
1+
import { useState, useCallback, ButtonHTMLAttributes } from 'react';
22
import cx from 'clsx';
33

4-
export interface MenuItemProps {
5-
/**
6-
* Function to call when the item is clicked. Includes the click event.
7-
*/
8-
onClick?: (event: React.MouseEvent<HTMLElement>) => void;
9-
/**
10-
* Whether the item is disabled.
11-
*
12-
* Default: `false`
13-
*/
14-
disabled?: boolean;
15-
className?: string;
16-
children: ReactNode;
17-
}
4+
export interface MenuItemProps extends ButtonHTMLAttributes<HTMLButtonElement> {}
185

196
export interface MenuItemExternalProps {
207
hide: () => void;
218
}
229

2310
interface MenuItemState {
2411
clicked: boolean;
25-
eventRef: React.MouseEvent<HTMLElement> | null;
12+
eventRef: React.MouseEvent<HTMLButtonElement> | null;
2613
}
2714

2815
const MenuItem = ({ children, onClick, className, disabled = false, ...rest }: MenuItemProps) => {
2916
const [state, setState] = useState<MenuItemState>({ clicked: false, eventRef: null });
3017

3118
const handleClick = useCallback(
32-
(event: React.MouseEvent<HTMLElement>) => {
19+
(event: React.MouseEvent<HTMLButtonElement>) => {
3320
event.stopPropagation();
3421

3522
if (!disabled && onClick) {
@@ -57,7 +44,7 @@ const MenuItem = ({ children, onClick, className, disabled = false, ...rest }: M
5744
});
5845

5946
return (
60-
<div
47+
<button
6148
onClick={handleClick}
6249
onAnimationEnd={handleAnimationEnd}
6350
className={classNames}
@@ -66,7 +53,7 @@ const MenuItem = ({ children, onClick, className, disabled = false, ...rest }: M
6653
tabIndex={-1}
6754
>
6855
{children}
69-
</div>
56+
</button>
7057
);
7158
};
7259

src/styles.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,16 @@
105105
}
106106

107107
.react-context-menu__item {
108+
display: flex;
109+
width: 100%;
110+
108111
color: var(--react-context-menu-item-color);
109112
padding: var(--react-context-menu-padding-sm) var(--react-context-menu-padding-md);
110113

111114
line-height: 1;
112115
font-size: var(--react-context-menu-font-size);
113116
border-radius: var(--react-context-menu-border-radius-inner);
117+
border: none;
114118

115119
user-select: none;
116120
-webkit-user-select: none;

0 commit comments

Comments
 (0)