Skip to content

Commit

Permalink
fix: Table sorter tooltip cannot be open when showSorterTooltip is a …
Browse files Browse the repository at this point in the history
…object (ant-design#45403)
  • Loading branch information
afc163 authored Oct 19, 2023
1 parent 98e3f4a commit 49ef16b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
15 changes: 15 additions & 0 deletions components/table/__tests__/Table.sorter.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
7 changes: 6 additions & 1 deletion components/table/hooks/useSorter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,12 @@ function injectSorter<RecordType>(
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 }),
Expand Down

0 comments on commit 49ef16b

Please sign in to comment.