Skip to content

Commit

Permalink
fix(menu): #2618 修改if判断为可选链
Browse files Browse the repository at this point in the history
  • Loading branch information
qiusen committed Oct 16, 2023
1 parent e790773 commit 6a15028
Showing 1 changed file with 12 additions and 39 deletions.
51 changes: 12 additions & 39 deletions packages/ui/menu/src/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,9 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
})}
onClick={() => {
if (isArrayNonEmpty(children)) {
if (!disabled && clickSubMenu) {
clickSubMenu(id)
}
!disabled && clickSubMenu?.(id)
} else {
if (!disabled && clickMenu) {
// @ts-ignore
clickMenu(id, raw)
}
!disabled && clickMenu?.(id, raw as MenuDataItem)
if (
closeAllPopper &&
!(placement === 'vertical' && expandedType === 'collapse' && mini === false)
Expand Down Expand Up @@ -188,9 +183,7 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
gutterGap={16}
className={overlayClassName}
onClose={() => {
if (closePopper) {
closePopper(id)
}
closePopper?.(id)
}}
>
<ul className={`${prefixCls}-popmenu ${prefixCls}--size-${size}`}>
Expand Down Expand Up @@ -218,9 +211,7 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
disabledPortal
className={overlayClassName}
onClose={() => {
if (closePopper) {
closePopper(id)
}
closePopper?.(id)
}}
>
<ul className={`${prefixCls}-popmenu ${prefixCls}--size-${size}`}>
Expand Down Expand Up @@ -251,9 +242,7 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
gutterGap={16}
className={overlayClassName}
onClose={() => {
if (closePopper) {
closePopper(id)
}
closePopper?.(id)
}}
>
<ul className={`${prefixCls}-popmenu ${prefixCls}--size-${size}`}>
Expand All @@ -279,9 +268,7 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
gutterGap={16}
className={overlayClassName}
onClose={() => {
if (closePopper) {
closePopper(id)
}
closePopper?.(id)
}}
>
<ul className={`${prefixCls}-popmenu ${prefixCls}--size-${size}`}>
Expand All @@ -308,9 +295,7 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
gutterGap={16}
className={overlayClassName}
onClose={() => {
if (closePopper) {
closePopper(id)
}
closePopper?.(id)
}}
>
<div className={`${prefixCls}-fat-menu`}>
Expand All @@ -323,10 +308,7 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
{child.children.map((item) => (
<div
onClick={() => {
if(!item.disabled) {
clickMenu && clickMenu(item.id, item)
closePopper && closePopper(id)
}
!item.disabled && (clickMenu?.(item.id, item), closePopper?.(id))
}}
className={cx(`${prefixCls}-item`, {
[`${prefixCls}-item--active`]: activeId === item.id,
Expand Down Expand Up @@ -357,9 +339,7 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
gutterGap={level === 1 ? 8 : 16}
className={overlayClassName}
onClose={() => {
if (closePopper) {
closePopper(id)
}
closePopper?.(id)
}}
>
<ul className={`${prefixCls}-popmenu ${prefixCls}--size-${size}`}>
Expand All @@ -385,9 +365,7 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
gutterGap={level === 1 ? 8 : 16}
className={overlayClassName}
onClose={() => {
if (closePopper) {
closePopper(id)
}
closePopper?.(id)
}}
>
<ul className={`${prefixCls}-popmenu ${prefixCls}--size-${size}`}>
Expand All @@ -414,9 +392,7 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
gutterGap={8}
className={overlayClassName}
onClose={() => {
if (closePopper) {
closePopper(id)
}
closePopper?.(id)
}}
>
<div className={`${prefixCls}-fat-menu`}>
Expand All @@ -433,10 +409,7 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
[`${prefixCls}-item--disabled`]: item.disabled
})}
onClick={() => {
if(!item.disabled) {
clickMenu && clickMenu(item.id, item)
closePopper && closePopper(id)
}
!item.disabled && (clickMenu?.(item.id, item),closePopper?.(id))
}}
key={item.id}
>
Expand Down

0 comments on commit 6a15028

Please sign in to comment.