From e0150db5b60d0951eecbe1dd9ada4df006cd8956 Mon Sep 17 00:00:00 2001 From: "hankin.dream" Date: Fri, 2 Dec 2022 13:13:43 +0800 Subject: [PATCH] fix(components): [table]fix the problem that show-overflow-tooltip will also be displayed when the browser is zoomed (#10816) closed https://github.com/element-plus/element-plus/issues/10790 --- packages/components/table/src/table-body/events-helper.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/components/table/src/table-body/events-helper.ts b/packages/components/table/src/table-body/events-helper.ts index e751934f66..0fe97c2d81 100644 --- a/packages/components/table/src/table-body/events-helper.ts +++ b/packages/components/table/src/table-body/events-helper.ts @@ -89,7 +89,13 @@ function useEvents(props: Partial>) { const range = document.createRange() range.setStart(cellChild, 0) range.setEnd(cellChild, cellChild.childNodes.length) - const rangeWidth = range.getBoundingClientRect().width + /** detail: https://github.com/element-plus/element-plus/issues/10790 + * What went wrong? + * UI > Browser > Zoom, In Blink/WebKit, getBoundingClientRect() sometimes returns inexact values, probably due to lost precision during internal calculations. In the example above: + * - Expected: 188 + * - Actual: 188.00000762939453 + */ + const rangeWidth = Math.round(range.getBoundingClientRect().width) const padding = (Number.parseInt(getStyle(cellChild, 'paddingLeft'), 10) || 0) + (Number.parseInt(getStyle(cellChild, 'paddingRight'), 10) || 0)