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

Hotfix/menu(#2618) #2620

Merged
merged 7 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
28 changes: 13 additions & 15 deletions packages/ui/menu/src/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
})}
onClick={() => {
if (isArrayNonEmpty(children)) {
if (clickSubMenu) {
if (!disabled && clickSubMenu) {
clickSubMenu(id)
}
} else {
if (clickMenu) {
if (!disabled && clickMenu) {
// @ts-ignore
clickMenu(id, raw)
}
Expand All @@ -121,7 +121,7 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
placement === 'vertical' &&
expandedType === 'collapse' &&
!showAllSubMenus &&
(expandedIds?.includes(id) ? (
(!disabled && expandedIds?.includes(id) ? (
<Arrow prefixCls={`${prefixCls}-item`} direction="up" />
) : (
<Arrow prefixCls={`${prefixCls}-item`} direction="down" />
Expand All @@ -144,7 +144,7 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
{hasChildren &&
placement === 'horizontal' &&
level === 1 &&
(expandedIds?.includes(id) ? (
(!disabled && expandedIds?.includes(id) ? (
<Arrow prefixCls={`${prefixCls}-item`} direction="up" />
) : (
<Arrow prefixCls={`${prefixCls}-item`} direction="down" />
Expand All @@ -156,7 +156,7 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
!mini &&
!showAllSubMenus &&
expandedType === 'collapse' ? (
<Expander visible={!!expandedIds?.includes(id)}>
<Expander visible={!disabled && !!expandedIds?.includes(id)}>
<ul className={`${prefixCls}-submenu`}>
{children!.map((child) => (
<MenuItem
Expand Down Expand Up @@ -323,15 +323,14 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
{child.children.map((item) => (
<div
onClick={() => {
if (clickMenu) {
clickMenu(item.id, item)
}
if (closePopper) {
closePopper(id)
if(!item.disabled) {
clickMenu && clickMenu(item.id, item)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这2行代码建议使用可选链,代码更简洁

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

closePopper && closePopper(id)
}
}}
className={cx(`${prefixCls}-item`, {
[`${prefixCls}-item--active`]: activeId === item.id,
[`${prefixCls}-item--disabled`]: item.disabled
})}
key={item.id}
>
Expand Down Expand Up @@ -431,13 +430,12 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
<div
className={cx(`${prefixCls}-item`, {
[`${prefixCls}-item--active`]: activeId === item.id,
[`${prefixCls}-item--disabled`]: item.disabled
})}
onClick={() => {
if (clickMenu) {
clickMenu(item.id, item)
}
if (closePopper) {
closePopper(id)
if(!item.disabled) {
clickMenu && clickMenu(item.id, item)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

closePopper && closePopper(id)
}
}}
key={item.id}
Expand Down
34 changes: 34 additions & 0 deletions packages/ui/menu/src/styles/menu.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
@import '~@hi-ui/core-css/lib/index.scss';

$prefix: '#{$component-prefix}-menu' !default;
$disabled-color: var(--hi-v4-color-gray-400, #c9ced6) !default;

@mixin menu-item-disabled() {
color: $disabled-color;
cursor: not-allowed;
}

.#{$prefix}-fat-menu {
background-color: use-color-static('white');
Expand Down Expand Up @@ -41,6 +47,10 @@ $prefix: '#{$component-prefix}-menu' !default;
&:not(.#{$prefix}-item--active):hover {
background-color: use-color('gray', 100);
}

&--disabled {
@include menu-item-disabled;
}
}

ul {
Expand Down Expand Up @@ -92,6 +102,10 @@ $prefix: '#{$component-prefix}-menu' !default;
&:not(.#{$prefix}-item__inner--active):hover {
background-color: use-color('gray', 100);
}

&--disabled {
@include menu-item-disabled;
}
}

&__content {
Expand Down Expand Up @@ -143,6 +157,10 @@ $prefix: '#{$component-prefix}-menu' !default;
height: 100%;
flex-shrink: 0;
}

&--disabled {
@include menu-item-disabled;
}
}

&__wrapper {
Expand Down Expand Up @@ -220,6 +238,18 @@ $prefix: '#{$component-prefix}-menu' !default;
white-space: nowrap;
max-width: none;
}

&--disabled {
@include menu-item-disabled;

.#{$prefix}-item__inner.#{$prefix}-item__inner {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2个类选择器名字一样,是否多余

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是为了增加权限,否则样式无法复写

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议可以按照非禁用状态下的样式结构进行覆写,更利于代码阅读,例如:
&--disabled {
&:hover {
.#{$prefix}-item__inner {
border-bottom: none;
}
}
}

border-bottom: 0;

.#{$prefix}-item__content {
color: $disabled-color;
}
}
}
}
}

Expand Down Expand Up @@ -309,6 +339,10 @@ $prefix: '#{$component-prefix}-menu' !default;
white-space: nowrap;
text-indent: 0.5px;
}

&--disabled {
@include menu-item-disabled;
}
}
}

Expand Down