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

fix(menu): 修复 mini 模式下子菜单内容展示不全问题 (#2656) #2659

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/thick-news-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/hiui": patch
---

Menu fix: 修复 mini 模式下子菜单内容展示不全问题
5 changes: 5 additions & 0 deletions .changeset/wet-snails-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/menu": patch
---

fix: 修复 mini 模式下子菜单内容展示不全问题
24 changes: 15 additions & 9 deletions packages/ui/menu/src/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,18 @@ export const Menu = forwardRef<HTMLDivElement | null, MenuProps>(
)
}

const renderItem = useCallback(
(menuItem: MenuDataItem, level?: number) => {
// 显示缩略内容
if (showMini && level === 1) {
return renderMenuItemMini(menuItem)
}

return isFunction(render) ? render(menuItem, level) : menuItem.title
},
[render, showMini]
)

const cls = cx(
prefixCls,
className,
Expand Down Expand Up @@ -260,19 +272,13 @@ export const Menu = forwardRef<HTMLDivElement | null, MenuProps>(
{mergedTagList.map((item, index) => {
return showMini ? (
<Tooltip title={item.title} key={item.id} placement="right">
<MenuItem
{...item}
level={1}
render={renderMenuItemMini}
raw={item}
size={size}
/>
<MenuItem {...item} level={1} render={renderItem} raw={item} size={size} />
</Tooltip>
) : (
<MenuItem
hidden={!showVertical && index >= tagMaxCount}
{...item}
render={render}
render={renderItem}
key={item.id}
level={1}
raw={item}
Expand Down Expand Up @@ -372,7 +378,7 @@ export interface MenuProps extends Omit<HiBaseHTMLProps<'div'>, 'onClick'> {
/**
* 自定义渲染菜单项
*/
render?: (menuItem: MenuDataItem) => React.ReactNode
render?: (menuItem: MenuDataItem, level?: number) => React.ReactNode
/**
* 额外的头部内容
*/
Expand Down
8 changes: 4 additions & 4 deletions packages/ui/menu/src/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(

{icon ? <span className={`${prefixCls}-item__icon`}>{icon}</span> : null}
<span className={`${prefixCls}-item__content`}>
{isFunction(render) ? render({ id, icon, title }) : title}
{isFunction(render) ? render({ id, icon, title }, level) : title}
</span>
{/* 垂直菜单-纵向展开 */}
{hasChildren &&
Expand Down Expand Up @@ -315,7 +315,7 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
}}
className={cx(`${prefixCls}-item`, {
[`${prefixCls}-item--active`]: activeId === item.id,
[`${prefixCls}-item--disabled`]: item.disabled
[`${prefixCls}-item--disabled`]: item.disabled,
})}
key={item.id}
>
Expand Down Expand Up @@ -409,7 +409,7 @@ export const MenuItem = forwardRef<HTMLLIElement | null, MenuItemProps>(
<div
className={cx(`${prefixCls}-item`, {
[`${prefixCls}-item--active`]: activeId === item.id,
[`${prefixCls}-item--disabled`]: item.disabled
[`${prefixCls}-item--disabled`]: item.disabled,
})}
onClick={() => {
if (!item.disabled) {
Expand Down Expand Up @@ -443,7 +443,7 @@ export interface MenuItemProps extends Omit<HiBaseHTMLProps<'li'>, 'id'> {
children?: MenuDataItem[]
level?: number
parentIds?: React.ReactText[]
render?: (node: MenuDataItem) => React.ReactNode
render?: (node: MenuDataItem, level?: number) => React.ReactNode
raw?: MenuDataItem
size?: HiBaseSizeEnum
}
Expand Down