소스 검색

Table: optimize tooltip logic (#11137)

杨奕 7 년 전
부모
커밋
6289144d84
1개의 변경된 파일5개의 추가작업 그리고 2개의 파일을 삭제
  1. 5 2
      packages/table/src/table-body.js

+ 5 - 2
packages/table/src/table-body.js

@@ -336,15 +336,18 @@ export default {
 
       // 判断是否text-overflow, 如果是就显示tooltip
       const cellChild = event.target.querySelector('.cell');
+      if (!hasClass(cellChild, 'el-tooltip')) {
+        return;
+      }
       // use range width instead of scrollWidth to determine whether the text is overflowing
       // to address a potential FireFox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1074543#c3
       const range = document.createRange();
       range.setStart(cellChild, 0);
-      range.setEnd(cellChild, 1);
+      range.setEnd(cellChild, cellChild.childNodes.length);
       const rangeWidth = range.getBoundingClientRect().width;
       const padding = (parseInt(getStyle(cellChild, 'paddingLeft'), 10) || 0) +
         (parseInt(getStyle(cellChild, 'paddingRight'), 10) || 0);
-      if (hasClass(cellChild, 'el-tooltip') && rangeWidth + padding > cellChild.offsetWidth && this.$refs.tooltip) {
+      if (rangeWidth + padding > cellChild.offsetWidth && this.$refs.tooltip) {
         const tooltip = this.$refs.tooltip;
         // TODO 会引起整个 Table 的重新渲染,需要优化
         this.tooltipContent = cell.textContent || cell.innerText;