diff --git a/packages/f2/src/components/tooltip/tooltipView.tsx b/packages/f2/src/components/tooltip/tooltipView.tsx index 1d67235e7..753017d98 100644 --- a/packages/f2/src/components/tooltip/tooltipView.tsx +++ b/packages/f2/src/components/tooltip/tooltipView.tsx @@ -218,7 +218,7 @@ const RenderXTip = (props) => { xPositionType === 'coord' ? coordData.xText : isFunction(xTip) - ? xTip(xFirstText) + ? xTip(xFirstText, firstRecord) : xFirstText, }} /> @@ -250,7 +250,7 @@ const RenderYTip = (props) => { yPositionType === 'coord' ? coordData.yText : isFunction(yTip) - ? yTip(yFirstText) + ? yTip(yFirstText, firstRecord) : yFirstText, }} /> diff --git a/packages/f2/src/components/tooltip/withTooltip.tsx b/packages/f2/src/components/tooltip/withTooltip.tsx index 440523512..46249bc91 100644 --- a/packages/f2/src/components/tooltip/withTooltip.tsx +++ b/packages/f2/src/components/tooltip/withTooltip.tsx @@ -84,6 +84,7 @@ export interface TooltipProps { showTooltipMarker?: boolean; customText?: any; markerBackgroundStyle?: any; + [key: string]: any; } export interface TooltipState { diff --git a/packages/f2/test/components/tooltip/tooltip.test.tsx b/packages/f2/test/components/tooltip/tooltip.test.tsx index 5db6215da..ffc8c3514 100644 --- a/packages/f2/test/components/tooltip/tooltip.test.tsx +++ b/packages/f2/test/components/tooltip/tooltip.test.tsx @@ -403,6 +403,8 @@ describe('tooltip', () => { }); it('Tooltip-xTip-yTip相关配置', async () => { + const xTipFn = jest.fn(); + const yTipFn = jest.fn(); const context = createContext('Tooltip xTip yTip相关配置'); const { props } = ( @@ -448,6 +450,14 @@ describe('tooltip', () => { fill: 'red', text: '', }} + xTip={(text, record) => { + xTipFn(text, record); + return text; + }} + yTip={(text, record) => { + yTipFn(text, record); + return text; + }} /> @@ -460,6 +470,10 @@ describe('tooltip', () => { await delay(100); expect(context).toMatchImageSnapshot(); + expect(xTipFn.mock.calls.length).toBe(1); + expect(yTipFn.mock.calls.length).toBe(1); + expect(xTipFn.mock.calls[0][1]).toBeDefined(); + expect(yTipFn.mock.calls[0][1]).toBeDefined(); }); it('Tooltip 自动换行', async () => {