mirror of
https://github.com/ant-design/ant-design.git
synced 2026-02-16 06:12:28 +08:00
Compare commits
3 Commits
master
...
copilot/fi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
718c161122 | ||
|
|
da18ebbd2b | ||
|
|
a5d62db058 |
@@ -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
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user