Skip to content

Commit 6b2af5c

Browse files
committed
fix: menu icon
1 parent b8c52b3 commit 6b2af5c

File tree

6 files changed

+33
-19
lines changed

6 files changed

+33
-19
lines changed

components/menu/src/MenuItem.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default defineComponent({
3333
inheritAttrs: false,
3434
props: menuItemProps,
3535
emits: ['mouseenter', 'mouseleave', 'click', 'keydown', 'focus'],
36-
slots: ['icon'],
36+
slots: ['icon', 'title'],
3737
setup(props, { slots, emit, attrs }) {
3838
const instance = getCurrentInstance();
3939
const key = instance.vnode.key;
@@ -149,6 +149,7 @@ export default defineComponent({
149149
};
150150

151151
const renderItemChildren = (icon: any, children: any) => {
152+
const wrapNode = <span class={`${prefixCls.value}-title-content`}>{children}</span>;
152153
// inline-collapsed.md demo 依赖 span 来隐藏文字,有 icon 属性,则内部包裹一个 span
153154
// ref: https://github.com/ant-design/ant-design/pull/23456
154155
if (!icon || (isValidElement(children) && children.type === 'span')) {
@@ -157,16 +158,15 @@ export default defineComponent({
157158
<div class={`${prefixCls.value}-inline-collapsed-noicon`}>{children.charAt(0)}</div>
158159
);
159160
}
160-
return children;
161161
}
162-
return <span class={`${prefixCls.value}-title-content`}>{children}</span>;
162+
return wrapNode;
163163
};
164164

165165
// ========================== DirectionStyle ==========================
166166
const directionStyle = useDirectionStyle(computed(() => keysPath.value.length));
167167

168168
return () => {
169-
const { title } = props;
169+
const title = props.title ?? slots.title?.();
170170
const children = flattenChildren(slots.default?.());
171171
const childrenLength = children.length;
172172
let tooltipTitle: any = title;

components/menu/src/SubMenu.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export default defineComponent({
188188
typeof title === 'string' ? (
189189
<div class={`${prefixCls.value}-inline-collapsed-noicon`}>{title.charAt(0)}</div>
190190
) : (
191-
title
191+
<span class={`${prefixCls.value}-title-content`}>{title}</span>
192192
);
193193
}
194194
// inline-collapsed.md demo 依赖 span 来隐藏文字,有 icon 属性,则内部包裹一个 span
@@ -223,6 +223,10 @@ export default defineComponent({
223223
return res ? getTransitionProps(res.name) : undefined;
224224
});
225225

226+
const subMenuTriggerModeRef = computed(() =>
227+
triggerModeRef.value === 'horizontal' ? 'vertical' : triggerModeRef.value,
228+
);
229+
226230
return () => {
227231
const icon = getPropsSlot(slots, props, 'icon');
228232
const title = renderTitle(getPropsSlot(slots, props, 'title'), icon);
@@ -268,7 +272,7 @@ export default defineComponent({
268272
popup: ({ visible }) => (
269273
<MenuContextProvider
270274
props={{
271-
mode: computed(() => (triggerMode === 'horizontal' ? 'vertical' : triggerMode)),
275+
mode: subMenuTriggerModeRef,
272276
isRootMenu: false,
273277
}}
274278
>

components/menu/style/dark.less

+1-2
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@
8787
> span > a {
8888
color: @menu-dark-highlight-color;
8989
}
90-
> .@{menu-prefix-cls}-submenu-title,
91-
> .@{menu-prefix-cls}-submenu-title:hover {
90+
> .@{menu-prefix-cls}-submenu-title {
9291
> .@{menu-prefix-cls}-submenu-arrow {
9392
opacity: 1;
9493
&::after,

components/menu/style/index.less

+19-9
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,6 @@
211211
+ span {
212212
margin-left: @menu-icon-margin-right;
213213
opacity: 1;
214-
// transition: opacity @animation-duration-slow @ease-in-out,
215-
// width @animation-duration-slow @ease-in-out, color @animation-duration-slow;
216214
transition: opacity @animation-duration-slow @ease-in-out, margin @animation-duration-slow,
217215
color @animation-duration-slow;
218216
}
@@ -365,19 +363,19 @@
365363
&:not(.@{menu-prefix-cls}-dark) {
366364
> .@{menu-prefix-cls}-item,
367365
> .@{menu-prefix-cls}-submenu {
368-
margin: @menu-item-padding;
369366
margin-top: -1px;
370367
margin-bottom: 0;
371368
padding: @menu-item-padding;
372-
padding-right: 0;
373-
padding-left: 0;
374369

375370
&:hover,
376371
&-active,
377372
&-open,
378373
&-selected {
379374
color: @menu-highlight-color;
380-
border-bottom: 2px solid @menu-highlight-color;
375+
376+
&::after {
377+
border-bottom: 2px solid @menu-highlight-color;
378+
}
381379
}
382380
}
383381
}
@@ -388,7 +386,16 @@
388386
top: 1px;
389387
display: inline-block;
390388
vertical-align: bottom;
391-
border-bottom: 2px solid transparent;
389+
390+
&::after {
391+
position: absolute;
392+
right: @menu-item-padding-horizontal;
393+
bottom: 0;
394+
left: @menu-item-padding-horizontal;
395+
border-bottom: 2px solid transparent;
396+
transition: border-color @animation-duration-slow @ease-in-out;
397+
content: '';
398+
}
392399
}
393400

394401
> .@{menu-prefix-cls}-submenu > .@{menu-prefix-cls}-submenu-title {
@@ -535,7 +542,6 @@
535542

536543
.@{menu-prefix-cls}-submenu-arrow {
537544
opacity: 0;
538-
display: none;
539545
}
540546

541547
.@{menu-prefix-cls}-item-icon,
@@ -626,8 +632,12 @@
626632
&-submenu-disabled {
627633
color: @disabled-color !important;
628634
background: none;
629-
border-color: transparent !important;
630635
cursor: not-allowed;
636+
637+
&::after {
638+
border-color: transparent !important;
639+
}
640+
631641
a {
632642
color: @disabled-color !important;
633643
pointer-events: none;

components/style/themes/default.less

+2-1
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,8 @@
512512
@menu-item-vertical-margin: 4px;
513513
@menu-item-font-size: @font-size-base;
514514
@menu-item-boundary-margin: 8px;
515-
@menu-item-padding: 0 20px;
515+
@menu-item-padding-horizontal: 20px;
516+
@menu-item-padding: 0 @menu-item-padding-horizontal;
516517
@menu-horizontal-line-height: 46px;
517518
@menu-icon-margin-right: 10px;
518519
@menu-icon-size: @menu-item-font-size;

0 commit comments

Comments
 (0)