From 49ef16b5ff1201ba64d213e53e89928b741e05b0 Mon Sep 17 00:00:00 2001 From: afc163 Date: Thu, 19 Oct 2023 10:08:10 +0800 Subject: [PATCH] fix: Table sorter tooltip cannot be open when showSorterTooltip is a object (#45403) --- components/table/__tests__/Table.sorter.test.tsx | 15 +++++++++++++++ components/table/hooks/useSorter.tsx | 7 ++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/components/table/__tests__/Table.sorter.test.tsx b/components/table/__tests__/Table.sorter.test.tsx index 8b4c09211437..e11a613a111a 100644 --- a/components/table/__tests__/Table.sorter.test.tsx +++ b/components/table/__tests__/Table.sorter.test.tsx @@ -321,6 +321,21 @@ describe('Table.sorter', () => { expect(container.querySelector('.ant-tooltip-open')).toBeTruthy(); fireEvent.mouseOut(container.querySelector('.ant-table-column-sorters')!); + // should merge original title into showSorterTooltip object + rerender( + createTable({ + showSorterTooltip: { + overlayClassName: 'custom-tooltip', + }, + }), + ); + fireEvent.mouseEnter(container.querySelector('.ant-table-column-sorters')!); + act(() => { + jest.runAllTimers(); + }); + expect(container.querySelector('.ant-tooltip-open')).toBeTruthy(); + fireEvent.mouseOut(container.querySelector('.ant-table-column-sorters')!); + // Root to false rerender(createTable({ showSorterTooltip: false })); act(() => { diff --git a/components/table/hooks/useSorter.tsx b/components/table/hooks/useSorter.tsx index c2551decd19a..6937c6855c62 100644 --- a/components/table/hooks/useSorter.tsx +++ b/components/table/hooks/useSorter.tsx @@ -168,7 +168,12 @@ function injectSorter( sortTip = triggerAsc; } const tooltipProps: TooltipProps = - typeof showSorterTooltip === 'object' ? showSorterTooltip : { title: sortTip }; + typeof showSorterTooltip === 'object' + ? { + title: sortTip, + ...showSorterTooltip, + } + : { title: sortTip }; newColumn = { ...newColumn, className: classNames(newColumn.className, { [`${prefixCls}-column-sort`]: sortOrder }),