Skip to content

Commit

Permalink
fix: 修复手动调用 showTooltip 不展示菜单的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinke666 committed Dec 6, 2024
1 parent 8a55fa6 commit d8afe27
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 27 deletions.
24 changes: 4 additions & 20 deletions packages/s2-react/playground/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ export const S2TooltipOptions: SheetComponentOptions['tooltip'] = {
key: 'custom-a',
label: '操作1',
icon: 'Trend',
visible: (cell) => {
return cell instanceof DataCell;
},
onClick: (info, cell) => {
console.log('操作1点击:', info, cell);
},
Expand All @@ -302,33 +305,14 @@ export const S2TooltipOptions: SheetComponentOptions['tooltip'] = {
key: 'custom-b',
label: '操作2',
icon: 'EyeOutlined',
onClick: (info, cell) => {
console.log('操作2点击:', info, cell);
},
},
{
key: 'custom-c',
label: '操作3',
icon: 'EyeOutlined',
visible: (cell) => {
return cell instanceof DataCell;
},
onClick: (info, cell) => {
console.log('操作3点击:', info, cell);
},
},
{
key: 'custom-d',
label: '操作4',
icon: 'EyeOutlined',
visible: (cell) => {
// 叶子节点才显示
const meta = cell.getMeta();

return meta.isLeaf;
},
onClick: (info, cell) => {
console.log('操作4点击:', info, cell);
console.log('操作2点击:', info, cell);
},
},
],
Expand Down
25 changes: 18 additions & 7 deletions packages/s2-react/src/components/tooltip/custom-tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable import/order */
/* eslint-disable import/no-extraneous-dependencies */
// eslint-disable-next-line prettier/prettier
import { BaseTooltip, isMobile, SpreadSheet } from '@antv/s2';
import { BaseTooltip, customMerge, isMobile, SpreadSheet } from '@antv/s2';
import { omit } from 'lodash';
import React from 'react';
import {
forceClearContent,
Expand Down Expand Up @@ -32,19 +33,29 @@ export class CustomTooltip extends BaseTooltip<

renderContent() {
// 配置级 s2.options.tooltip.content = ''
const { content: contentFromOptions } = this.spreadsheet.options.tooltip!;
const { content: contentFromOptions, operation } =
this.spreadsheet.options.tooltip!;
// 方法级 s2.showTooltip({ content: '' })
const showOptions = this.options;
const cell = this.spreadsheet.getCell(showOptions?.event?.target);
// 优先级: 方法级 > 配置级, 兼容 content 为空字符串的场景
const content = (showOptions?.content ??
contentFromOptions) as React.ReactNode;

const tooltipProps: TooltipRenderProps = {
...showOptions,
cell,
content,
};
const tooltipProps = customMerge<TooltipRenderProps>(
{
options: {
operator: {
menu: omit(operation?.menu, 'items'),
},
},
},
{
...showOptions,
cell,
content,
},
);

if (showOptions?.options?.forceRender) {
this.forceClearContent();
Expand Down

0 comments on commit d8afe27

Please sign in to comment.