Compare commits

...

3 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
718c161122 Address code review feedback: improve variable naming and add comment
Co-authored-by: meet-student <59312002+meet-student@users.noreply.github.com>
2026-02-14 03:10:22 +00:00
copilot-swe-agent[bot]
da18ebbd2b Fix Typography.Paragraph tooltip false positive with font metrics
Co-authored-by: meet-student <59312002+meet-student@users.noreply.github.com>
2026-02-14 03:05:08 +00:00
copilot-swe-agent[bot]
a5d62db058 Initial plan 2026-02-14 02:57:48 +00:00
2 changed files with 36 additions and 1 deletions

View File

@@ -21,6 +21,12 @@ export function getNode(dom: React.ReactNode, defaultNode: React.ReactNode, need
export function isEleEllipsis(ele: HTMLElement): boolean {
// Create a new div to get the size
const childDiv = document.createElement('em');
// Set styles to prevent the child element from affecting layout measurements
// line-height: 0 prevents font metrics from causing false positives
childDiv.style.lineHeight = '0';
childDiv.style.verticalAlign = 'top';
ele.appendChild(childDiv);
// For test case

View File

@@ -387,10 +387,16 @@ describe('Typography.Ellipsis', () => {
'ant-typography-css-ellipsis-content-measure',
)
) {
// Check if line-height is set to 0 (from the fix)
const element = this as unknown as HTMLElement;
const lineHeight = element.style.lineHeight;
// 22 is the default LINE_HEIGHT used in the test setup
const height = lineHeight === '0' ? 0 : 22;
return {
...measureRect,
right: measureRect.left,
bottom: measureRect.top + 22,
bottom: measureRect.top + height,
};
}
@@ -502,6 +508,29 @@ describe('Typography.Ellipsis', () => {
expect(baseElement.querySelector('.ant-tooltip-open')).toBeFalsy();
});
// Fix for font metric issue where em element height differs from container
it('should not show tooltip when em height differs due to font metrics', async () => {
// Simulate scenario where:
// - Container and measure have same horizontal bounds (no horizontal overflow)
// - Without fix: em element height would be 20px, container is 18px
// - With fix: em element height is 0px (line-height: 0)
containerRect.right = 100;
containerRect.bottom = 18;
measureRect.left = 0;
measureRect.top = 0;
const { container, baseElement } = await getWrapper({
title: true,
});
fireEvent.mouseEnter(container.firstChild!);
await waitFakeTimer();
// With the fix, tooltip should not show because text is not actually ellipsed
// The em element now has line-height: 0, so its height won't exceed container height
expect(baseElement.querySelector('.ant-tooltip-open')).toBeFalsy();
});
});
});