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

feat: support show tooltip when menu collapsed #2921

Merged
merged 4 commits into from
May 31, 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
10 changes: 5 additions & 5 deletions src/menu/__tests__/__snapshots__/menu-item.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exports[`MenuItem > props > :disabled 1`] = `
>
<!---->
<ul
class="t-menu t-menu--scroll narrow-scrollbar"
class="t-menu t-menu--scroll"
>

<li
Expand Down Expand Up @@ -40,7 +40,7 @@ exports[`MenuItem > props > :name 1`] = `
>
<!---->
<ul
class="t-menu t-menu--scroll narrow-scrollbar"
class="t-menu t-menu--scroll"
>

<li
Expand Down Expand Up @@ -71,7 +71,7 @@ exports[`MenuItem > props > :route 1`] = `
>
<!---->
<ul
class="t-menu t-menu--scroll narrow-scrollbar"
class="t-menu t-menu--scroll"
>

<li
Expand Down Expand Up @@ -102,7 +102,7 @@ exports[`MenuItem > slot > <default> 1`] = `
>
<!---->
<ul
class="t-menu t-menu--scroll narrow-scrollbar"
class="t-menu t-menu--scroll"
>

<li
Expand Down Expand Up @@ -132,7 +132,7 @@ exports[`MenuItem > slot > <icon> 1`] = `
>
<!---->
<ul
class="t-menu t-menu--scroll narrow-scrollbar"
class="t-menu t-menu--scroll"
>

<li
Expand Down
20 changes: 10 additions & 10 deletions src/menu/__tests__/__snapshots__/menu.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exports[`Menu > props > :active 1`] = `
>
<!---->
<ul
class="t-menu t-menu--scroll narrow-scrollbar"
class="t-menu t-menu--scroll"
>
<!---->
</ul>
Expand All @@ -29,7 +29,7 @@ exports[`Menu > props > :collapsed 1`] = `
>
<!---->
<ul
class="t-menu narrow-scrollbar"
class="t-menu t-menu--scroll"
>
<!---->
</ul>
Expand All @@ -49,7 +49,7 @@ exports[`Menu > props > :collapsedWidth 1`] = `
>
<!---->
<ul
class="t-menu t-menu--scroll narrow-scrollbar"
class="t-menu t-menu--scroll"
>
<!---->
</ul>
Expand All @@ -69,7 +69,7 @@ exports[`Menu > props > :height 1`] = `
>
<!---->
<ul
class="t-menu t-menu--scroll narrow-scrollbar"
class="t-menu t-menu--scroll"
>
<!---->
</ul>
Expand All @@ -88,7 +88,7 @@ exports[`Menu > props > :theme 1`] = `
>
<!---->
<ul
class="t-menu t-menu--scroll narrow-scrollbar"
class="t-menu t-menu--scroll"
>
<!---->
</ul>
Expand All @@ -107,7 +107,7 @@ exports[`Menu > props > :theme 2`] = `
>
<!---->
<ul
class="t-menu t-menu--scroll narrow-scrollbar"
class="t-menu t-menu--scroll"
>
<!---->
</ul>
Expand All @@ -126,7 +126,7 @@ exports[`Menu > props > :width 1`] = `
>
<!---->
<ul
class="t-menu t-menu--scroll narrow-scrollbar"
class="t-menu t-menu--scroll"
>
<!---->
</ul>
Expand All @@ -145,7 +145,7 @@ exports[`Menu > slot > <default> 1`] = `
>
<!---->
<ul
class="t-menu t-menu--scroll narrow-scrollbar"
class="t-menu t-menu--scroll"
>

<div />
Expand All @@ -172,7 +172,7 @@ exports[`Menu > slot > <logo> 1`] = `

</div>
<ul
class="t-menu t-menu--scroll narrow-scrollbar"
class="t-menu t-menu--scroll"
>
<!---->
</ul>
Expand All @@ -191,7 +191,7 @@ exports[`Menu > slot > <operations> 1`] = `
>
<!---->
<ul
class="t-menu t-menu--scroll narrow-scrollbar"
class="t-menu t-menu--scroll"
>
<!---->
</ul>
Expand Down
1 change: 1 addition & 0 deletions src/menu/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface TdMenuInterface {
theme?: Ref<string>;
isHead: boolean;
vMenu?: VMenu;
collapsed?: Ref<boolean>;
select: (val: MenuValue) => void;
open?: (val: MenuValue, type?: TdOpenType) => boolean | void;
}
Expand Down
19 changes: 17 additions & 2 deletions src/menu/menu-item.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { defineComponent, computed, inject, onMounted, ref, toRefs } from 'vue';
import { defineComponent, computed, inject, onMounted, ref, toRefs, getCurrentInstance } from 'vue';
import props from './menu-item-props';
import { TdMenuInterface, TdSubMenuInterface } from './const';
import { renderContent, renderTNodeJSX } from '../utils/render-tnode';
import { emitEvent } from '../utils/event';
import useRipple from '../hooks/useRipple';
import { usePrefixClass } from '../hooks/useConfig';
import Tooltip from '../tooltip';

export default defineComponent({
name: 'TMenuItem',
Expand All @@ -18,6 +19,7 @@ export default defineComponent({
useRipple(itemRef);
const submenu = inject<TdSubMenuInterface>('TdSubmenu', null);
const active = computed(() => menu.activeValue.value === props.value);
const collapsed = computed(() => menu.collapsed?.value);
const classes = computed(() => [
`${classPrefix.value}-menu__item`,
{
Expand All @@ -37,6 +39,7 @@ export default defineComponent({
classPrefix,
menu,
active,
collapsed,
classes,
itemRef,
href,
Expand Down Expand Up @@ -67,7 +70,7 @@ export default defineComponent({
},
},
render() {
return (
const liContent = (
<li ref="itemRef" class={this.classes} onClick={this.handleClick}>
{renderTNodeJSX(this, 'icon')}
{this.href ? (
Expand All @@ -79,5 +82,17 @@ export default defineComponent({
)}
</li>
);

const instance = getCurrentInstance();
const node = instance.parent;
// 菜单收起,且只有本身为一级菜单才需要显示 tooltip
if (this.collapsed && /tmenu/i.test(node?.type.name)) {
return (
<Tooltip content={() => renderContent(this, 'default', 'content')} placement="right">
{liContent}
</Tooltip>
);
}
return liContent;
},
});
8 changes: 3 additions & 5 deletions src/menu/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,15 @@ export default defineComponent({
const mode = ref(props.expandType);
const theme = computed(() => props.theme);
const isMutex = computed(() => props.expandMutex);
const collapsed = computed(() => props.collapsed);
const menuClass = computed(() => [
`${classPrefix.value}-default-menu`,
`${classPrefix.value}-menu--${props.theme}`,
{
[`${classPrefix.value}-is-collapsed`]: props.collapsed,
},
]);
const innerClasses = computed(() => [
`${classPrefix.value}-menu`,
{ [`${classPrefix.value}-menu--scroll`]: mode.value !== 'popup' },
'narrow-scrollbar',
]);
const innerClasses = computed(() => [`${classPrefix.value}-menu`, `${classPrefix.value}-menu--scroll`]);
const expandWidth = computed(() => {
const { width } = props;
const format = (val: string | number) => (isNumber(val) ? `${val}px` : val);
Expand Down Expand Up @@ -68,6 +65,7 @@ export default defineComponent({
theme,
isHead: false,
vMenu,
collapsed,
select: (value: MenuValue) => {
setActiveValue(value);
},
Expand Down
5 changes: 1 addition & 4 deletions src/menu/submenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export default defineComponent({
{
[`${classPrefix.value}-is-opened`]: popupVisible.value,
},
'narrow-scrollbar',
]);
const submenuClass = computed(() => [
`${classPrefix.value}-menu__item`,
Expand Down Expand Up @@ -240,9 +239,7 @@ export default defineComponent({
onMouseenter={this.handleEnterPopup}
onMouseleave={this.handleMouseLeavePopup}
>
<ul class={`${this.classPrefix}-menu__popup-wrapper narrow-scrollbar`}>
{renderContent(this, 'default', 'content')}
</ul>
<ul class={`${this.classPrefix}-menu__popup-wrapper`}>{renderContent(this, 'default', 'content')}</ul>
</div>
);
const slots = {
Expand Down
Loading