fix: menu item click area (#3051)

This commit is contained in:
Peng Xiao
2023-07-06 14:53:50 +08:00
committed by GitHub
parent 8a565b8633
commit fab03006e8
2 changed files with 15 additions and 5 deletions

View File

@@ -44,6 +44,10 @@ export const content = style({
flex: 1, flex: 1,
}); });
export const postfix = style({
justifySelf: 'flex-end',
});
export const icon = style({ export const icon = style({
color: 'var(--affine-icon-color)', color: 'var(--affine-icon-color)',
fontSize: '20px', fontSize: '20px',

View File

@@ -19,6 +19,10 @@ export interface MenuLinkItemProps
extends MenuItemProps, extends MenuItemProps,
Pick<LinkProps, 'href'> {} Pick<LinkProps, 'href'> {}
const stopPropagation: React.MouseEventHandler = e => {
e.stopPropagation();
};
export const MenuItem = React.forwardRef<HTMLDivElement, MenuItemProps>( export const MenuItem = React.forwardRef<HTMLDivElement, MenuItemProps>(
( (
{ {
@@ -44,6 +48,7 @@ export const MenuItem = React.forwardRef<HTMLDivElement, MenuItemProps>(
<div <div
ref={ref} ref={ref}
{...props} {...props}
onClick={onClick}
className={clsx([styles.root, props.className])} className={clsx([styles.root, props.className])}
data-active={active} data-active={active}
data-disabled={disabled} data-disabled={disabled}
@@ -69,15 +74,16 @@ export const MenuItem = React.forwardRef<HTMLDivElement, MenuItemProps>(
)} )}
{React.cloneElement(icon, { {React.cloneElement(icon, {
className: clsx([styles.icon, icon.props.className]), className: clsx([styles.icon, icon.props.className]),
onClick: onClick,
})} })}
</div> </div>
)} )}
<div onClick={onClick} className={styles.content}> <div className={styles.content}>{children}</div>
{children} {postfix ? (
</div> <div className={styles.postfix} onClick={stopPropagation}>
{postfix} {postfix}
</div>
) : null}
</div> </div>
); );
} }